Пример #1
0
        public async Task <ForgotPasswordResponse> ForgotPasswordAsync(string emailUser)
        {
            ForgotPasswordResponse response = new ForgotPasswordResponse();

            // E-mail validation
            Email            email          = new Email(emailUser);
            EmailValidator   emailValidator = new EmailValidator();
            ValidationResult emailResult    = await emailValidator.ValidateAsync(email);

            if (!emailResult.IsValid)
            {
                response.AddErrorValidationResult(emailResult);
                return(response);
            }

            // Verify is e-mail not exist
            bool emailExist = await _unitOfWork.UserRepository.IsEmailExistsAsync(emailUser);

            if (emailExist == false)
            {
                response.SetError(new ErrorResponse("Email", Msg.EmailDoesnotExist));
                return(response);
            }

            // Persistence
            UserSecurity security = await _unitOfWork.UserSecurityRepository.GetByEmailAsync(email.EmailAddress);

            security.GenerateTokenForgotPassword();
            _unitOfWork.UserSecurityRepository.Update(security);

            // Send mail
            //emailService.SendEmailForgotPassword(email.EmailAddress, security.TokenForgotPassword.Value);

            return(response);
        }