Esempio n. 1
0
        public string CreateRecoveryLinkText(RecoveryLink link, string linkRoot)
        {
            long ticks = (link.ExpirationDate - DateTime.MinValue).Ticks;
            string expiresEncrypted = _stringEncryptor.EncryptString(ticks.ToString(CultureInfo.InvariantCulture));
            string userIdEncrypted = _stringEncryptor.EncryptString(link.Id);

            return String.Format("{0}/?e={1}&i={2}", linkRoot, expiresEncrypted, userIdEncrypted);
        }
        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 async Task<bool> CheckIfLinkIsValid(RecoveryLink recoveryLink)
 {
     PasswordRecoveryEntity entity = await _passwordRecoverRepository.SingleOrDefaultAsync(e => e.LinkData == recoveryLink.Id);
     return entity != null && !entity.IsConfirmed;
 }