private Email ComposeRecoveryMail(PasswordRecoveryEntity recoveryEntity, string userName, string link) { string emailAddress = _settings.EmailAddressAlerts; string emailDisplayName = Emails.SenderDisplayName; string emailSubject = Emails.SubjectPasswordRecovery; string emailTemplate = PortalResources.UserRecovery; string emailBody = String.Format(emailTemplate, userName, link); var result = new Email(emailSubject, emailBody, ContentType.Html, new EmailAddress(emailAddress, emailDisplayName)); result.To.Add(new EmailAddress(recoveryEntity.Email, recoveryEntity.Email)); return(result); }
public async Task SendNewRecoveryMail(DomainUser user, string validationPath) { string guid = Guid.NewGuid().ToString(); DateTime expires = DateTime.UtcNow.Add(_expirationTime); var recoveryLink = new RecoveryLink { ExpirationDate = expires, Id = guid }; PasswordRecoveryEntity entity = _passwordRecoveryFactory.CreateDefault(user.Id, guid, user.Email, expires); PasswordRecoveryEntity recoveryEntity = await _passwordRecoverRepository.AddAsync(entity); string linkRoot = _settings.PortalUri + validationPath; string linkText = _recoveryLinkService.CreateRecoveryLinkText(recoveryLink, linkRoot); Email emailToSend = ComposeRecoveryMail(recoveryEntity, user.Name, linkText); await _mailerRepository.SendMail(emailToSend); }
public async Task ChangePassword(RecoveryLink recoveryLink, string newPassword) { PasswordRecoveryEntity entity = await _passwordRecoverRepository.SingleOrDefaultAsync(e => e.LinkData == recoveryLink.Id); if (entity == null || entity.IsConfirmed) { throw new NotFoundException(); } entity.Modified = DateTime.UtcNow; entity.IsConfirmed = true; entity = await _passwordRecoverRepository.UpdateAsync(entity); UserEntity user = await _userRepository.FindByEmailAsync(entity.Email); if (user == null) { throw new NotFoundException(); } await _passwordService.ChangePasswordAsync(user.Id, newPassword); }
public virtual async Task <Execute> RecoveryPassword([FromBody] PasswordRecoveryEntity info) { return(await LoginBusiness.RecoveryPasswordAsync(info)); }
public Task <Execute> RecoveryPasswordAsync(PasswordRecoveryEntity info) { throw new NotImplementedException(); }
public async Task <bool> CheckIfLinkIsValid(RecoveryLink recoveryLink) { PasswordRecoveryEntity entity = await _passwordRecoverRepository.SingleOrDefaultAsync(e => e.LinkData == recoveryLink.Id); return(entity != null && !entity.IsConfirmed); }