解释一下这行代码 async Task<LoginResultModel> PasswordSignInAsync(IAuthenticationManager authenticationManager, LoginViewModel model) { var obj = new { l = model.Account, p = Security.Encrypt(model.Password) }; LogHelper.Debug(JsonHelper.SerializeObject(obj)); var content = SSOHelper.GetLoginInfo(model.Account, model.Password); var content1 = SSOHelper.GetLoginInfo1(model.Account, model.Password); LogHelper.Debug(content); LoginResultModel result = JsonHelper.DeserializeObject<LoginResultModel>(content); LoginResultModel result1 = JsonHelper.DeserializeObject<LoginResultModel>(content1); ExceptionHelper.TrueThrow(result == null, "登录结果为空,请联系管理员!"); ExceptionHelper.TrueThrow(result.code == 500, result.message); string username = result.result.user_info.user_name; string usercode = model.Account; string dutyname = result.result.user_info.duty_name; string groupname = result.result.user_info.group_name; string usernametest = result.result.user_info.user_name; var Information = result.result.user_info; string password = result1.result.access_token; OnlineHistory aa = new OnlineHistory() { GWMCode = usercode, GWMName = username, GWMDuty = dutyname, GWMGroupName = groupname, OnlineTime = DateTime.Now, }; int useInsertOnlineHistory = OnlineHistoryDAL.Instance.InsertOnlineHistory(aa); ClaimsIdentity _identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie); _identity.AddClaim(new Claim(ClaimTypes.Name, username)); _identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, usercode)); _identity.AddClaim(new Claim(ClaimTypes.Role, dutyname)); _identity.AddClaim(new Claim(ClaimTypes.GroupSid, usercode)); _identity.AddClaim(new Claim(ClaimTypes.Actor, usernametest)); _identity.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity")); _identity.AddClaim(new Claim("DepartmentName", groupname)); _identity.AddClaim(new Claim("DutyName", dutyname)); _identity.AddClaim(new Claim("Password", password)); var Staffpermission = PermissionManageDAL.Instance.GetUersPermissionList(usercode.ToUpper()); var UseStaffpermission = Staffpermission.Select(m => new StaffPermissionItem { PermissionCode = m.PermissionCode }).ToList(); _identity.AddClaim(new Claim("Permissions", JsonHelper.SerializeObject(UseStaffpermission)));//用户的权限列表 authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = model.RememberMe }, _identity); return await Task.FromResult(result); }
时间: 2023-05-14 09:07:08 浏览: 105
这段代码的作用是进行登录操作。代码中的 `PasswordSignInAsync` 方法接受两个参数:`authenticationManager` 和 `model`。
在方法中,首先会创建一个匿名对象,包含账号和经过加密的密码。接着,使用 `SSOHelper.GetLoginInfo` 和 `SSOHelper.GetLoginInfo1` 方法获取登录信息,并使用 `JsonHelper.DeserializeObject` 将获取的信息反序列化为 `LoginResultModel` 类型的对象。然后,检查登录结果是否为空,或者返回码是否为 500。如果满足任意一个条件,就会抛出异常。
接下来,会创建一个 `ClaimsIdentity` 对象,并为其添加多个声明,包括用户名、用户代码、职位等信息。然后,使用 `PermissionManageDAL.Instance.GetUersPermissionList` 方法获取用户的权限列表,并将其添加为声明。最后,使用 `authenticationManager.SignIn` 方法登录用户,并返回登录结果。
阅读全文
相关推荐












