コード例 #1
0
        public async Task <IActionResult> Index(CancellationToken cancellationToken, string username = null, Guid?folderId = null, int offset = 0, int?limit = null)
        {
            var token = await GetAccessTokenAsync();

            if (token == null)
            {
                return(Forbid());
            }

            var offset_param = PagingOffset.NewPagingOffset(offset);
            var limit_param  = limit is int l
                ? PagingLimit.NewPagingLimit(l)
                : PagingLimit.MaximumPagingLimit;

            var resp = await DeviantArtFs.Api.Gallery.AsyncPageGallery(
                token,
                ObjectExpansion.None,
                username != null
                ?UserScope.NewForUser(username)
                : UserScope.ForCurrentUser,
                folderId is Guid ff
                ?GalleryFolderScope.NewSingleGalleryFolder(ff)
                : GalleryFolderScope.AllGalleryFoldersPopular,
                limit_param,
                offset_param).StartAsTask(cancellationToken: cancellationToken);

            ViewBag.Username = username;
            ViewBag.FolderId = folderId;
            ViewBag.Limit    = limit;
            return(View(resp));
        }
コード例 #2
0
 public IEnumerable <User> GetUsersWhoseAgeIsGreaterThan(int age)
 {
     return(_context.Users
            .AsNoTracking()
            .Where(UserScope.AgeGreaterThan(age))
            .ToList());
 }
コード例 #3
0
ファイル: UsersCommand.cs プロジェクト: Exeteres/Replica
        public OutMessage Scope([Protect(UserScope.Admin)] Chat chat, User user, UserScope scope)
        {
            var me        = Context.GetMember(null, chat);
            var target    = Context.GetMember(user, chat);
            var localizer = Context.GetLocalizer();

            if (target == null)
            {
                return(OutMessage.FromCode(localizer["TargetNotFound"]));
            }
            if (!Context.GetUser().IsSuperUser &&
                (me.Scope < target.Scope ||
                 (me.Scope != UserScope.Owner &&
                  target.Scope >= UserScope.Admin &&
                  scope >= UserScope.Admin)))
            {
                return(OutMessage.FromCode(localizer["AccessDenied"]));
            }
            var db = new RepoContext();

            target.Scope = scope;
            db.Update(target);
            db.SaveChanges();
            return(OutMessage.FromCode(localizer["UserScopeUpdated"]));
        }
コード例 #4
0
 public LeaderboardKey(string id, UserScope userScope, TimeScope timeScope, ushort startingRank, ushort numberOfRanks)
 {
     this.id            = id;
     this.userScope     = userScope;
     this.timeScope     = timeScope;
     this.startingRank  = startingRank;
     this.numberOfRanks = numberOfRanks;
 }
コード例 #5
0
        private string CreateScopeToken(string currentScope)
        {
            var token = new UserScope {
                ScopeName = currentScope
            };

            return(token.CompressToken(true, options.Value.EncryptCookie));
        }
コード例 #6
0
        public User(string nome, string email)
        {
            Nome   = nome;
            Email  = email;
            _tasks = new List <Task>();

            UserScope.ValidUserName(Nome);
            UserScope.ValidEmail(Email);
        }
コード例 #7
0
 public Task <IEnumerable <BasicUser> > GetUsers(
     [FromRoute] Guid hubId,
     [FromRoute] Guid campusId,
     [FromQuery(Name = "scope")] UserScope scope = UserScope.Basic
     )
 {
     User.ConfirmGroupMembership(campusId, _authConfig.HubLeadsAccessGroup);
     return(_service.GetUsers(campusId, User, scope));
 }
コード例 #8
0
        public async Task <int> Handle(InsertOrUpdateUserScopeCommand request, CancellationToken cancellationToken)
        {
            UserScope userScope = request.ToUserScope();

            _context.UserScopes.AddOrUpdate(us => new { us.ScopeName }, userScope);
            await _context.SaveChangesAsync();

            return(userScope.Id);
        }
コード例 #9
0
 ///<inheritdoc/>
 public async Task AddUserScopeAsync(Guid userId, Guid scopeId, CancellationToken cancellationToken = default)
 {
     DbSet <UserScope> dbSet     = _ctx.Set <UserScope>();
     UserScope         userScope = new UserScope()
     {
         UserId  = userId,
         ScopeId = scopeId
     };
     await dbSet.AddAsync(userScope, cancellationToken);
 }
