public virtual async Task <JsonResult> CheckLogin(VmAdminLogin vm, string returnUrl = "", string returnUrlHash = "") { try { //returnUrl = NormalizeReturnUrl(returnUrl); if (!string.IsNullOrWhiteSpace(returnUrlHash)) { returnUrl = returnUrl + returnUrlHash; } var loginResult = await GetLoginResultAsync(vm.txtUserName, vm.txtPassword, GetTenancyNameOrNull()); await _signInManager.SignInAsync(loginResult.Identity, vm.RememberMe); await UnitOfWorkManager.Current.SaveChangesAsync(); //return Json(new AjaxResponse { TargetUrl = returnUrl }); //var loginResult = await _manager.CheckLogin(vm); //if (null == loginResult) //{ // return ResponseFail("系统繁忙,请稍后重试!"); //} //if (loginResult.Success) //{ //await _signInManager.SignOutAndSignInAsync(loginResult.Identity, true); return(ResponseSucc("登录成功", new { returnUrl = returnUrl })); //} //return ResponseFail(loginResult.Message); } catch (Exception ex) { return(ResponseException()); } }
public async Task <LoginRespose> CheckLogin(VmAdminLogin vm) { LoginRespose result = new LoginRespose() { Success = false }; try { var list = await _manager.GetAllAsync(c => c.user_name == vm.txtUserName); if (null == list) { result.Message = "账号不存在!"; return(result); } var managers = list.ToList(); if (managers.Count == 0) { result.Message = "账号不存在!"; return(result); } if (managers.Count > 1) { result.Message = "存在多个相同账号!"; return(result); } var model = managers.FirstOrDefault(); if (!model.password.Equals(vm.txtPassword.ToMd5())) { result.Message = "登录密码不正确!"; return(result); } if (model.is_lock == 1) { result.Message = "该账号已被锁定!"; return(result); } var claimsIdentity = new ClaimsIdentity("ApplicationCookie"); claimsIdentity.AddClaim(new Claim(ClaimTypes.Name, model.user_name)); var security = Guid.NewGuid().ToString(); claimsIdentity.AddClaim(new Claim(ClaimTypes.GroupSid, "1")); claimsIdentity.AddClaim(new Claim(ClaimTypes.Role, "")); claimsIdentity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity")); claimsIdentity.AddClaim(new Claim(ClaimTypes.System, "-1")); claimsIdentity.AddClaim(new Claim("AspNet.Identity.SecurityStamp", security)); claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, model.Id.ToString())); result.Success = true; result.Identity = claimsIdentity; return(result); } catch (Exception) { } return(result); }
public ActionResult Index(VmAdminLogin model) { if (!ModelState.IsValid) { return(View(model)); } if (model.Password == Properties.Settings.Default.AdminPassword) { //授权 AspFormsAuthentication.SetAuthenticationToken("Admin", new[] { "Admin" }, true); //跳到AdminHome return(RedirectToAction("AdminHome")); } ModelState.AddModelError("", "密码错误!"); return(View(model)); }