public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { try { if (ModelState.IsValid) { var user = LoginCmd.Execute(model.UserName, model.Password); if (user != null) { FormsAuthentication.SetAuthCookie(user.Identity.Name, false); if (ControllerContext.HttpContext.Session != null) { ControllerContext.HttpContext.Session["user"] = model.UserName; } //System.Web.HttpContext.Current.User =new System.Security.Principal.GenericPrincipal() FormsAuthentication.RedirectFromLoginPage(model.UserName, false); return(RedirectToLocal("~/JusHome/Index")); } } model.ShowMessage = true; return(View("Login", model)); } catch (Exception ex) { ModelState.AddModelError("", ManejadorExcepciones.GetMensaje(ex)); //Flash.Error(); } return(null); //return System.Web.UI.WebControls.View(model); }
void OnErrorOccur(object sender, ModelEventArgs e) { switch (e.Type) { case ModelEventType.Exception: Forms.MessageBox.Show(e.ModelException.Message); break; case ModelEventType.ConnectMeesage: FailedMessage = e.FailedMessage; break; case ModelEventType.ErrorMessage: MessageBox.Show(e.ErrorMessage); break; case ModelEventType.ServerTimeout: _tickTimer.Stop(); Forms.MessageBox.Show(e.ErrorMessage); LoginCmd.Execute(null); break; default: break; } }
public LoginViewModel(Action closeAction) { //关闭窗口 this._closeAction = closeAction; //自动登录 if (IsAutoLogin) { LoginCmd.Execute(null); } }
public LoginViewModel(Action closeAction) { //关闭窗口 _closeAction = closeAction; InitUserConfig(); InitCommand(); //自动登录 if (IsAutoLogin) { LoginCmd.Execute(); } }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { try { if (ModelState.IsValid) { //var user = await UserManager.FindAsync(model.UserName, model.Password); //LoginCmd.Execute(model.UserName, model.Password); //if (user != null) //JusNucleo.Bl.LoginCmd.Execute(model.UserName, model.Password) //Membership.ValidateUser(model.UserName, model.Password); var user = LoginCmd.Execute(model.UserName, model.Password); if (user != null) { //AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); //var identity = await UserManager.CreateIdentityAsync(A, DefaultAuthenticationTypes.ApplicationCookie); //AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); //SignInAsync(user, model.RememberMe); FormsAuthentication.SetAuthCookie(user.Identity.Name, false); //var x=UsuarioActual.Login; //var usuario = UsuarioActual; return(RedirectToLocal("./Principal")); } else { ModelState.AddModelError("", "Usuario o clave Incorrecta"); } } // If we got this far, something failed, redisplay form return(View(model)); } catch (Exception ex) { ModelState.AddModelError("", ManejadorExcepciones.GetMensaje(ex)); //Flash.Error(); } return(View(model)); }
public void Logear() { RegisterDependency.Init(); Assert.AreEqual(true, LoginCmd.Execute("admin", "Adm1nAdm1n").Identity.IsAuthenticated); }