private bool ValidateLogOn(string userName, string password, out UserModel loginUser) { loginUser = null; if (string.IsNullOrEmpty(userName)) { ModelState.AddModelError("errorMsg", "用户名为空"); return(false); } if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("errorMsg", "密码为空"); return(false); } UserModel user = _userService.Get(t => t.UserName == userName); if (user == null) { ModelState.AddModelError("errorMsg", "用户名不存在"); return(false); } string pwdhash = MD5Helper.ComputeMD5((userName + password).Trim()); if (user.Password != pwdhash) { ModelState.AddModelError("errorMsg", "用户名与密码不匹配"); return(false); } loginUser = user; return(true); }
public async Task <ActionResult> AskUser(bool confirm = false) { bool flag = (bool)(Session["_askuser_"] ?? false), remember = (bool)(Session["_remember_"] ?? false); string username = (Session["_tempuser_"] ?? "").ToString(); Session.Remove("_askuser_"); Session.Remove("_remember_"); Session.Remove("_tempuser_"); if (!flag || string.IsNullOrEmpty(username)) { return(this.RedirectToAction("Index", "Home")); } if (confirm) { UserModel user = RedisHelper.GetUserInfo(username) ?? _userService.Get(obj => obj.UserName == username); if (user == null) { return(this.RedirectToAction("Index", "Home")); } //退出当前用户 this._formsAuth.SignOut(username, true); //登录 this._formsAuth.SignIn(user, remember); } return(await this.SendResponse(confirm)); }
//[Route("/")] public ActionResult <List <UserModel> > Get() => this.HandleServiceResponse(_userService.Get());