コード例 #10
0
        public void AgeGreaterThan()
        {
            var result = _userList.AsQueryable().Where(UserScope.AgeGreaterThan(20));

            Assert.AreEqual(2, result.Count());
            Assert.AreEqual(false, result.Any(x => x.Name == "User 1"));
            Assert.AreEqual(true, result.Any(x => x.Name == "User 2"));
            Assert.AreEqual(false, result.Any(x => x.Name == "User 3"));
            Assert.AreEqual(true, result.Any(x => x.Name == "User 4"));
        }
コード例 #11
0
        public async Task <BasicUser> GetBasicUserById(Guid userId, UserScope scope)
        {
            var user = await GetGraphUserById(userId);

            if (scope == UserScope.Basic)
            {
                return(BasicUser.FromGraphUser(user));
            }

            return(await AddFullScope(user));
        }
コード例 #12
0
 ///<inheritdoc/>
 public Task RemoveUserScopeAsync(Guid userId, Guid scopeId, CancellationToken cancellationToken)
 {
     return(Task.Run(() =>
     {
         DbSet <UserScope> dbSet = _ctx.Set <UserScope>();
         UserScope userScope = dbSet.Where(x => x.UserId == userId && x.ScopeId == scopeId).FirstOrDefault();
         if (userScope != null)
         {
             dbSet.Remove(userScope);
         }
     }));
 }
コード例 #13
0
		public static void GetAccessToken(User user, UserScope[] scopes, bool getNewAccessToken = false)
		{
			if (getNewAccessToken || string.IsNullOrEmpty(user.AccessToken))
			{
				var authWindow = new AuthWindow(user, scopes);
				bool? result = authWindow.ShowDialog();

				if (result.Value && !string.IsNullOrEmpty(authWindow.AccessToken))
				{
					user.AccessToken = authWindow.AccessToken;
				}

				DataFileManager.SetUser(user);
			}
		}
コード例 #14
0
ファイル: User.cs プロジェクト: Exeteres/Replica
        public void AssignPermissions(Chat chat, UserScope scope)
        {
            var db       = new RepoContext();
            var position = Chats.FirstOrDefault(x => x.ChatId == chat.Id);

            if (position == null)
            {
                position      = new ChatMember();
                position.User = this;
                position.Chat = chat;
            }
            position.Scope = scope;
            db.ChatMembers.Update(position);
            db.SaveChanges();
        }
コード例 #15
0
        public virtual void RetrieveFromSettings()
        {
            // Grab the the app version
            string tempString;
            int    currentVersion = PlayerPrefs.GetInt(VersionKey, -1);

            // Update the app status
            status = AppStatus.Replaying;
            if (currentVersion < 0)
            {
                status = AppStatus.FirstTimeOpened;
            }
            else if (currentVersion < AppVersion)
            {
                status = AppStatus.RecentlyUpdated;
            }

            // Set the version
            PlayerPrefs.SetInt(VersionKey, AppVersion);

            // Grab the number of levels unlocked
            numLevelsUnlocked = PlayerPrefs.GetInt(NumLevelsUnlockedKey, DefaultNumLevelsUnlocked);

            // Grab the music settings
            musicVolume = PlayerPrefs.GetFloat(MusicVolumeKey, DefaultMusicVolume);
            musicMuted  = GetBool(MusicMutedKey, false);

            // Grab the sound settings
            soundVolume = PlayerPrefs.GetFloat(SoundVolumeKey, DefaultSoundVolume);
            soundMuted  = GetBool(SoundMutedKey, false);

            // Grab the language
            language = PlayerPrefs.GetString(LanguageKey, DefaultLanguage);

            // Grab leaderboard user scope
            leaderboardUserScope = (UserScope)PlayerPrefs.GetInt(LeaderboardUserScopeKey, (int)DefaultLeaderboardUserScope);

            // Grab the best score
            tempString = PlayerPrefs.GetString(LocalHighScoresKey, null);
            bestScores.Clear();
            if (string.IsNullOrEmpty(tempString) == false)
            {
                RetrieveHighScores(tempString);
            }

            // NOTE: Feel free to add more stuff here
        }
