Ejemplo n.º 1
0
        public async Task <string> GenerateForgotPasswordEmail(ForgotPasswordRequestModel model)
        {
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user != null)
            {
                var hash = GenericHelper.GenerateForgotPasswordToken(user);
                _dbContext.ForgotPasswordToken.Add(new ForgotPasswordValidationKey
                {
                    ValidationKey = hash,
                    UserId        = user.Id
                });
                await _dbContext.SaveChangesAsync();

                model.UserId = user.Id;
                string body = await GetForgotPasswordEmailBody(model, hash);

                await _emailService.SendEmail(user.Email, body, "Password Reset");

                return("");
            }
            else
            {
                throw new GenericException(ErrorCodes.GetCode("UserNotFound"));
            }
        }