public IActionResult Login(LoginModel model) { if (IsUserAuthenticated()) { return(Redirect("/")); } if (ModelState.IsValid) { var user = model.AuthenticateUser(); if (user != null) { //auth ok, save to session IAuthenticationHelper authHelper = new SessionAuthenticationHelper(HttpContext.Session); authHelper.SaveState(user); return(Redirect("/")); } else { //add error ModelState.AddModelError(string.Empty, "The username or password provided is incorrect."); } } return(View(model)); }
public ActionResult Index(Login collection) { ViewBag.ErrorMessage = collection.username + " <br> " + collection.password; Login login = LoginModel.AuthenticateUser(collection.username.Trim(), collection.password); if (login == null) { ViewBag.ErrorMessage = "Incorrect User Credential"; } else { ViewBag.ErrorMessage = "Correct user"; Session["loggedUser"] = login; //Response.Redirect("Info"); return(RedirectToAction("Info")); } return(View()); }
internal void AuthenticateUser() { dynamic login = new ExpandoObject(); login.userName = loginView.userName; login.password = loginView.password; dynamic logedInDetails = loginModel.AuthenticateUser(login); if (logedInDetails.valid) { loginView.name = logedInDetails.name; loginView.userName = loginView.userName; loginView.userRole = logedInDetails.userType; loginView.errorMessage = string.Empty; loginView.showErrorMessage = false; loginView.isValidLogin = true; } else { loginView.errorMessage = "Invalid login, please try again"; loginView.showErrorMessage = true; } }
public ActionResult Index(LoginModel model, string command) { Application.ValidateLicenseFile(); // If not in trial mode and not licensed if (!Application.IsTrialMode && !Application.IsLicensed) { return(RedirectToAction("TrialExpired", "Home")); } try { switch (command) { case "Manager": if (model.AuthenticateUser(Roles.Manager)) { BaseRepository.GetUserInfo(1, model.ManagerEmail, out _username, out _userId); Session["Manager"] = _username; Session["ManagerId"] = _userId; return(RedirectToAction("Index", "Manager")); } break; case "Supervisor": if (model.AuthenticateUser(Roles.Supervisor)) { BaseRepository.GetUserInfo(2, model.SupervisorEmail, out _username, out _userId); Session["Supervisor"] = _username; Session["SupervisorId"] = _userId; return(RedirectToAction("Index", "Supervisor")); } break; case "Requestor": if (model.AuthenticateUser(Roles.Requestor)) { BaseRepository.GetUserInfo(3, model.RequestorEmail, out _username, out _userId); Session["Requestor"] = _username; Session["RequestorId"] = _userId; return(RedirectToAction("Index", "Requestor")); } break; } TempData["ErrorMessage"] = string.Format(Common.ErrorDiv, Home.ErrorMsgForCredentials); } catch (Exception exc) { TempData["ErrorMessage"] = string.Format(Common.ErrorDiv, exc.Message); Logger.LogError(exc, "Error while authenticating user"); } // If we got this far, something failed, redisplay form return(PartialView("Index", model)); }