private UserPermissionCacheItem GetUserPermissionCacheItem(long userId) { var cacheKey = userId + "@" + (GetCurrentTenantId() ?? 0); return(_cacheManager.GetUserPermissionCache().Get(cacheKey, () => { var user = AbpUserStore.FindById(userId.ToString()); if (user == null) { return null; } var newCacheItem = new UserPermissionCacheItem(userId); foreach (var roleName in AbpUserStore.GetRoles(user)) { newCacheItem.RoleIds.Add((RoleManager.GetRoleByName(roleName)).Id); } foreach (var permissionInfo in UserPermissionStore.GetPermissions(userId)) { if (permissionInfo.IsGranted) { newCacheItem.GrantedPermissions.Add(permissionInfo.Name); } else { newCacheItem.ProhibitedPermissions.Add(permissionInfo.Name); } } return newCacheItem; })); }
/// <summary> /// Gets a user by given id. /// Throws exception if no user found with given id. /// </summary> /// <param name="userId">User id</param> /// <returns>User</returns> /// <exception cref="AbpException">Throws exception if no user found with given id</exception> public virtual TUser GetUserById(long userId) { var user = AbpUserStore.FindById(userId.ToString()); if (user == null) { throw new AbpException("There is no user with id: " + userId); } return(user); }
public bool IsLockedOut(string userId) { var user = AbpUserStore.FindById(userId); if (user == null) { throw new AbpException("There is no user with id: " + userId); } var lockoutEndDateUtc = AbpUserStore.GetLockoutEndDate(user); return(lockoutEndDateUtc > DateTimeOffset.UtcNow); }