init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
212
Kreta.BusinessLogic/Helpers/JelszoLinkHelper.cs
Normal file
212
Kreta.BusinessLogic/Helpers/JelszoLinkHelper.cs
Normal file
|
@ -0,0 +1,212 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Kreta.BusinessLogic.Exceptions;
|
||||
using Kreta.BusinessLogic.HelperClasses;
|
||||
using Kreta.BusinessLogic.Utils;
|
||||
using Kreta.Core;
|
||||
using Kreta.Core.ConnectionType;
|
||||
using Kreta.DataAccess.Interfaces;
|
||||
using Kreta.DataAccessManual;
|
||||
using Kreta.DataAccessManual.Interfaces;
|
||||
using Kreta.DataAccessManual.Util;
|
||||
using Kreta.Resources;
|
||||
|
||||
namespace Kreta.BusinessLogic.Helpers
|
||||
{
|
||||
public class JelszoLinkHelper : LogicBase
|
||||
{
|
||||
public JelszoLinkHelper(IConnectionType connectionType, string guid) : base(connectionType)
|
||||
{
|
||||
this.guid = guid;
|
||||
}
|
||||
|
||||
public JelszoLinkHelper(IConnectionType connectionType, int gondviseloId) : base(connectionType)
|
||||
{
|
||||
this.gondviseloId = gondviseloId;
|
||||
}
|
||||
|
||||
private const int maxProbalkozasokSzama = 3;
|
||||
private string guid;
|
||||
private int? gondviseloId;
|
||||
|
||||
private IJelszoModositasLink GetLink(IDalHandler h)
|
||||
{
|
||||
var dal = h.JelszoModositasLinkDal();
|
||||
|
||||
if (gondviseloId.IsEntityId())
|
||||
{
|
||||
guid = dal.GetGuidByGondviseloId(gondviseloId.Value);
|
||||
}
|
||||
|
||||
var id = dal.GetId(guid);
|
||||
if (id.IsEntityId())
|
||||
{
|
||||
return dal.Get(id.Value);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsSzulDatumValidacio()
|
||||
{
|
||||
return Dal.CustomConnection.Run(ConnectionType, h =>
|
||||
{
|
||||
var link = GetLink(h);
|
||||
|
||||
if (link != null)
|
||||
{
|
||||
return IsSzulDatumValidacio(h, link);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
public IsSuccessResponseCo SaveJelszo(JelszoValtoztatoCo co)
|
||||
{
|
||||
return Dal.CustomConnection.Run(ConnectionType, h =>
|
||||
{
|
||||
var link = GetLink(h);
|
||||
|
||||
if (link == null)
|
||||
{
|
||||
return new IsSuccessResponseCo(false, AdminisztracioResource.AJelszoValtoztatasSikertelen);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
co.IsSzulDatumValidacio = IsSzulDatumValidacio(h, link);
|
||||
}
|
||||
catch (KretaJelszoModositasException e)
|
||||
{
|
||||
return new IsSuccessResponseCo(false, e.Message);
|
||||
}
|
||||
|
||||
if (co.IsSzulDatumValidacio)
|
||||
{
|
||||
if (!ValidateSzulestesiDatum(h, co.TanuloSzuletesiDatum.Value, link.FelhasznaloId))
|
||||
{
|
||||
var probalkozasokSzama = default(int);
|
||||
link.ProbalkozasokSzama++;
|
||||
h.JelszoModositasLinkDal().Update(link);
|
||||
|
||||
probalkozasokSzama = maxProbalkozasokSzama - link.ProbalkozasokSzama;
|
||||
|
||||
if (probalkozasokSzama > 0)
|
||||
{
|
||||
return new IsSuccessResponseCo(false, string.Format(ErrorResource.HibasSzuletesiDatumMeg0AlkalommalProbalkozhat, probalkozasokSzama.ToString()));
|
||||
}
|
||||
|
||||
var intezmenyCo = new IntezmenyHelper(new DalHandlerConnectionType(ConnectionType, h)).GetAktivIntezmenyNevCim();
|
||||
return new IsSuccessResponseCo(false, string.Format(ErrorResource.HibasSzuletesiDatum, intezmenyCo.Nev, intezmenyCo.IntezmenyCim));
|
||||
}
|
||||
}
|
||||
|
||||
JelszoModositasEsEmail(h, co, link.GondviseloId, link.FelhasznaloId);
|
||||
DeleteLink(h, link);
|
||||
|
||||
return new IsSuccessResponseCo(true, AdminisztracioResource.AJelszoValtoztatasSikeres);
|
||||
});
|
||||
}
|
||||
|
||||
public void DeleteLink()
|
||||
{
|
||||
Dal.CustomConnection.Run(ConnectionType, h =>
|
||||
{
|
||||
var link = GetLink(h);
|
||||
|
||||
if (link != null)
|
||||
{
|
||||
DeleteLink(h, link);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private bool IsSzulDatumValidacio(IDalHandler h, IJelszoModositasLink link)
|
||||
{
|
||||
if ((DateTime.Now - link.LetrehozasDatuma).Days > 7)
|
||||
{
|
||||
DeleteInvalidLink(h, link);
|
||||
var intezmenyCo = new IntezmenyHelper(new DalHandlerConnectionType(ConnectionType, h)).GetAktivIntezmenyNevCim();
|
||||
throw new KretaJelszoModositasException(string.Format(ErrorResource.EzAFeluletMarNemElerhetoAzOnSzamaraInvalidLink, intezmenyCo.Nev, intezmenyCo.IntezmenyCim));
|
||||
}
|
||||
|
||||
if (link.ProbalkozasokSzama > 2)
|
||||
{
|
||||
DeleteInvalidLink(h, link);
|
||||
var intezmenyCo = new IntezmenyHelper(new DalHandlerConnectionType(ConnectionType, h)).GetAktivIntezmenyNevCim();
|
||||
throw new KretaJelszoModositasException(string.Format(ErrorResource.EzAFeluletMarNemElerhetoAzOnSzamaraInvalidLink, intezmenyCo.Nev, intezmenyCo.IntezmenyCim));
|
||||
}
|
||||
|
||||
return link.IsSzuletesiDatumValidacio;
|
||||
}
|
||||
|
||||
private void JelszoModositasEsEmail(IDalHandler h, JelszoValtoztatoCo co, int gondviseloId, int felhasznaloId)
|
||||
{
|
||||
var connectionType = new DalHandlerConnectionType(ConnectionType, h);
|
||||
var felhasznaloBelepesHelper = new FelhasznaloBelepesHelper(connectionType);
|
||||
|
||||
if (gondviseloId.IsEntityId())
|
||||
{
|
||||
var intezmenyCo = new IntezmenyHelper(connectionType).GetAktivIntezmenyNevCim();
|
||||
var felhasznaloBelepesDal = h.FelhasznaloBelepes();
|
||||
var gondviseloDal = h.Gondviselo();
|
||||
var gondviselo = gondviseloDal.Get(gondviseloId);
|
||||
var gondviseloFelhasznaloBelepes = gondviselo.FelhasznaloBelepes.SingleOrDefault(x => !x.Torolt);
|
||||
var felhasznaloNev = string.Empty;
|
||||
if (gondviseloFelhasznaloBelepes == null)
|
||||
{
|
||||
var tanulo = h.Tanulo().Get(felhasznaloId);
|
||||
var index = 1;
|
||||
felhasznaloNev = CommonUtils.GenerateGondviseloBejelentkezesiNev(felhasznaloBelepesDal, tanulo.OktatasiAzonosito, ref index, TanevId);
|
||||
|
||||
felhasznaloBelepesHelper.GrantLogin(felhasznaloId, felhasznaloNev, co.UjJelszo, gondviseloId);
|
||||
}
|
||||
else
|
||||
{
|
||||
felhasznaloNev = gondviseloFelhasznaloBelepes.BejelentkezesiNev;
|
||||
felhasznaloBelepesHelper.ChangeUserPassword(felhasznaloNev, co.UjJelszo);
|
||||
}
|
||||
|
||||
var gondviseloEmail = gondviselo.Email.SingleOrDefault(x => !x.Torolt && !x.IsHibasanMegadva && x.Alapertelmezett);
|
||||
if (gondviseloEmail != null)
|
||||
{
|
||||
var message = string.Format(EmailResource.JelszoValtoztatasUtanFelhaszNevErtesitesEmail, gondviselo.Nev, felhasznaloNev, intezmenyCo.Nev, intezmenyCo.IntezmenyCim, CommonUtils.GetIntezmenyUrl(intezmenyCo.IntezmenyAzonosito));
|
||||
new UzenetekHelper(connectionType).GondviseloJelszoEmail(message, gondviseloEmail.EmailCim, gondviseloEmail.Guid);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var felhasznaloBelepes = h.Tanulo().Get(felhasznaloId).FelhasznaloBelepes.SingleOrDefault(x => !x.Torolt && x.Gondviselo == null);
|
||||
felhasznaloBelepesHelper.ChangeUserPassword(felhasznaloBelepes.BejelentkezesiNev, co.UjJelszo);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteInvalidLink(IDalHandler h, IJelszoModositasLink link)
|
||||
{
|
||||
var gondviseloDal = h.Gondviselo();
|
||||
|
||||
var gondviselo = gondviseloDal.Get(link.GondviseloId);
|
||||
if (gondviselo.IsCsokkentettGondviselo)
|
||||
{
|
||||
gondviseloDal.Delete(gondviselo);
|
||||
}
|
||||
else
|
||||
{
|
||||
DeleteLink(h, link);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteLink(IDalHandler h, IJelszoModositasLink link)
|
||||
{
|
||||
h.JelszoModositasLinkDal().Delete(link);
|
||||
}
|
||||
|
||||
private bool ValidateSzulestesiDatum(IDalHandler h, DateTime tanuloSzuletesiDatum, int felhasznaloId)
|
||||
{
|
||||
var tanuloSzulDatumDbben = h.Tanulo().Get(felhasznaloId).SzuletesiDatum;
|
||||
|
||||
return tanuloSzulDatumDbben.Equals(tanuloSzuletesiDatum);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue