public ActionResult Login(string returnURL) { Models.LogInModel model = new Models.LogInModel() { ReturnURL = returnURL }; return(View(model)); }
public ActionResult Login(Models.LogInModel user) { if (ModelState.IsValid) { if (_userService.IsValid(user.Username, user.Password)) { FormsAuthentication.SetAuthCookie(user.Username, user.RememberMe); var role = _userService.GetUserRole(user.Username, user.Password); Session["user"] = role; return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError("", "Login data is incorrect!"); } } return(View(user)); }
public async Task <ActionResult> Login(Models.LogInModel model) { if (!ModelState.IsValid) { return(View()); } IdentityUser user = await appUserManager.FindByNameAsync(model.Email); if (user.Id != null) { var result = appUserManager.PasswordHasher.VerifyHashedPassword(user.PasswordHash, model.Password); if (result.Equals(PasswordVerificationResult.Success)) { ClaimsIdentity identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, user.Name), new Claim(ClaimTypes.Email, user.UserName), new Claim(ClaimTypes.Sid, user.Id) }, "ApplicationCookie" ); Microsoft.Owin.IOwinContext ctx = Request.GetOwinContext(); Microsoft.Owin.Security.IAuthenticationManager authManager = ctx.Authentication; authManager.SignIn(identity); return(Redirect(GetRedirectUrl(model.ReturnURL))); } else { ModelState.AddModelError("Invalid_Login", "Invalid login attempted, please check your username and password"); return(View(model)); } } else { ModelState.AddModelError("Invalid_Login", "Invalid login attempted, please check your username: it was not found"); return(View(model)); } }
public ActionResult LogInDetails(Models.LogInModel loginDetails) { ViewBag.LoginFailed = false; if (ModelState.IsValid) { B_UserController bUCtr = new B_UserController(); bool authenticated = bUCtr.Login(loginDetails.UserName, loginDetails.Password); if (authenticated) { FormsAuthentication.SetAuthCookie(loginDetails.UserName, false); } else { // Error message - Wrong credentials ViewBag.LoginFailed = true; ModelState.AddModelError("error_msg", "Wrong credentials"); return(View("LogIn")); } return(RedirectToAction("Index", "Home")); } return(View("LogIn")); }
public ActionResult Login(Models.LogInModel loginModel) { Session["UserName"] = loginModel.UserName; return(RedirectToAction("Index")); }