public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { try { if (!ModelState.IsValid) { return(View(model)); } AspNetUser user = null; //get user login by either email or only username if (model.Email.Contains("@")) { user = await UserManager.FindByEmailAsync(model.Email); } else { user = await UserManager.FindByNameAsync(model.Email); } if (user != null) { if (!await UserManager.IsEmailConfirmedAsync(user.Id)) { ModelState.AddModelError("", "Email not confirmed"); return(View(model)); } else { if (user.LockoutEnabled) { ModelState.AddModelError("", "User Is locked, Please contact admin to unlock the user"); return(View(model)); } else { var role = user.AspNetRoles.FirstOrDefault(); if (role.Id == Utility.MemberRoleId) { //Commenting ToysWorld //if (string.IsNullOrEmpty(user.RegisterPayPalTxnID )) //{ // return RedirectToAction("Pricing","Account", new { vkpy = user.Email }); //} } } } } // This doen't count login failures towards lockout only two factor authentication // To enable password failures to trigger lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(user != null?user.UserName : "", model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: { Session["ClientGMT"] = model.TimeOffset / 60; SetUserPermissions(user.Email); SetCultureInfo(user.Id); var role = user.AspNetRoles.FirstOrDefault(); if (role.Id == Utility.MemberRoleId) { return(RedirectToAction("Index", "Dashboard")); } if (string.IsNullOrEmpty(returnUrl)) { return(RedirectToAction("Index", "Dashboard")); } return(RedirectToLocal(returnUrl)); } case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } } catch (Exception ex) { return(View("Error", new { e = ex.Message })); } }
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { try { //if (string.IsNullOrEmpty(returnUrl)) // returnUrl = "/Home/Index"; if (!ModelState.IsValid) { return View(model); } var user = await UserManager.FindByNameAsync(model.Email); if (user != null) { if (!await UserManager.IsEmailConfirmedAsync(user.Id)) { ModelState.AddModelError("", "Email not confirmed"); return View(model); } else { if (user.LockoutEnabled) { ModelState.AddModelError("", "User Is locked, Please contact admin to unlock the user"); return View(model); } else { var role = user.AspNetRoles.FirstOrDefault(); if (role.Id == Utility.MemberRoleId) { if (string.IsNullOrEmpty(user.RegisterPayPalTxnID )) { return RedirectToAction("Pricing","Account", new { vkpy = user.Email }); } } } } } // This doen't count login failures towards lockout only two factor authentication // To enable password failures to trigger lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); switch (result) { case SignInStatus.Success: { SetUserPermissions(user.Email); SetCultureInfo(user.Id); var role = user.AspNetRoles.FirstOrDefault(); if (role.Id == Utility.MemberRoleId) { return RedirectToAction("Index", "Home"); } if (string.IsNullOrEmpty(returnUrl)) return RedirectToAction("Home", "Admin"); return RedirectToLocal(returnUrl); } case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.RequiresVerification: return RedirectToAction("SendCode", new { ReturnUrl = returnUrl }); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return View(model); } } catch (Exception ex) { return RedirectToAction("Error"); } }