Advertisement
Guest User

Untitled

a guest
Mar 4th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. public async Task<HttpResponseMessage> ForgotPassword(ForgotPasswordViewModel model)
  2. {
  3. if (!ModelState.IsValid)
  4. {
  5. HttpError error = new HttpError(ModelState, false);
  6. error.Message = Resource.No_Item_Found_Message;
  7. return Request.CreateErrorResponse(HttpStatusCode.BadRequest, error);
  8. }
  9. var user = await UserManager.FindByEmailAsync(model.Email);
  10. if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
  11. {
  12. // Don't reveal that the user does not exist or is not confirmed
  13. HttpError error = new HttpError();
  14. error.Message = Resource.Process_Failed;
  15. return Request.CreateErrorResponse(HttpStatusCode.BadRequest, error);
  16. }
  17. var provider = new DpapiDataProtectionProvider("ECommerceWebApp");
  18. UserManager.UserTokenProvider = new DataProtectorTokenProvider<ECommerceUser, string>(provider.Create("UserToken"));
  19. var code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
  20. code = HttpUtility.UrlEncode(code);
  21. try
  22. {
  23. // var callbackUrl = new Uri(Url.Link("ResetPasswordRoute", new { userId = user.Id, code = code, newPassword = model.Password }));
  24. var callbackUrl = Url.Link("Default", new { Controller = "Account", action = "ResetPassword", userId = user.Id, code = code });
  25. await UserManager.SendEmailAsync(user.Id, "تغییر رمز عبور در IRI1", "<div style='font-family:tahoma;direction:rtl;text-align:right;font-size:12px;'>" + "<h3>اولین و بزرگترین مرکز دادوستد بدون واسطه در ایران و کشورهای همسایه</h3>لطفاً با کلیک بر روی گزینۀ تغییر رمز به صفحۀ مربوطه بروید : <br/><br/><a href="" + callbackUrl + "">تغییر رمز عبور </a><br/><br/><br/><a href='iri1.com'>Iri1 Web Sites</a>" + "</div>");
  26. }
  27. catch (Exception ex)
  28. {
  29. HttpError error = new HttpError();
  30. error.Message = ex.Message;
  31. return Request.CreateErrorResponse(HttpStatusCode.BadRequest, error);
  32.  
  33. }
  34.  
  35.  
  36. return Request.CreateResponse(Resource.Reset_Password_Message_Client);
  37. }
  38.  
  39. [HttpPost]
  40. [AllowAnonymous]
  41. [ValidateAntiForgeryToken]
  42. public async Task<ActionResult> ResetPassword(ResetPasswordViewModel model)
  43. {
  44. if (!ModelState.IsValid)
  45. {
  46. return View(model);
  47. }
  48. var user = await UserManager.FindByEmailAsync(model.Email);
  49. if (user == null)
  50. {
  51. // Don't reveal that the user does not exist
  52. return RedirectToAction("ResetPasswordConfirmation", "Account");
  53. }
  54. var code = HttpUtility.UrlDecode(model.Code);
  55. var result = await UserManager.ResetPasswordAsync(user.Id, code, model.Password);
  56. if (result.Succeeded)
  57. {
  58. return RedirectToAction("ResetPasswordConfirmation", "Account");
  59. }
  60. AddErrors(result);
  61. return View();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement