public ActionResult Authenticate(Credential credential) { if (ModelState.IsValid) { var user = _db.Users.FirstOrDefault (t => t.Email == credential.Email && t.Password == credential.Password); if (user == null) { ViewBag.Message = "Credenciais inválidas"; return View(); } SaveCookie(user); user.LastLoggedOn = DateTime.Now; _db.SaveChanges(); return RedirectToAction("Index", "Desafio"); } ViewBag.Message = "Credenciais inválidas"; return View(); }
public ActionResult ChangePassword(Credential credential) { var userID = ((CustomPrincipal)HttpContext.User).UserID; var loggedUser = _db.Users.SingleOrDefault(t => t.ID == userID); if (loggedUser == null) { ViewBag.Message = "Credenciais inválidas"; return View("Authenticate"); } loggedUser.Password = credential.Password; _db.SaveChanges(); ViewBag.Message = "Senha alterada com sucesso."; return View("ChangePassword"); }