コード例 #16
0
        public async Task <IEnumerable <BasicUser> > GetAllUsers(UserScope scope)
        {
            // TODO: check in the future if office location is supported as a graph filter attribute. Try something like $filter=officeLocation+eq+'Munich'. Currently this is not supported.

            var users = await _graphService.Client.Users.Request().GetAsync();

            // only return users where location is not empty
            var filteredUsers = users.Where(u => !string.IsNullOrWhiteSpace(u.OfficeLocation));

            // if the user scope is "full" we have to get group memberships for each user as well
            if (scope == UserScope.Full)
            {
                return(await AddFullScope(filteredUsers));
            }

            return(GraphHelper.MapBasicUsers(filteredUsers));
        }
コード例 #17
0
        public ILeaderboardWrapper GetLeaderboard(string leaderboardKey = null,
                                                  UserScope userScope   = UserScope.Global, TimeScope timeScope = TimeScope.AllTime,
                                                  ushort startingRank   = 0, ushort numberOfRanks = 0, bool retrieveScore = true)
        {
            ILeaderboardWrapper returnWrapper  = null;
            ServiceSpecificIds  leaderboardIds = DefaultLeaderboardIds;

            if (string.IsNullOrEmpty(leaderboardKey) == false)
            {
                leaderboardIds = GetLeaderboardIds(leaderboardKey);
            }

            // Check if the ID is provided
            if (leaderboardIds == null)
            {
                if (Debug.isDebugBuild == true)
                {
                    Debug.LogWarning("No Leaderboard with key " + leaderboardKey + " found");
                }
            }
            else if (string.IsNullOrEmpty(leaderboardIds.Id) == true)
            {
                if (Debug.isDebugBuild == true)
                {
                    Debug.LogWarning("No Leaderboard ID provided");
                }
            }
            else
            {
                // Find a LeaderboardWrapper from the dictionary
                LeaderboardKey key = new LeaderboardKey(leaderboardIds.Id, userScope, timeScope, startingRank, numberOfRanks);
                if (allLeaderboards.TryGetValue(key, out returnWrapper) == false)
                {
                    // Create a new wrapper, and add it to the dictionary
                    returnWrapper = new LeaderboardWrapper(key);
                    allLeaderboards.Add(key, returnWrapper);

                    // Check if we should retrive scores for this leaderboard
                    if ((retrieveScore == true) && (CurrentLogInState == LogInState.AuthenticationSuccess))
                    {
                        returnWrapper.LoadLeaderboardAsync();
                    }
                }
            }
            return(returnWrapper);
        }
コード例 #18
0
        internal LeaderboardWrapper(string id, UserScope userScope, TimeScope timeScope, ushort startingRank, ushort numberOfRanks)
        {
            // Setup Leaderboard
            reference           = Social.CreateLeaderboard();
            reference.id        = id;
            reference.userScope = userScope;
            reference.timeScope = timeScope;

            // Update the range
            Range newRange = reference.range;

            if (startingRank > 0)
            {
                newRange.from = startingRank;
            }
            if (numberOfRanks > 0)
            {
                newRange.count = numberOfRanks;
            }
            reference.range = newRange;
        }
コード例 #19
0
        public void SetScopes(string id, [FromBody] List <Region> regions)
        {
            var user          = UserManager.FindById(id);
            var currentScopes = dbContext.Set <UserScope>()
                                .Where(s => s.fkUserId == user.Id)
                                .ToList();

            foreach (var scope in currentScopes)
            {
                dbContext.Entry(scope).State = EntityState.Deleted;
            }
            foreach (var region in regions)
            {
                var scope = new UserScope
                {
                    fkUserId   = user.Id,
                    fkRegionId = region.Id
                };
                dbContext.Set <UserScope>().Add(scope);
            }
            dbContext.SaveChanges();
        }
コード例 #20
0
        public async Task <IActionResult> List(CancellationToken cancellationToken, string username = null)
        {
            var token = await GetAccessTokenAsync();

            if (token == null)
            {
                return(Forbid());
            }

            var list = await DeviantArtFs.Api.Gallery.AsyncGetFolders(
                token,
                CalculateSize.NewCalculateSize(true),
                FolderPreload.Default,
                username != null
                ?UserScope.NewForUser(username)
                : UserScope.ForCurrentUser,
                PagingLimit.MaximumPagingLimit,
                PagingOffset.StartingOffset).ToListAsync(cancellationToken);

            ViewBag.Username = username;
            return(View(list));
        }
コード例 #21
0
        /// <inheritdoc />
        public async Task <IEnumerable <BasicUser> > GetUsers(Guid campusId, ClaimsPrincipal user, UserScope scope)
        {
            var campus = await _campusDbService.GetById(campusId);

            AuthorizeHubLeadForCampus(campus, user);

            var users = await _graphGroupService.GetGroupMembers(campus.AadGroupId);

            if (scope == UserScope.Basic)
            {
                return(users.Select(BasicUser.FromGraphUser));
            }

            return(await _graphUserService.AddFullScope(users));
        }
