public async Task <ActionResult> Login(LoginModel model) { if (!ModelState.IsValid) { return(View(model)); } if (!VeryfyCodeUtility.IsVerifyCodeMatch(Session, model.ValidateCode)) { ModelState.AddModelError("ValidateCode", "验证码错误!"); return(View(model)); } var loginResult = await UsersRepository.Login(model.UserName, model.Password); if (loginResult.Status == SigninStatus.Succ) { FormsAuthSvc.CreateAuthenticationTicket(loginResult.UserInfo, Response, HttpContext, model.IsRemember); //添加到Fom if (model.IsRemember) { CookieUtils.SetCookie(FormsAuthSvc.GetUserNameCookieKey(), model.UserName, true); } else { CookieUtils.RemoveCookie(FormsAuthSvc.GetUserNameCookieKey()); } //添加登录日志 await SysOperationLogRepository.Insert(TableSource.Users, OperationType.UserLogin, "", ""); return(Redirect(Url.AdminHome())); } ModelState.AddModelError("UserName", "登录失败!" + loginResult.Status.GetDescriotion()); return(View(model)); }
public ActionResult Login(LoginModel model) { var result = new JsonModel(); #region check params if (model == null) { result.msg = "请输入数据!"; return(Json(result)); } if (string.IsNullOrEmpty(model.UserName)) { result.msg = "请输入用户名"; return(Json(result)); } if (string.IsNullOrEmpty(model.Password) || model.Password.Length < 6) { result.msg = "请输入正确的密码"; return(Json(result)); } if (string.IsNullOrEmpty(model.ValidateCode)) { result.msg = "请输入验证码"; return(Json(result)); } #endregion if (!VeryfyCodeUtility.IsVerifyCodeMatch(Session, model.ValidateCode)) { result.msg = "验证码错误!"; return(Json(result)); } var loginResult = UsersRepository.AdminLogin(model.UserName, model.Password); if (loginResult.Status == SigninStatus.Succ) { FormsAuthSvc.CreateAuthenticationTicket(loginResult.UserInfo, Response, HttpContext, model.IsRemember); //添加到Fom if (model.IsRemember) { CookieUtils.SetCookie(FormsAuthSvc.GetUserNameCookieKey(), model.UserName, true); } else { CookieUtils.RemoveCookie(FormsAuthSvc.GetUserNameCookieKey()); } //添加登录日志 SysOperationLogRepository.Insert(TableSource.Users, OperationType.UserLogin, loginResult.UserInfo.Id); result.code = JsonModelCode.Succ; return(Json(result)); } result.msg = "登录失败!" + loginResult.Status.GetDescriotion(); return(Json(result)); }
public async Task <ActionResult> LoginDialog(LoginModel model) { var result = new JsonModel(); if (!VeryfyCodeUtility.IsVerifyCodeMatch(Session, model.ValidateCode)) { ModelState.AddModelError("ValidateCode", "验证码错误!"); } if (!ModelState.IsValid) { result.GetError(ModelState); return(Json(result)); } var loginResult = await UsersRepository.Login(model.UserName, model.Password); if (loginResult.Status == SigninStatus.Succ) { FormsAuthSvc.CreateAuthenticationTicket(loginResult.UserInfo, Response, HttpContext, model.IsRemember); //添加到Fom if (model.IsRemember) { CookieUtils.SetCookie(FormsAuthSvc.GetUserNameCookieKey(), model.UserName, true); } else { CookieUtils.RemoveCookie(FormsAuthSvc.GetUserNameCookieKey()); } //添加登录日志 await SysOperationLogRepository.Insert(TableSource.Users, OperationType.UserLogin, "", ""); result.message = "登录成功!"; return(Json(result)); } result.statusCode = 300; result.message = "登录失败!" + loginResult.Status.GetDescriotion(); //result.Error.Add(new ErorrModel() {Key="UserName",Value= "登录失败!" + loginResult.Status.GetDescriotion() }); return(Json(result)); }
public ActionResult GetVerifyCode() { return(File(VeryfyCodeUtility.CreateVerifyImage(Session, 5), @"image/jpeg")); }