public ActionResult LogOn(LogOnModel model, string returnUrl) { if (ModelState.IsValid) { if (Membership.ValidateUser(model.UserName, model.Password)) { //Save date for latest log on. var logontime = db.Profiles.Where(l => l.Username == model.UserName).Select(l => l); foreach(Profile p in logontime){ p.LatestLogon = DateTime.Now.ToString(); } db.SaveChanges(); FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } } else { ModelState.AddModelError("", "The user name or password provided is incorrect."); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult DeleteAccount(LogOnModel model) { model.UserName = User.Identity.Name; if (Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SignOut(); Membership.DeleteUser(User.Identity.Name); var user = db.Profiles.Where(f => f.Username == User.Identity.Name).Select(f => f); foreach(Profile e in user){ db.Profiles.Remove(e); } db.SaveChanges(); return RedirectToAction("DeleteAccountSuccess"); } return RedirectToAction("Index", "Home"); }