public virtual async Task Unlink(UserIdentifier userIdentifier) { var targetUserAccount = await GetUserAccountAsync(userIdentifier); targetUserAccount.UserLinkId = null; await CurrentUnitOfWork.SaveChangesAsync(); }
//This is for test purposes public async Task SendMessageAsync(UserIdentifier user, string message, NotificationSeverity severity = NotificationSeverity.Info) { await _notificationPublisher.PublishAsync( "App.SimpleMessage", new MessageNotificationData(message), severity: severity, userIds: new[] { user } ); }
public async Task SaveSettingMenusAsync(long?userId, string settingStr) { if (userId.HasValue) { var userIdentifier = new Abp.UserIdentifier(AbpSession.TenantId, userId.Value); await SettingManager.ChangeSettingForUserAsync(userIdentifier, SettingNames.MenuSetting, settingStr); } else if (AbpSession.TenantId.HasValue) { await SettingManager.ChangeSettingForTenantAsync(AbpSession.TenantId.Value, SettingNames.MenuSetting, settingStr); } }
public virtual async Task<bool> AreUsersLinked(UserIdentifier firstUserIdentifier, UserIdentifier secondUserIdentifier) { var firstUserAccount = await GetUserAccountAsync(firstUserIdentifier); var secondUserAccount = await GetUserAccountAsync(secondUserIdentifier); if (!firstUserAccount.UserLinkId.HasValue || !secondUserAccount.UserLinkId.HasValue) { return false; } return firstUserAccount.UserLinkId == secondUserAccount.UserLinkId; }
public async Task SaveSettingMenusAsync(long?userId, List <MenuItemDefinition> menuItems) { var settingStr = Newtonsoft.Json.JsonConvert.SerializeObject(menuItems); if (userId.HasValue) { var userIdentifier = new Abp.UserIdentifier(AbpSession.TenantId, userId.Value); await SettingManager.ChangeSettingForUserAsync(userIdentifier, SettingNames.MenuSetting, settingStr); } else if (AbpSession.TenantId.HasValue) { await SettingManager.ChangeSettingForTenantAsync(AbpSession.TenantId.Value, SettingNames.MenuSetting, settingStr); } }
public virtual async Task<UserAccount> GetUserAccountAsync(UserIdentifier userIdentifier) { return await _userAccountRepository.FirstOrDefaultAsync(ua => ua.TenantId == userIdentifier.TenantId && ua.UserId == userIdentifier.UserId); }
public async Task<JsonResult> Authenticate([FromBody] AuthenticateModel model) { //AuthenticateResultModel 返回的字典类型 SortedDictionary<string, object> DgDict = new SortedDictionary<string, object>(); //返回登录结果 var loginResult = await GetLoginResultAsync( model.UserNameOrEmailAddress, model.Password, GetTenancyNameOrNull() ); AbpClaimTypes.UserId = loginResult.User.Id.ToString(); #region 角色列表版本 暂时没用 DgDict.Add("permissionsToRolesVersion", 1001); #endregion #region 获取所有权限列表 var Permissions = PermissionManager.GetAllPermissions(); Treelist = new List<TreeClass>(); TreeClass treeClass1 = new TreeClass(); treeClass1.id = 1; treeClass1.parentId = 0; treeClass1.label = Mapper.Map<PermissionDto>(Permissions.Where(x => x.Name == PermissionNames.Pages_Staff).FirstOrDefault()).DisplayName; treeClass1.Permission = Mapper.Map<PermissionDto>(Permissions.Where(x => x.Name == PermissionNames.Pages_Staff).FirstOrDefault()); Treelist = Recursion(Permissions.Where(x => x.Name == PermissionNames.Pages_Staff).FirstOrDefault(), 1); Treelist.Add(treeClass1); DgDict.Add("allPermissions", new ListResultDto<PermissionDto>( ObjectMapper.Map<List<PermissionDto>>(Permissions) )); try { DgDict.Add("allPermissionsForTree", Treelist); } catch (Exception ex) { } num = 1; //权限列表 List<Permission> allPermissions = new List<Permission>(); foreach (var item in Permissions) { allPermissions.Add(item); } #endregion #region 角色列表 //var allRoles = await _roleRepository.GetAllListAsync(); var allRoleIReadOnlyList = await _roleRepository.GetAllListAsync(); List<Role> allRoles = new List<Role>(); foreach (var item in allRoleIReadOnlyList.Where(x=>x.IsDeleted==false).ToList()) { allRoles.Add(item); } DgDict.Add("allRoles", Mapper.Map<List<RoleListDto>>(allRoles)); //DgDict.Add("allRoles", new ListResultDto<RoleListDto>(ObjectMapper.Map<List<RoleListDto>>(allRoles))); //new ListResultDto<RoleListDto>(ObjectMapper.Map<List<RoleListDto>>(allRoles)); #endregion //获取登录用户的所拥有的所有权限 var grantedPermissionNames = new List<string>(); if (loginResult.User.Id>0) { foreach (var permissionName in allPermissions) { Abp.UserIdentifier Identifier=UserIdentifier.Parse(loginResult.User.Id.ToString()); if (await PermissionChecker.IsGrantedAsync(Identifier, permissionName.Name)) { grantedPermissionNames.Add(permissionName.Name); // 获取当前用户的权限 } } } #region 是否有审核权 canAssignInspectionToOther bool canAssignInspectionToOther = await PermissionChecker.IsGrantedAsync(UserIdentifier.Parse(loginResult.User.Id.ToString()), PermissionNames.Pages_Inspection); if (!canAssignInspectionToOther) { DgDict.Add("canAssignInspectionToOther", "没有Pages_Inspection"); DgDict.Add("canAssignInspectionToOtherValue", false); } else { DgDict.Add("canAssignInspectionToOther", "拥有Pages_Inspection"); DgDict.Add("canAssignInspectionToOtherValue", true); } #endregion bool canAssignRolesFromAdmin = await PermissionChecker.IsGrantedAsync(UserIdentifier.Parse(loginResult.User.Id.ToString()), PermissionNames.Pages_Tenants); bool canAssignRolesFromRQAdmin = await PermissionChecker.IsGrantedAsync(UserIdentifier.Parse(loginResult.User.Id.ToString()), PermissionNames.Pages_Admin); bool canAssignRolesFromRQAssitant = await PermissionChecker.IsGrantedAsync(UserIdentifier.Parse(loginResult.User.Id.ToString()), PermissionNames.Pages_RQAssitant); #region 可分配角色列表--针对员工管理 List<Role> RolescanAssigned = allRoles; List<string> RolescanAssignedString = new List<string>();//角色名数组初始化 foreach (var item in allRoleIReadOnlyList.Where(x => x.IsDeleted == false).ToList()) { RolescanAssignedString.Add(item.Name); } //如果任务已经分配且未分配给自己,且不具有分配任务权限,则抛出异常 if (canAssignRolesFromAdmin) { List<Role> allmyRoles = new List<Role>();//当前用户可分配的角色 初始化 string[] outAdmin = { "Admin"}; foreach (var item in outAdmin) { if (RolescanAssignedString.Contains(item)) { RolescanAssignedString.Remove(item); } //item.SetNormalizedName in } foreach (var itemStr in RolescanAssignedString) { foreach (var item in allRoles) { if (item.Name == itemStr) { allmyRoles.Add(item); } } } DgDict.Add("RolescanAssigned", Mapper.Map<List<RoleDto>>(allmyRoles)); } else if (canAssignRolesFromRQAdmin) { List<Role> allmyRoles = new List<Role>();//当前用户可分配的角色 初始化 string[] outAdmin = { "Admin","RQAdmin","RQAdminPermissions"}; foreach (var item in outAdmin) { if (RolescanAssignedString.Contains(item)) { RolescanAssignedString.Remove(item); } //item.SetNormalizedName in } foreach (var itemStr in RolescanAssignedString) { foreach (var item in allRoles) { if (item.Name == itemStr) { allmyRoles.Add(item); } } } DgDict.Add("RolescanAssigned", Mapper.Map<List<RoleDto>>(allmyRoles)); } else if (canAssignRolesFromRQAssitant) { string[] outAdmin = { "Admin", "RQAssitantPermissions", "RQAdmin" , "RQAssitant" ,"RQAdminPermissions"}; List<Role> allmyRoles = new List<Role>();//当前用户可分配的角色 初始化 foreach (var item in outAdmin) { if (RolescanAssignedString.Contains(item)) { RolescanAssignedString.Remove(item); } //item.SetNormalizedName in } foreach (var itemStr in RolescanAssignedString) { foreach (var item in allRoles) { if (item.Name == itemStr) { allmyRoles.Add(item); } } } DgDict.Add("RolescanAssigned", Mapper.Map<List<RoleDto>>(allmyRoles)); } else { DgDict.Add("RolescanAssigned", null); } #endregion #region 可分配权限列表【角色管理-分配权限】 var PermissionscanAssigned = allPermissions; List<string> PermissionscanAssignedString = new List<string>(); foreach (var item in PermissionscanAssigned) { PermissionscanAssignedString.Add(item.Name); } if (canAssignRolesFromAdmin) { DgDict.Add("PermissionscanAssigned", Mapper.Map<List<PermissionDto>>(PermissionscanAssigned)); } else if (canAssignRolesFromRQAdmin) { List<Permission> allMyPermission = new List<Permission>();//当前用户可分配的权限 初始化 string[] outAdmin = {"Pages","Pages.Tenants", "Pages.Users", "Pages.Roles", "Pages.Admin", "Pages.Admin.Users","Pages.Admin.Roles" }; foreach (var item in outAdmin) { if (PermissionscanAssignedString.Contains(item)) { PermissionscanAssignedString.Remove(item); } } foreach (var itemStr in PermissionscanAssignedString) { foreach (var item in PermissionscanAssigned) { if (item.Name == itemStr) { allMyPermission.Add(item); } } } DgDict.Add("PermissionscanAssigned", Mapper.Map<List<PermissionDto>>(allMyPermission)); } else if (canAssignRolesFromRQAssitant) { List<Permission> allMyPermission = new List<Permission>();//当前用户可分配的权限 初始化 string[] outAdmin = {"Pages","Pages.Tenants", "Pages.Users", "Pages.Roles", "Pages.Admin", "Pages.Admin.Users","Pages.Admin.Roles", "Pages.RQAssitant.Roles", "Pages.RQAssitant.Users", "Pages.RQAssitant" }; foreach (var item in outAdmin) { if (PermissionscanAssignedString.Contains(item)) { PermissionscanAssignedString.Remove(item); } } foreach (var itemStr in PermissionscanAssignedString) { foreach (var item in PermissionscanAssigned) { if (item.Name == itemStr) { allMyPermission.Add(item); } } } DgDict.Add("PermissionscanAssigned", Mapper.Map<List<PermissionDto>>(allMyPermission)); } else { DgDict.Add("PermissionscanAssigned", null); } #endregion #region 登录返回UserId-accessToken--EncryptedAccessToken-ExpireInSeconds var accessToken = CreateAccessToken(CreateJwtClaims(loginResult.Identity)); DgDict.Add("AuthenticateResultModel", new AuthenticateResultModel { AccessToken = accessToken, EncryptedAccessToken = GetEncrpyedAccessToken(accessToken), ExpireInSeconds = (int)_configuration.Expiration.TotalSeconds, UserId = loginResult.User.Id } ); #endregion return Json(DgDict); }