public async Task <IList <UserDto> > GetUsersAsync() { IList <UserDto> users = null; if (!_cacheService.TryGetUsers(out users)) { users = await _usersClient.Get(); _cacheService.AddUsers(users); } return(users); }
public static async Task <User> GetProfile(HttpContext context, IUsersClient client, IIdentityDataGetter identityDataGetter) { var token = await identityDataGetter.GetAccessToken(context); var id = identityDataGetter.GetClaimId(context.User); var res = await client.Get(token, id); if (res == null) { if (await client.Create(token, id, new User { Name = identityDataGetter.GetClaimName(context.User), Email = identityDataGetter.GetClaimEmail(context.User) }) == null) { throw new System.Exception("Create user profile failed"); } res = await client.Get(token, id); } return(res); }
public async Task LoadUser(IUsersClient client, string token) { User = await client.Get(token, Data.UserId); if (User == null) { User = new User { Id = Data.UserId, Email = Data.UserId, Name = Data.UserId, }; } }
async Task ChangeState() { var state = _ropuClient.State; State = state.ToString(); switch (state) { case StateId.Start: case StateId.NoGroup: case StateId.Unregistered: PttColor = Gray; break; case StateId.Registered: case StateId.Deregistering: case StateId.StartingCall: PttColor = Blue; break; case StateId.InCallRequestingFloor: case StateId.InCallReleasingFloor: case StateId.InCallTransmitting: case StateId.InCallIdle: case StateId.InCallReceiving: PttColor = Green; break; default: throw new Exception("Unhandled Call State"); } Transmitting = state == StateId.InCallTransmitting; var callGroup = InCall(state) && _ropuClient.CallGroup.HasValue ? await _groupsClient.Get(_ropuClient.CallGroup.Value) : null; CallGroup = callGroup?.Name == null ? "" : callGroup.Name; CallGroupImage = callGroup?.Image; await SetupCircleText(state); var user = state == StateId.InCallReceiving ? (_ropuClient.Talker.HasValue ? await _usersClient.Get(_ropuClient.Talker.Value) : null) : null; Talker = user?.Name; if (user != null) { TalkerImage = await _imageClient.GetImage(user.ImageHash); } }
/// <summary> /// Query GitHub to get users in organization. This is not done /// in the constructor so that async capabilities can be used /// </summary> /// <param name="githubCredentials"></param> /// <returns></returns> private async Task <User[]> InitUsers(Credentials githubCredentials) { GitHubClient ghClient = new GitHubClient(new ProductHeaderValue("git-hub-client-for-byu-skills-test")); ghClient.Credentials = githubCredentials; // get the organization members IOrganizationMembersClient omc = ghClient.Organization.Member; IReadOnlyList <User> diminishedUsers = await omc.GetAll(orgName); // the users returned from an organization do not have all meta data. Get // the complete users using the direct user client IUsersClient uc = ghClient.User; return(await Task.WhenAll(diminishedUsers.Select(x => uc.Get(x.Login)))); }
public async Task <FilteredResutsDto <ProjectDto> > GetProjectsAsync(ProjectsFilterDto filter, string userId) { IList <ProjectDto> projects = null; if (!_cacheService.TryGetProjects(out projects)) { var projectsTask = _projectsClient.Get(); var usersTask = _usersClient.Get(); projects = await projectsTask; CleanProjectsAccessTokens(projects); var users = await usersTask; AddOwnersToProjects(projects, users); _cacheService.AddProjectsToCache(projects); } IEnumerable <ProjectDto> query = projects; query = FilterByName(filter, query); query = FilterByDescription(filter, query); query = FilterByGroups(filter, query); query = FilterByTags(filter, query); query = FilterByLimitedAccess(filter, query, userId); var allResults = query.Count(); query = query.OrderBy(x => x.Name); if (filter.Limit > 0) { query = query.Skip(filter.Page * filter.Limit).Take(filter.Limit); } var filteredResults = new FilteredResutsDto <ProjectDto> { Results = query, AllResults = allResults }; return(filteredResults); }
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, HasAccessToManageUsersRequirement requirement) { if (context.User.Identity.AuthenticationType == "SecureToken") { if (context.User.Identity.Name == "System") { context.Succeed(requirement); } } else if (context.User.Identity.AuthenticationType == "Bearer" || context.User.Identity.AuthenticationType == "AuthenticationTypes.Federation" || context.User.Identity.AuthenticationType == "UserToken") { var userId = context.User.Identity.Name.ToLower(); var user = await _usersClient.Get(userId); if (user != null && (user.Role == RoleEnumDto.Administrator)) { context.Succeed(requirement); } } }
/// <summary> /// Returns the user specified by the login. /// </summary> /// <param name="login">The login name for the user</param> public IObservable <User> Get(string login) { Ensure.ArgumentNotNull(login, "login"); return(_client.Get(login).ToObservable()); }
public async Task <IActionResult> OnGetAsync(int id, int?pageIndex) { string token = await idData.GetAccessToken(HttpContext); Token = token; try { Data = new CategoriesViewModel { Data = await client.Get(token, id) }; if (Data.Data.UserId != idData.GetClaimId(User)) { Onwer = await usersClient.Get(token, Data.Data.UserId); } Paging = new PagingSettings { ItemCountPerPage = 8, RouteData = new Dictionary <string, string> { ["id"] = Data.Data.Id.ToString(), } }; IEnumerable <Note> notes; { int count = (await nodesClient.Query(token, categoryId: Data.Data.Id, targets: NoteTargets.Count)).Count(); Paging.MaximumIndex = (count / Paging.ItemCountPerPage) + (count % Paging.ItemCountPerPage > 0 ? 1 : 0); if (!pageIndex.HasValue) { pageIndex = 1; } Paging.CurrentIndex = pageIndex.Value; int offset = (Paging.CurrentIndex - 1) * Paging.ItemCountPerPage; notes = await nodesClient.Query(token, categoryId : Data.Data.Id, offset : offset, count : Paging.ItemCountPerPage); Notes = notes.ToList(); } /*{ * Dictionary<int, Relation> rs = new Dictionary<int, Relation>(); * foreach (Note v in notes) * { * foreach (Relation r in await relationsClient.GetAdjacents(token, v.Id)) * { * if (rs.ContainsKey(r.Id)) * { * continue; * } * * rs.Add(r.Id, r); * } * } * Graph = new GraphViewModel * { * Graph = await RelationHelper.GenerateGraph(nodesClient, client, rs.Values, token) * }; * }*/ } catch { return(NotFound()); } return(Page()); }
private async Task <User> GetUserProfile(string id) { return(await _usersClient.Get(id)); }
public static async Task <User> GetProfile(string id, HttpContext context, IUsersClient client, IIdentityDataGetter identityDataGetter) { return(await client.Get(await identityDataGetter.GetAccessToken(context), id)); }