public IActionResult LoginIndex(LoginModel model) { string r = HttpContext.Session.GetString(R_KEY); r = r ?? ""; //类似于三木运算符 if (!ModelState.IsValid) { AjaxData.Message = "请输入用户账号和密码"; return(Json(AjaxData)); } var result = _sysUserService.validateUser(model.Account, model.Password, ""); AjaxData.Status = result.Item1; AjaxData.Message = result.Item2; if (result.Item1) { //保存登录信息 ClaimsIdentity.ClaimsPrincipal _authenticationService.signIn(result.Item3, result.Item4.Name); } else { //登录失败 } return(Json(AjaxData)); }
public IActionResult LoginIndex(LoginModel model) //loginModel处理登录的事 { string r = HttpContext.Session.GetString(R_KEY); r = r ?? ""; //admin abc123 if (!ModelState.IsValid) { AjaxData.Message = "请输入用户账号和密码"; return(Json(AjaxData)); } //var result= _sysUserService.validateUser(model.Account,model.Password,""); var result = _sysUserService.validateUser(model.Account, model.Password, r); //这里成功后就写入了 AjaxData.Status = result.Item1; AjaxData.Message = result.Item2; if (result.Item1) { //_authenticationService.signIn(result.Item3, result.Item4.Name); //保存登录状态 ClasimsIdentity,ClaimsPrincipal //HttpContext.SignInAsync() //登录成功后需要写入token表中 _authenticationService.signIn(result.Item3, result.Item4.Name); } else { //失败也这样 } return(Json(AjaxData)); }
public IActionResult LoginIndex(LoginModel model) { string r = HttpContext.Session.GetString(R_KEY); r = r ?? ""; if (!ModelState.IsValid) { AjaxData.Message = "请输入用户账号和密码"; return(Json(AjaxData)); } var result = _sysUserService.validateUser(model.Account, model.Password, r); AjaxData.Status = result.Item1; AjaxData.Message = result.Item2; if (result.Item1) { _authenticationService.signIn(result.Item3, result.Item4.Name); } return(Json(AjaxData)); }
public IActionResult LoginIndex(LoginModel model) { string r = HttpContext.Session.GetString(R_KEY); r = r ?? ""; if (!ModelState.IsValid) { AjaxData.Message = "请输入用户账号和密码"; return(Json(AjaxData)); } var result = _sysUserService.validateUser(model.Account, model.Password, r); AjaxData.Status = result.Status; AjaxData.Message = result.Message; if (result.Item1) { //保存登录状态 ClaimsIdentity,ClaimPrincipal,Asp.Net HttpContext,Current _authenticationService.signIn(result.Token, result.User.Name); } return(Json(AjaxData)); }
public IActionResult LoginIndex(LoginModel model) { #region 判断验证码 //if (!ValidateCaptchaCode(model.CaptchaCode)) //{ // AjaxData.Success = false; // AjaxData.Message = ResultCodeAddMsgKeys.SignInCaptchaCodeErrorMsg; // return Json(AjaxData); //} #endregion #region 属性判断 LoginModelValidation validation = new LoginModelValidation(); ValidationResult results = validation.Validate(model); if (!results.IsValid) { AjaxData.Success = false; AjaxData.Message = results.ToString("||"); return(Json(AjaxData)); } #endregion #region 数据库验证 string r = HttpContext.Session.GetString(R_KEY); r = r ?? ""; var result = _baseUserService.ValidateUser(model.Account, model.Password, r); AjaxData.Success = result.Success; AjaxData.Message = result.Message; if (result.Success) { _authenticationService.signIn(result.Token, result.User.Account); } return(Json(AjaxData)); #endregion }