コード例 #22
0
    /// <summary>
    /// 获取排行榜的排名
    /// </summary>
    /// <param name="id">排行榜ID</param>
    /// <param name="range">区间</param>
    /// <param name="onComplete">完成回调</param>
    /// <param name="scope">时间区间</param>
    /// <param name="userScope">用户区间</param>
    public void GetTopByByLeaderboardID(string id, Range range, System.Action <bool, IScore[]> onComplete, TimeScope scope = TimeScope.AllTime, UserScope userScope = UserScope.Global)
    {
        if (!Social.localUser.authenticated)
        {
            return;
        }
        ILeaderboard lb = Social.CreateLeaderboard();

        Debug.Log(lb);
        if (lb == null)
        {
            return;
        }
        lb.id        = id;
        lb.range     = range;
        lb.timeScope = scope;
        lb.userScope = userScope;
        lb.LoadScores(ok =>
        {
            onComplete(ok, lb.scores);
        });
    }
コード例 #23
0
        void RetrieveVersion0Settings()
        {
            // Grab the number of levels unlocked
            numLevelsUnlocked = Settings.GetInt(NumLevelsUnlockedKey, DefaultNumLevelsUnlocked);

            // Grab the music settings
            musicVolume = Settings.GetFloat(MusicVolumeKey, DefaultMusicVolume);
            musicMuted  = Settings.GetBool(MusicMutedKey, false);

            // Grab the sound settings
            soundVolume = Settings.GetFloat(SoundVolumeKey, DefaultSoundVolume);
            soundMuted  = Settings.GetBool(SoundMutedKey, false);

            // Grab the language
            language = Settings.GetString(LanguageKey, DefaultLanguage);

            // Grab leaderboard user scope
            leaderboardUserScope = Settings.GetEnum(LeaderboardUserScopeKey, DefaultLeaderboardUserScope);

            // Grab number of plays
            numberOfTimesAppOpened = Settings.GetInt(NumberOfTimesAppOpenedKey, 0);

            // Grab the best score
            string tempString = Settings.GetString(LocalHighScoresKey, null);

            bestScores.Clear();
            if (string.IsNullOrEmpty(tempString) == false)
            {
                RetrieveHighScores(tempString);
            }

            // Grab Keyboard Sensitivity information
            splitKeyboardAxis = Settings.GetBool(SplitKeyboardAxisKey, false);

            // Grab how long we've played this game
            lastTimeOpen = DateTime.UtcNow;
            lastPlayTime = Settings.GetTimeSpan(TotalPlayTimeKey, TimeSpan.Zero);

            // Get Keyboard Sensitivity information
            splitKeyboardAxis        = Settings.GetBool(SplitKeyboardAxisKey, false);
            keyboardXAxisSensitivity = Settings.GetFloat(KeyboardXAxisSensitivityKey, DefaultSensitivity);
            keyboardYAxisSensitivity = Settings.GetFloat(KeyboardYAxisSensitivityKey, DefaultSensitivity);
            isKeyboardXAxisInverted  = Settings.GetBool(IsKeyboardXAxisInvertedKey, false);
            isKeyboardYAxisInverted  = Settings.GetBool(IsKeyboardYAxisInvertedKey, false);

            // Get Mouse Sensitivity information
            splitMouseAxis        = Settings.GetBool(SplitMouseAxisKey, false);
            mouseXAxisSensitivity = Settings.GetFloat(MouseXAxisSensitivityKey, DefaultSensitivity);
            mouseYAxisSensitivity = Settings.GetFloat(MouseYAxisSensitivityKey, DefaultSensitivity);
            isMouseXAxisInverted  = Settings.GetBool(IsMouseXAxisInvertedKey, false);
            isMouseYAxisInverted  = Settings.GetBool(IsMouseYAxisInvertedKey, false);

            // Get Mouse Wheel Sensitivity information
            scrollWheelSensitivity = Settings.GetFloat(ScrollWheelSensitivityKey, DefaultSensitivity);
            isScrollWheelInverted  = Settings.GetBool(IsScrollWheelInvertedKey, false);

            // Get Special Effects information
            isSmoothCameraEnabled  = Settings.GetBool(IsSmoothCameraEnabledKey, false);
            isBobbingCameraEnabled = Settings.GetBool(IsBobbingCameraEnabledKey, false);
            isFlashesEnabled       = Settings.GetBool(IsFlashesEnabledKey, true);
            isMotionBlursEnabled   = Settings.GetBool(IsMotionBlursEnabledKey, true);
            isBloomEnabled         = Settings.GetBool(IsBloomEnabledKey, true);
        }
