Exemple #1
0
        public JsonResult GeneratePasswordResetLink(PasswordResetLink passwordResetLink)
        {
            UserSettings userSettings = UserService.GetUserByEmailAddress(passwordResetLink.Email);

            if (userSettings == null)
            {
                PostRequestResult result = new PostRequestResult
                {
                    Success      = false,
                    ErrorMessage = "A user with the specified email address could not be found"
                };

                return(Json(result));
            }
            else
            {
                bool success             = UserService.SendResetPasswordLink(passwordResetLink.Email);
                PostRequestResult result = new PostRequestResult
                {
                    Success      = success,
                    ErrorMessage = success ? "" : "Couldn't send email because of an unexpected error"
                };

                return(Json(result));
            }
        }
Exemple #2
0
        private bool SendResetPasswordLink(PasswordResetLink passwordResetLink)
        {
            string emailSubject = "Project Jetson Password Reset";
            string emailBody    = GetEmailBody(passwordResetLink);

            return(_emailService.SendEmail(passwordResetLink.Email, emailSubject, emailBody));
        }
Exemple #3
0
        private string GetEmailBody(PasswordResetLink passwordResetLink)
        {
            string emailBody =
                RazorEngineWrapper.RunCompile("Views/User", "PasswordResetEmailBodyTemplate.cshtml", passwordResetLink);

            return(emailBody);
        }
Exemple #4
0
 public IActionResult GeneratePasswordResetLink(string id)
 {
     try
     {
         User user = UserService.GetUser(id);
         PasswordResetLink link = AuthService.GeneratePasswordResetLink(user);
         return(Ok(link));
     }
     catch (EntityNotFoundException exception)
     {
         return(HandleResourceNotFoundException(exception));
     }
     catch (Exception exception)
     {
         return(HandleUnexpectedException(exception));
     }
 }
Exemple #5
0
        public bool SendResetPasswordLink(string email)
        {
            string       token = GeneratePasswordResetToken();
            string       url   = "http://" + _hostname + "/User/PasswordReset?id=" + token;
            DatabaseUser user  = _dbQueryService.GetUserByEmailAddress(email);

            if (user == null)
            {
                return(false);
            }
            PasswordResetLink passwordResetLink = new PasswordResetLink(url, email, user.FirstName + " " + user.LastName);

            if (SendResetPasswordLink(passwordResetLink))
            {
                return(_dbQueryService.PersistPasswordResetToken(token, email));
            }
            else
            {
                return(false);
            }
        }