Ejemplo n.º 1
0
 public ActionResult ResetPassword(string id)
 {
     if (ModelState.IsValid)
     {
         if (String.IsNullOrEmpty(id))
         {
             ViewBag.ErrorMessage = "Email is required";
             return(View());
         }
         Account theAccount = accountDB.getAccountByEmail(id);
         if (theAccount == null)
         {
             ViewBag.ErrorMessage = "Email " + id + " has not been registered.";
             return(View());
         }
         else
         {
             string newPassword = accountDB.RandomPassword();
             theAccount.Password = newPassword;
             accountDB.SendEmailViaGoogle(theAccount.Email, newPassword);
             accountDB.ChangePassword(theAccount.Email, theAccount.Password);
             ViewBag.Message = "New password has been sent to email " + id;
             return(RedirectToAction("ResetPasswordSuccess"));
         }
     }
     return(View());
 }