Created
April 13, 2017 15:30
-
-
Save trntsmn/3afd891550b2ffdb2eb7dfa372b49d88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ForceHttps] | |
[HttpPatch] | |
public async Task<ActionResult> UpdatePassword(SvcUserPasswordUpdateViewModel viewModel) | |
{ | |
viewModel.UserId = viewModel.UserId ?? ApplicationUserId; | |
var user = await UserManager.FindByIdAsync(viewModel.UserId); | |
var serviceResponse = new ServiceResponseObject(); | |
if (!ModelState.IsValid) | |
{ | |
this.Response.StatusCode = 422; | |
serviceResponse.ErrorMessage = "Please double check that passwords match."; | |
return Json(serviceResponse); | |
} | |
if (user == null) | |
{ | |
this.Response.StatusCode = 404; | |
serviceResponse.ErrorMessage = "An error has occured"; | |
return Json(serviceResponse); | |
} | |
var result = await UserManager.ChangePasswordAsync(viewModel.UserId, viewModel.Password, viewModel.NewPassword); | |
if (result.Succeeded) | |
{ | |
serviceResponse.Data = _generateUserDetailsObject(user); | |
string emailBody = String.Format("<p>Hi {0},<br>Based on your request, we have updated the password for your MyCulver's account.</p><p>To view or manage your profile, go to <a href=\"MyCulvers.com\">MyCulvers.com</a></p>", user.FirstName); | |
string emailSubject = "Your MyCulver's password has been successfully updated"; | |
await EmailHelper.SendHtmlMailAsync("\"Culver's\" [email protected]", user.Email, "", "", emailSubject, emailBody); | |
} | |
else | |
{ | |
this.Response.StatusCode = 422; | |
serviceResponse.ErrorMessage = "An error has occured"; | |
} | |
return Json(serviceResponse); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment