/// <summary> /// Make a account recovery /// </summary> /// <param name="id">Recovery index</param> /// <param name="key">Recovery key</param> /// <returns>AccountRecovery object</returns> public static AccountRecovery AccountRecovery(int id, string key) { AccountRecovery recovery = _context.AccountRecoveries .Include(r => r.Account) .Where(r => r.Id == id && r.Key == key && !r.Expired) .FirstOrDefault(); if (recovery == null) { throw new Exception("Didn't find any active account recovery on this link."); } return(recovery.DeepCopy()); }
/// <summary> /// Save account recovery password change /// </summary> /// <param name="id">Recovery index</param> /// <param name="key">Recovery key</param> /// <param name="password">Password to change to</param> public static void SaveAccountRecovery(int id, string key, string password) { AccountRecovery recovery = _context.AccountRecoveries .Include(r => r.Account) .Where(r => r.Id == id && r.Key == key && !r.Expired) .FirstOrDefault(); if (recovery == null) { throw new Exception("Didn't find any active account recovery on this link."); } recovery.Account.Password = password; _context.Accounts.Update(recovery.Account); _context.Remove(recovery); _context.SaveChanges(); }
public ActionResult PasswordResetEmail(AccountRecovery pwrecover, EmailBuilder emailer) { if (ModelState.IsValid) { if (!pwrecover.checkEmail()) { ModelState.AddModelError("givenEmail", "Email Doesnt exist"); return(View(pwrecover)); } else { pwrecover.generateCode(); emailer.SendPasswordReset(pwrecover, pwrecover.verificationCode); TempData["verificationCode"] = pwrecover.verificationCode; TempData["Email"] = pwrecover.givenEmail; TempData["UserObject"] = pwrecover; return(RedirectToAction("PasswordResetCode")); } } return(View()); }
public ActionResult PasswordResetCode(AccountRecovery accRecover) { /* ONCE INPUTTED CODE, CHECK IF CODES ARE THE SAME VALUE. IF IT DOESNT, THROW ERROR MESSAGE, IF IT DOES, REDIRECT TO NEW PASSWORD PAGE.. */ //ModelState.AddModelError("givenEmail", "That code doesn't match up what we sent."); int verificode = (int)TempData["verificationCode"]; TempData.Keep("verificationCode"); if (accRecover.givenCode == verificode) { return(View("PasswordResetNewPassword")); } else { ModelState.AddModelError("givenCode", "Invalid code given, please refresh your inbox and try again.."); return(View()); } //return View(pwrecover); }