Esempio n. 1
0
        public ActionResult ResetPassword(PassRecoverVM model)
        {
            var user = db.Users.FirstOrDefault(u => u.username == model.username);

            if (user.email != model.email)
            {
                ModelState.AddModelError("email", "This username is not registered using this email");
            }

            if (ModelState.IsValid)
            {
                //Assign a random string to recoveryCode column, compare after
                user.recoveryCode = Guid.NewGuid().ToString();
                db.SaveChanges();

                string link = "https://*****:*****@"";

                MailMessage m = new MailMessage();
                m.To.Add(model.email);
                m.Subject    = "Password Recovery";
                m.Body       = link;
                m.IsBodyHtml = true; //Can send HTML FORMATTED Mail
                new SmtpClient().Send(m);
                return(RedirectToAction("AwaitResetPassword", "Account", new { email = model.email }));
            }
            return(View(model));
        }
Esempio n. 2
0
 // Check if username is registered
 public JsonResult IsUserNameRegistered(PassRecoverVM model)
 {
     return(Json(db.Users.Any(u => u.username == model.username), JsonRequestBehavior.AllowGet));
 }