public InternalLoginInfo AddUserInfo(String login, String password, int idPerson, DateTime passwordExpiresOn, InternalAuthenticationProvider provider) { InternalLoginInfo userInfo = null; try { Person currentUser = Manager.GetPerson(UC.CurrentUserID); Person creator = Manager.GetPerson(idPerson); if (currentUser == null) { currentUser = creator; } if (provider != null && creator != null) { Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor(); Manager.BeginTransaction(); userInfo = new InternalLoginInfo(); userInfo.CreateMetaInfo(currentUser, UC.IpAddress, UC.ProxyIpAddress); userInfo.PasswordExpiresOn = passwordExpiresOn; userInfo.Deleted = BaseStatusDeleted.None; userInfo.isEnabled = true; userInfo.Provider = provider; userInfo.Login = login; userInfo.Password = helper.Encrypt(password); userInfo.Person = creator; if (creator.IdDefaultProvider == 0 || String.IsNullOrEmpty(creator.FirstLetter)) { //// TEMPORANEO //creator.Login = login; //creator.Password=userInfo.Password; //// TEMPORANEO if (creator.IdDefaultProvider == 0) { creator.IdDefaultProvider = provider.Id; } if (String.IsNullOrEmpty(creator.FirstLetter)) { creator.FirstLetter = creator.Surname[0].ToString().ToLower(); } Manager.SaveOrUpdate(creator); } Manager.SaveOrUpdate(userInfo); AddToHistory(userInfo); Manager.Commit(); } } catch (Exception ex) { Manager.RollBack(); userInfo = null; } return(userInfo); }
public InternalLoginInfo GenerateUserInfo(Person person, String login, String password, InternalAuthenticationProvider provider, Boolean oneTimePassword) { InternalLoginInfo userInfo = null; try { Person currentUser = Manager.GetPerson(UC.CurrentUserID); if (currentUser == null) { currentUser = person; } if (provider != null && person != null) { Helpers.InternalEncryptor helper = new Helpers.InternalEncryptor(); Manager.BeginTransaction(); if (!(from l in Manager.GetIQ <InternalLoginInfo>() where l.Person == person && l.Deleted == BaseStatusDeleted.None && l.Provider == provider select l.Id).Any()) { userInfo = new InternalLoginInfo(); userInfo.CreateMetaInfo(currentUser, UC.IpAddress, UC.ProxyIpAddress); userInfo.PasswordExpiresOn = (provider == null || provider.ChangePasswordAfterDays == 0) ? DateTime.MaxValue : DateTime.Now.AddDays(provider.ChangePasswordAfterDays); userInfo.Deleted = BaseStatusDeleted.None; userInfo.isEnabled = true; userInfo.Provider = provider; userInfo.Login = login; userInfo.Password = helper.Encrypt(password); userInfo.Person = person; userInfo.ResetType = (oneTimePassword) ? EditType.oneTime : EditType.admin; if (person.IdDefaultProvider == 0 || String.IsNullOrEmpty(person.FirstLetter)) { if (person.IdDefaultProvider == 0) { person.IdDefaultProvider = provider.Id; } if (String.IsNullOrEmpty(person.FirstLetter)) { person.FirstLetter = person.Surname[0].ToString().ToLower(); } Manager.SaveOrUpdate(person); } Manager.SaveOrUpdate(userInfo); AddToHistory(userInfo); } else { userInfo = (from l in Manager.GetIQ <InternalLoginInfo>() where l.Person == person && l.Deleted == BaseStatusDeleted.None && l.Provider == provider select l).Skip(0).Take(1).ToList().FirstOrDefault(); } Manager.Commit(); } } catch (Exception ex) { Manager.RollBack(); userInfo = null; } return(userInfo); }