public DataResultUserActivate ActivateAccount(Guid activateUserToken) { DataResultUserActivate result = null; ITokenTemporaryPersistenceBL<MembershipUserWrapper> _tokenServices = new TokenTemporaryPersistenceBL<MembershipUserWrapper>(); TokenTemporaryPersistenceServiceItem<MembershipUserWrapper> _tokenItem = _tokenServices.GetById(activateUserToken); if (_tokenItem == null) { result = new DataResultUserActivate() { IsValid = false, Message = UserAdminTexts.ActivationTokenExpired, Data = new AccountActivationModel() { ActivateUserToken = activateUserToken } }; } else { using (TransactionScope trans = this.TransactionScopeCreate()) { try { result = this._dal.ActivateAccount((MembershipUserWrapper)_tokenItem.TokenObject, activateUserToken); _tokenServices.Delete(new TokenTemporaryPersistenceServiceItem<MembershipUserWrapper>() { Token = activateUserToken }); trans.Complete(); this.ForceAuthentication(((MembershipUserWrapper)_tokenItem.TokenObject).UserName); } catch (Exception ex) { throw ex; } finally { _tokenServices.Dispose(); } } } return result; }
public DataResultUserCantAccess CantAccessYourAccount(string activateFormVirtualPath, string email) { ITokenTemporaryPersistenceBL<MembershipUserWrapper> tokenServices = null; DataResultUserCantAccess dalResult; try { using (TransactionScope trans = this.TransactionScopeCreate()) { dalResult = this._dal.CantAccessYourAccount(activateFormVirtualPath, email); if (dalResult.IsValid) { tokenServices = new TokenTemporaryPersistenceBL<MembershipUserWrapper>(); TokenTemporaryPersistenceServiceItem<MembershipUserWrapper> token = new TokenTemporaryPersistenceServiceItem<MembershipUserWrapper>(dalResult.Data.User); tokenServices.Insert(token); dalResult.Data.ChangePasswordToken = token.Token; MailMessage mail = new MailMessage(); mail.From = new MailAddress(ApplicationConfiguration.MailingSettingsSection.SupportTeamEmailAddress); mail.Bcc.Add(new MailAddress(dalResult.Data.User.Email)); mail.Subject = string.Format("{0}: {1}", ApplicationConfiguration.DomainInfoSettingsSection.DomainName, AccountResources.CantAccessYourAccount_EmailTitle); mail.Body = string.Format( AccountResources.CantAccessYourAccount_Email, new Uri(string.Format("{0}://{1}{2}/{3}", ApplicationConfiguration.DomainInfoSettingsSection.SecurityProtocol, ApplicationConfiguration.DomainInfoSettingsSection.DomainName, activateFormVirtualPath, dalResult.Data.ChangePasswordToken.ToString())), ApplicationConfiguration.DomainInfoSettingsSection.DomainName); using (ISmtpClient smtp = DependencyFactory.Resolve<ISmtpClient>()) { // Do not use SendAsync -> otherwise transaction could commit without sending mail smtp.Send(mail); } trans.Complete(); } return dalResult; } } catch (Exception ex) { throw ex; } finally { if (tokenServices != null) { tokenServices.Dispose(); } } }
public DataResultUserCantAccess ResetPassword(Guid guid, string newPassword, string confirmNewPassword) { DataResultUserCantAccess result; if (!this.ValidatePasswordStrength(newPassword)) { result = new DataResultUserCantAccess() { IsValid = false, Message = Resources.Account.AccountResources.InvalidPassword, MessageType = DataResultMessageType.Error }; } else { if (!newPassword.Equals(confirmNewPassword)) { result = new DataResultUserCantAccess() { IsValid = false, Message = Resources.Account.AccountResources.NewPasswordConfirmError, MessageType = DataResultMessageType.Error }; } else { ITokenTemporaryPersistenceBL<MembershipUserWrapper> tokenServices = null; try { tokenServices = new TokenTemporaryPersistenceBL<MembershipUserWrapper>(); object tokenTempItem = tokenServices.GetById(guid); if (tokenTempItem == null) { result = new DataResultUserCantAccess() { IsValid = false, Message = AccountResources.CantAccessYourAccount_TokenExpired, MessageType = DataResultMessageType.Error }; } else { using (TransactionScope trans = this.TransactionScopeCreate()) { MembershipUserWrapper userChangingPassword = ((TokenTemporaryPersistenceServiceItem<MembershipUserWrapper>)tokenTempItem).TokenObject; result = this._dal.ResetPassword(userChangingPassword, newPassword, confirmNewPassword); if (result.IsValid) { MailMessage mail = new MailMessage(); mail.From = new MailAddress(ApplicationConfiguration.MailingSettingsSection.SupportTeamEmailAddress); mail.Bcc.Add(new MailAddress(result.Data.User.Email)); mail.Subject = string.Format(AccountResources.ChangePassword_EmailTitle, ApplicationConfiguration.DomainInfoSettingsSection.DomainName); mail.Body = string.Format(AccountResources.ChangePassword_EmailBody, ApplicationConfiguration.DomainInfoSettingsSection.DomainName); using (ISmtpClient smtp = DependencyFactory.Resolve<ISmtpClient>()) { // Do not use SendAsync -> otherwise transaction could commit without sending mail smtp.Send(mail); } tokenServices.Delete(new TokenTemporaryPersistenceServiceItem<MembershipUserWrapper>() { Token = guid }); trans.Complete(); this.ForceAuthentication(userChangingPassword.UserName); } } } } catch (Exception ex) { throw ex; } finally { if (tokenServices != null) { tokenServices.Dispose(); } } } } return result; }
public DataResultUserCreateResult CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, string activateFormVirtualPath) { DataResultUserCreateResult result; EmailAttribute emailDataAnnotations = new EmailAttribute(); if (!emailDataAnnotations.IsValid(email)) { //result = new DataResultUserCreateResult(new CreatedAccountResultModel(MembershipCreateStatus.InvalidEmail)); result = new DataResultUserCreateResult() { IsValid = true, MessageType = DataResultMessageType.Error, Data = new CreatedAccountResultModel(MembershipCreateStatus.InvalidEmail) }; } else { if (this.ValidatePasswordStrength(password)) { using (TransactionScope trans = this.TransactionScopeCreate()) { result = this._dal.CreateUser(username, password, email, passwordQuestion, passwordAnswer, activateFormVirtualPath); if (result.Data.CreateStatus == MembershipCreateStatus.Success) { MembershipUserWrapper newUser = _dal.GetUserByName(username, false).Data; IRoleAdminBL _roleBl = new RoleAdminBL(); DataResultBoolean newUserRole = _roleBl.AddToRoles(newUser.UserName, new string[1] { SiteRoles.Guest.ToString() }); _roleBl.Dispose(); ProfileBL _profileBL = new ProfileBL(); UserProfileModel usrProfile = _profileBL.Create(username).Data; _profileBL.Dispose(); ITokenTemporaryPersistenceBL<MembershipUserWrapper> _tokenServices = new TokenTemporaryPersistenceBL<MembershipUserWrapper>(); TokenTemporaryPersistenceServiceItem<MembershipUserWrapper> token = new TokenTemporaryPersistenceServiceItem<MembershipUserWrapper>(newUser); _tokenServices.Insert(token); result.Data.ActivateUserToken = token.Token; _tokenServices.Dispose(); if (newUserRole.Data) { MailMessage mail = new MailMessage(); mail.From = new MailAddress(ApplicationConfiguration.MailingSettingsSection.SupportTeamEmailAddress); mail.Bcc.Add(new MailAddress(newUser.Email)); mail.Subject = string.Format(AccountResources.CreateNewAccount_EmailSubject, ApplicationConfiguration.DomainInfoSettingsSection.DomainName); mail.Body = string.Format(AccountResources.CreateNewAccount_EmailBody, ApplicationConfiguration.DomainInfoSettingsSection.DomainName, new Uri(string.Format("{0}://{1}{2}/{3}", ApplicationConfiguration.DomainInfoSettingsSection.SecurityProtocol, ApplicationConfiguration.DomainInfoSettingsSection.DomainName, activateFormVirtualPath.ToString(), result.Data.ActivateUserToken))); using (ISmtpClient smtp = DependencyFactory.Resolve<ISmtpClient>()) { smtp.Send(mail); } trans.Complete(); } else { trans.Dispose(); } } else { trans.Dispose(); } } } else { result = new DataResultUserCreateResult() { IsValid = true, MessageType = DataResultMessageType.Error, Data = new CreatedAccountResultModel(MembershipCreateStatus.InvalidPassword) }; } } return result; }
public DataResultUserCantAccess CantAccessYourAccount(string activateFormVirtualPath, string email) { ITokenTemporaryPersistenceBL<MembershipUserWrapper> tokenServices = null; DataResultUserCantAccess dalResult; try { using (TransactionScope trans = this.TransactionScopeCreate()) { dalResult = this._dal.CantAccessYourAccount(activateFormVirtualPath, email); if (dalResult.IsValid) { tokenServices = new TokenTemporaryPersistenceBL<MembershipUserWrapper>(); TokenTemporaryPersistenceServiceItem<MembershipUserWrapper> token = new TokenTemporaryPersistenceServiceItem<MembershipUserWrapper>(dalResult.Data.User); tokenServices.Insert(token); dalResult.Data.ChangePasswordToken = token.Token; MailingHelper.Send(delegate() { MailMessage mail = new MailMessage(); mail.From = new MailAddress(MailingHelper.MailingConfig.SupportTeamEmailAddress); mail.Bcc.Add(new MailAddress(dalResult.Data.User.Email)); mail.Subject = AccountResources.CantAccessYourAccount_EmailTitle; mail.Body = string.Format(AccountResources.CantAccessYourAccount_Email, new Uri(string.Format("{0}://{1}/{2}/{3}", ApplicationConfiguration.DomainInfoSettingsSection.SecurityProtocol, ApplicationConfiguration.DomainInfoSettingsSection.DomainName, activateFormVirtualPath, dalResult.Data.ChangePasswordToken.ToString())), MailingHelper.DomainConfig.DomainName); return mail; }); trans.Complete(); } return dalResult; } } catch (Exception ex) { throw ex; } finally { if (tokenServices != null) { tokenServices.Dispose(); } } }
public DataResultUserCantAccess ResetPassword(Guid guid, string newPassword, string confirmNewPassword) { DataResultUserCantAccess result; if (!this.ValidatePasswordStrength(newPassword)) { result = new DataResultUserCantAccess() { IsValid = false, Message = Resources.Account.AccountResources.InvalidPassword, MessageType = DataResultMessageType.Error }; } else { if (!newPassword.Equals(confirmNewPassword)) { result = new DataResultUserCantAccess() { IsValid = false, Message = Resources.Account.AccountResources.NewPasswordConfirmError, MessageType = DataResultMessageType.Error }; } else { ITokenTemporaryPersistenceBL<MembershipUserWrapper> tokenServices = null; try { tokenServices = new TokenTemporaryPersistenceBL<MembershipUserWrapper>(); object tokenTempItem = tokenServices.GetById(guid); if (tokenTempItem == null) { result = new DataResultUserCantAccess() { IsValid = false, Message = AccountResources.CantAccessYourAccount_TokenExpired, MessageType = DataResultMessageType.Error }; } else { using (TransactionScope trans = this.TransactionScopeCreate()) { MembershipUserWrapper userChangingPassword = ((TokenTemporaryPersistenceServiceItem<MembershipUserWrapper>)tokenTempItem).TokenObject; result = this._dal.ResetPassword(userChangingPassword, newPassword, confirmNewPassword); if (result.IsValid) { MailingHelper.Send(delegate() { MailMessage mail = new MailMessage(); mail.From = new MailAddress(MailingHelper.MailingConfig.SupportTeamEmailAddress); mail.Bcc.Add(new MailAddress(result.Data.User.Email)); mail.Subject = string.Format(AccountResources.ChangePassword_EmailTitle, MailingHelper.DomainConfig.DomainName); mail.Body = string.Format(AccountResources.ChangePassword_EmailBody, MailingHelper.DomainConfig.DomainName); return mail; }); tokenServices.Delete(new TokenTemporaryPersistenceServiceItem<MembershipUserWrapper>() { Token = guid }); trans.Complete(); this.ForceAuthentication(userChangingPassword.UserName); } } } } catch (Exception ex) { throw ex; } finally { if (tokenServices != null) { tokenServices.Dispose(); } } } } return result; }