public async Task UpdateRoleAuth(long id, RoleUpdateAuthInput input) { var role = await _roleDomainService.Get(id); role.AuthNumbers = null; if (input.ModuleIds?.Count > 0) { var modules = await _moduleRep.GetListAsync(input.ModuleIds); var maxLayer = modules.Max(a => a.Layer); var authNumbers = new List <long>(); for (int i = 1; i <= maxLayer; i++) { var authNumber = 0L; var items = modules.Where(a => a.Layer == i); foreach (var x in items) { authNumber = authNumber | x.Number.Value; } authNumbers.Add(authNumber); } role.AuthNumbers = JsonConvert.SerializeObject(authNumbers); } var users = await _userRep.GetListAsync(new UserQuery() { RoleLevel = role.Level }); var ids = users.Where(a => a.AuthNumbers != role.AuthNumbers).Select(a => a.Id).ToList(); await _roleDomainService.UpdateRoleAuth(role); await _userRep.UpdateAuth(role.Id, role.AuthNumbers); //注销该角色下用户的登录信息 if (ids.Count < 1) { return; } await _publisher.PublishAsync(nameof(LogoutForUpdateAuthEventData), new LogoutForUpdateAuthEventData { UserIds = ids }); }
public async Task Add(UserAddInput input) { var user = input.Adapt <SysUser>(); user.FirstNameInitial = WordsHelper.GetFirstPinyin(user.Name.Substring(0, 1)); user.PasswordLevel = (PasswordLevel)H_Util.CheckPasswordLevel(user.Password); user.Password = H_EncryptProvider.HMACSHA256(user.Password, _appSettings.Key.Sha256Key); user.Enabled = true; var role = await _roleDomainService.Get(input.RoleId.Value); user.RoleId = role.Id; user.RoleName = role.Name; user.AuthNumbers = role.AuthNumbers; user.RoleLevel = role.Level; await _userDomainService.Add(user); }
public async Task <GetRoleOutput> Get(long id) { return(await _roleDomainService.Get(id)); }