public async Task <IActionResult> Login(LoginModel model) { if (ModelState.IsValid) { bool isDataRight = _accountLogic.Login(model.Email, model.Password); if (isDataRight) { ClaimsPrincipal id = _accountLogic.Authenticate(model.Email); // аутентификация await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(id)); return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("Incorrect password", "Некорректные данные"); } return(View(model)); }
public ActionResult Login(LoginModel login) { if (ModelState.IsValid) { User = Accounts.Authenticate(login); string role = User.Select(x => x.RoleName).FirstOrDefault().ToString(); string UserName = User.Select(x => x.UserName).FirstOrDefault().ToString(); string UserID = User.Select(x => x.AuthenticatedUserID).FirstOrDefault().ToString(); string UserImage = User.Select(x => x.UserImage).FirstOrDefault().ToString(); string DoctorID = User.Select(x => x.DoctorID).FirstOrDefault().ToString(); Session["UserName"] = UserName; Session["UserID"] = UserID; Session["UserImage"] = UserImage; Session["DoctorID"] = DoctorID; if (role == "SupplyChain") { return(Redirect("/SupplyChain/DashBoard/")); } if (role == "Pharmacy") { return(Redirect("/Pharmecy/DashBoard/")); } if (role == "HRManager") { return(Redirect("/DashBoard/HRIndex")); } if (role == "Doctor") { return(Redirect("/DashBoard/DoctorPanel")); } if (role == "Admin") { return(Redirect("/DashBoard/Admin")); } if (role == "FDManager") { return(Redirect("/FrontDesk/DashBoard/")); } else { return(View()); } } else { return(View()); } }
public ActionResult AuthenticateUser(User user) { var curUser = _context.GetByUsername(user.Username); if (_context.Authenticate(user)) { //authentication successful Session["id"] = curUser.Id; Session["Password"] = curUser.Password; Session["Username"] = curUser.Username; Session["Role"] = curUser.Role; if (_bankConfigContext.GetConfig() != null)//if bank has been set up create session for financial date { Session["FinancialDate"] = _bankConfigContext.GetConfig().FinancialDate; } if ((string)Session["Role"] == $"Admin") { var bankConfig = _bankConfigContext.GetConfig(); if (bankConfig == null)//if bank configuration is not set show the button to setup bank { Session["setup"] = "start"; } else { Session["isBusinessOpen"] = bankConfig.IsBusinessOpen; } return(RedirectToAction("AdminDashboard", "Users")); } if (curUser.PasswordStatus == false) { //user using default password return(RedirectToAction("ChangePassword", "Users")); } if ((string)Session["Role"] == $"Teller" && curUser.PasswordStatus) { //user has changed password return(RedirectToAction("TellerDashboard", "Users")); } } ViewBag.msg = "Incorrect Username or Password"; return(View("LoginForm")); }