Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ran into this as well. To fix it, I created some controller actions in <code>AccountController.cs</code> (and corresponding views) to handle it.</p> <p>Here are the actual lines that reset the user's password:</p> <pre><code>[AllowAnonymous] [HttpPost] public ActionResult ResetForgottenPassword(string key, ManageUserViewModel model) { var user = db.Users.SingleOrDefault(u =&gt; u.ForgotPasswordCode != null &amp;&amp; u.ForgotPasswordCode == key); if (user == null || !user.ForgotPasswordDate.HasValue || user.ForgotPasswordDate.Value.AddDays(1) &lt; DateTime.UtcNow) return new HttpUnauthorizedResult(); ModelState state = ModelState["OldPassword"]; if (state != null) { state.Errors.Clear(); } if (ModelState.IsValid) { if (UserManager.HasPassword(user.Id)) UserManager.RemovePassword(user.Id); IdentityResult result = UserManager.AddPassword(user.Id, model.NewPassword); if (result.Succeeded) { //Clear forgot password temp key user.ForgotPasswordCode = null; user.ForgotPasswordDate = null; db.SaveChanges(); //Sign them in var identity = UserManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity); return RedirectToAction("Manage", new { Message = ManageMessageId.SetPasswordSuccess }); } else { AddErrors(result); } } ViewBag.ForgotPasswordCode = key; return View(model); } </code></pre> <p>Some custom items are the new fields on the user object: </p> <ul> <li><code>ForgotPasswordCode</code> and <code>ForgotPasswordDate</code> to keep track of the user throughout the "reset password email" process.</li> <li>I pass the key around in in the <code>ViewBag</code> once the user arrives from the email link.</li> <li>The <code>db</code> variable is a property of my database context class inherited from a base controller.</li> <li>I use UTC DateTimes in my database. Change <code>DateTime.UtcNow</code> to <code>DateTime.Now</code> if you do not.</li> </ul> <p>Probably not the best solution, but it's a fairly quick and simple patch.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload