Exemple #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));
        }
Exemple #2
0
        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 <HttpResponseMessage> Put(ResetPasswordModel model)
        {
            // Check recovery link
            RecoveryLink link = _passwordRecoveryService.GetLink(model.E, model.I);

            if (link.ExpirationDate == DateTime.MinValue)
            {
                // If wrong '?i=' param don't show LinkExpired page
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ResponseMessages.ResourceNotFound));
            }
            if (link.ExpirationDate <= DateTime.UtcNow)
            {
                // link expired
                return(Request.CreateErrorResponse(HttpStatusCode.Gone, ResponseMessages.ResourceGone));
            }

            // Change password
            await _passwordRecoveryService.ChangePassword(link, model.Password);

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Exemple #4
0
        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);
        }
Exemple #5
0
 /// <summary>
 /// Add a new recovery link as an object
 /// </summary>
 /// <param name="link"></param>
 /// <returns></returns>
 public MinimoException AddRecoveryLink(RecoveryLink link)
 {
     RecoveryLinks.Add(link);
     return(this);
 }
Exemple #6
0
        public async Task <bool> CheckIfLinkIsValid(RecoveryLink recoveryLink)
        {
            PasswordRecoveryEntity entity = await _passwordRecoverRepository.SingleOrDefaultAsync(e => e.LinkData == recoveryLink.Id);

            return(entity != null && !entity.IsConfirmed);
        }