public ActionResult Login(LoginModel model, string returnUrl) { var resultEntry = new JsonResultEntry() { Success = false }; try { if (Session != null) { Session.UserState = null; Session.SessionId = null; Session.Session.Clear(); } var abc = Sys_UserManager.Login(model.UserName, model.Password); if (ModelState.IsValid && Membership.ValidateUser(model.UserName, model.Password)) { FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe); if (CUtils.IsNullOrEmpty(returnUrl) || returnUrl == "/") { var url = Url.ActionLocalized("Index", "Home", new { area = "Auth" }); returnUrl = url; } resultEntry.Success = true; resultEntry.RedirectToOpener = true; resultEntry.RedirectUrl = returnUrl; } else { var exitsData = "Tên đăng nhập hoặc mật khẩu không hợp lệ!"; resultEntry.AddMessage(exitsData); } return(Json(resultEntry)); // If we got this far, something failed, redisplay form //ModelState.AddModelError("", "The user name or password provided is incorrect."); //return View(model); } catch (ValidationException valEx) { foreach (var ver in valEx.ValidationErrors) { resultEntry.AddFieldError(ver.FieldName, ver.ErrorMessage); } } catch (Exception e) { resultEntry.SetFailed().AddException(this, e); } resultEntry.AddModelState(ViewData.ModelState); return(Json(resultEntry)); }
public ActionResult Login(string returnUrl) { if (Session != null) { Session.UserState = null; Session.SessionId = null; Session.Session.Clear(); } Response.Cookies.Clear(); if (CUtils.IsNullOrEmpty(returnUrl)) { returnUrl = Url.ActionLocalized("Index", "Home", new { area = "Auth" }); } ViewBag.ReturnUrl = returnUrl; return(View()); }
protected virtual void Init() { var bUserStateNotNull = false; if (Session.UserState == null) { if (!SecurityHelper.TryLoginFromProviders(Session, Cache, HttpContext)) { bUserStateNotNull = false; FormsAuthentication.SignOut(); string action = this.RouteData.Values["action"].ToString(); if (!action.Equals("Login", StringComparison.InvariantCultureIgnoreCase)) { var rawUrl = Request.RawUrl; var culture = CUtils.StrValue(RouteData.Values["Culture"]); var isCulture = false; if (!CUtils.IsNullOrEmpty(culture)) { var cList = Client.Core.Configuration.SiteConfiguration.Current.AcceptedCultures; foreach (var c in cList) { if (c.TwoLetterISOLanguageName.Equals(culture, StringComparison.InvariantCultureIgnoreCase)) { isCulture = true; culture = c.TwoLetterISOLanguageName; System.Web.HttpContext.Current.Session["Culture"] = culture; break; } } } if (!isCulture) { culture = SiteConfiguration.Current.DefaultCultureName; if (!CUtils.IsNullOrEmpty(culture)) { culture = culture.Substring(0, 2); } RouteData.Values["Culture"] = culture; rawUrl = Url.ActionLocalized("Index", "Home", new { area = "Auth" }); } var redirect = Url.ActionLocalized("Login", "Account", new { area = "Auth", returnUrl = rawUrl }); //redirect = Url.Action("Login", "Account", new { area = "Auth", returnUrl = Request.RawUrl }); Response.Redirect(redirect); } } else { bUserStateNotNull = true; } } else { bUserStateNotNull = true; } if (bUserStateNotNull) { var sysUser = Session.UserState.SysUser; if (sysUser != null) { if (CUtils.IsNullOrEmpty(FullName)) { if (!CUtils.IsNullOrEmpty(sysUser.FullName)) { FullName = CUtils.StrTrim(sysUser.FullName); } } } ViewBag.Fullname = FullName; } if (PageSizeAdminConfig == 0) { var pageSizeAdminConfig = System.Configuration.ConfigurationManager.AppSettings["PageSizeAdminConfig"]; if (!CUtils.IsNullOrEmpty(pageSizeAdminConfig)) { PageSizeAdminConfig = CUtils.ConvertToInt32(pageSizeAdminConfig); } else { PageSizeAdminConfig = 10; } } }