public ActionResult Login(AccountModel userLoginData) { User login = Mapper.Map <AccountModel, User>(userLoginData); User user = userManager.CheckLogin(login); if (user != null) { User ValidatedUser = userManager.CheckLogin(login); FormsAuthentication.SetAuthCookie(ValidatedUser.Email, false); var authTicket = new FormsAuthenticationTicket(1, ValidatedUser.Email, DateTime.Now, DateTime.Now.AddMinutes(30), false, ValidatedUser.Role); string encryptedTicket = FormsAuthentication.Encrypt(authTicket); var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); HttpContext.Response.Cookies.Add(authCookie); if (ValidatedUser.Role == "admin") { Session["Email"] = ValidatedUser.Role; Session["UserId"] = ValidatedUser.UserId; TempData["Message"] = ValidatedUser.Role; return(RedirectToAction("UserDashBoard")); } else if (ValidatedUser.Role != null) { Session["Email"] = ValidatedUser.Role; Session["UserId"] = ValidatedUser.UserId; TempData["Message"] = ValidatedUser.Role; return(RedirectToAction("UserDashBoard")); } } else { TempData["Message"] = "Incorrect UserName or Password"; } return(View()); }
public UserModel Login(UserModel usermodel) { UserBusinessLogic UserBL = new UserBusinessLogic(); return(UserBL.CheckLogin(usermodel)); }