コード例 #24
0
ファイル: AllowAttribute.cs プロジェクト: Exeteres/Replica
 public AllowAttribute(UserScope scope)
 {
     Scope = scope;
 }
 public Task <BasicUser> GetCurrentUser(
     [FromQuery(Name = "scope")] UserScope scope = UserScope.Basic
     )
 {
     return(_graphService.GetBasicUserById(AuthenticationHelper.GetUserIdFromToken(User), scope));
 }
コード例 #26
0
 public ProtectAttribute(UserScope scope) => Scope = scope;
コード例 #27
0
		public AuthWindow(User user, UserScope[] scopes)
			: this()
		{
			this.user = user;
			Scopes = scopes;
		}
コード例 #28
0
 /// <summary>
 /// 获取排行榜的排名
 /// </summary>
 /// <param name="id">排行榜ID</param>
 /// <param name="range">区间</param>
 /// <param name="onComplete">完成回调</param>
 /// <param name="scope">时间区间</param>
 /// <param name="userScope">用户区间</param>
 public void GetTopByByLeaderboardID(string id, Range range, System.Action<bool, IScore[]> onComplete, TimeScope scope = TimeScope.AllTime, UserScope userScope = UserScope.Global)
 {
     if (!Social.localUser.authenticated)
         return;
     ILeaderboard lb = Social.CreateLeaderboard();
     Debug.Log(lb);
     if (lb == null)
         return;
     lb.id = id;
     lb.range = range;
     lb.timeScope = scope;
     lb.userScope = userScope;
     lb.LoadScores(ok =>
    {
        onComplete(ok, lb.scores);
    });
 }
コード例 #29
0
        /// <summary>
        /// Loads the set of scores from the specified leaderboard within the specified timeScope and userScope.
        /// The range is defined by starting position fromRank and the number of scores to retrieve scoreCount.
        /// Note that each load score request is added into a queue and the
        /// next request is called after the callback of previous request has been invoked.
        /// </summary>
        /// <param name="leaderboardName">Leaderboard name.</param>
        /// <param name="fromRank">The rank of the first score to load.</param>
        /// <param name="scoreCount">The total number of scores to load.</param>
        /// <param name="timeScope">Time scope.</param>
        /// <param name="userScope">User scope.</param>
        /// <param name="callback">Callback receives the leaderboard name and an array of loaded scores.</param>
        public static void LoadScores(string leaderboardName, int fromRank, int scoreCount, TimeScope timeScope, UserScope userScope, Action <string, IScore[]> callback)
        {
            // IMPORTANT: On Android, the fromRank argument is ignored and the score range always starts at 1.
            // (This is not the intended behavior according to the SocialPlatform.Range documentation, and may simply be
            // a bug of the current (0.9.34) GooglePlayPlatform implementation).
            if (!IsInitialized())
            {
                if (Debug.isDebugBuild)
                {
                    Debug.Log("LoadScores FAILED: user is not logged in.");
                }

                return;
            }

            Leaderboard ldb = GetLeaderboardByName(leaderboardName);

            if (ldb == null)
            {
                if (Debug.isDebugBuild)
                {
                    Debug.Log("LoadScores FAILED: unknown leaderboard name.");
                }

                return;
            }

            // Create new request
            LoadScoreRequest request = new LoadScoreRequest();

            request.leaderboardName       = ldb.Name;
            request.leaderboardId         = ldb.Id;
            request.callback              = callback;
            request.useLeaderboardDefault = false;
            request.loadLocalUserScore    = false;
            request.fromRank              = fromRank;
            request.scoreCount            = scoreCount;
            request.timeScope             = timeScope;
            request.userScope             = userScope;

            // Add request to the queue
            loadScoreRequests.Add(request);

            DoNextLoadScoreRequest();
        }
 public Task <IEnumerable <BasicUser> > Get(
     [FromQuery(Name = "scope")] UserScope scope = UserScope.Basic)
 {
     return(_graphService.GetAllUsers(scope));
 }