public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); if (ModelState.IsValid) { if (model.Email != "*****@*****.**") { Session["Email"] = model.Email; TempData["id"] = Session["IDUser"]; TempData["name"] = Session["FullName"]; FormsAuthentication.SetAuthCookie(model.Email, false); return(RedirectToAction("Index", "Home")); } else { UserBusinessLayer businessLayer = new UserBusinessLayer(); if (businessLayer.IsValidUser(model)) { FormsAuthentication.SetAuthCookie(model.Email, true); return(RedirectToAction("Index", "HomeAdmin")); } else { ModelState.AddModelError("CredentialError", "Invalid User or Password"); return(View("Login")); } } } switch (result) { case SignInStatus.Success: return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
public ActionResult DoLogin(User u) { UserBusinessLayer userBL = new UserBusinessLayer(); if (userBL.IsValidUser(u)) { FormsAuthentication.SetAuthCookie(u.UserName, false); Session["UserName"] = u.UserName; Session["UserId"] = u.Id; Session["Roles"] = userBL.GetRoles(u.UserName); //MoodlePrincipal moodlePrincipal = new MoodlePrincipal(u.UserName, u.Password); //moodlePrincipal.RoleList = new ArrayList(userBL.GetRoles(u.UserName).Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)); //HttpContext.User = moodlePrincipal; return(RedirectToAction("Index", "Student")); } else { ModelState.AddModelError("CredentialError", "Invalid Username or Password"); return(View("Login")); } }