Beispiel #1
0
        public async Task Authorize(int userId, string authorizationCode)
        {
            TokenResponse tokenResponse = await _youtubeAuthClient.GetAuthorizationToken(authorizationCode);

            if (tokenResponse != null)
            {
                var userIntegration = _unitOfWork.UserIntegrations.GetById(userId, (int)IntegrationType.IntegrationTypes.Youtube);

                if (userIntegration != null)
                {
                    _unitOfWork.UserIntegrations.Delete(userIntegration);
                    _unitOfWork.Commit();
                }

                _unitOfWork.UserIntegrations.Add(new UserIntegration
                {
                    UserID            = userId,
                    IntegrationTypeID = (int)IntegrationType.IntegrationTypes.Youtube,
                    RefreshToken      = tokenResponse.RefreshToken,
                    Token             = tokenResponse.AccessToken
                });
                _unitOfWork.Commit();

                await SetChannelId(userId);
            }
        }
Beispiel #2
0
        public async Task AuthorizeTwitch(int userId, string authorizationCode)
        {
            string token = await _twitchClient.GetAuthorizationToken(authorizationCode);

            if (token != null)
            {
                var userIntegration = _unitOfWork.UserIntegrations.GetById(userId, 1);

                if (userIntegration != null)
                {
                    _unitOfWork.UserIntegrations.Delete(userIntegration);
                }

                var channel = await _twitchClient.GetChannel(token);

                _unitOfWork.UserIntegrations.Add(new UserIntegration
                {
                    UserID            = userId,
                    IntegrationTypeID = (int)IntegrationType.IntegrationTypes.Twitch,
                    Token             = token,
                    UserName          = channel.name,
                    ChannelId         = channel._id.ToString()
                });
                _unitOfWork.Commit();
            }
        }
Beispiel #3
0
        public Task DeleteAsync <T>(string key)
        {
            int userId = Convert.ToInt32(key);

            return(Task.Run(() =>
            {
                var user = _unitOfWork.UserIntegrations.GetById(userId, (int)IntegrationType.IntegrationTypes.Youtube);

                if (user != null)
                {
                    user.RefreshToken = null;
                    _unitOfWork.UserIntegrations.Update(user);
                    _unitOfWork.Commit();
                }
            }));
        }
        private void SaveCredentials(int userId, TwitterApiCredentials userCreds)
        {
            string userName = _twitterClient.GetUserName(userCreds.AccessToken, userCreds.AccessTokenSecret);

            DeleteUserIntegrationIfExists(userId);

            _unitOfWork.UserIntegrations.Add(new UserIntegration
            {
                IntegrationTypeID = (int)IntegrationType.IntegrationTypes.Twitter,
                UserID            = userId,
                Token             = userCreds.AccessToken,
                TokenSecret       = userCreds.AccessTokenSecret,
                UserName          = userName
            });
            _unitOfWork.Commit();
        }
Beispiel #5
0
        public async Task Add(User user, string password)
        {
            var newUser = user;

            newUser.ProfileImagePath = _unitOfWork.AzureBlobStorage.GetDefaultUserImage();

            if (UserNameExists(user.UserName))
            {
                throw new UsernameAlreadyExistsException("UserName is being used by another user");
            }
            newUser.UserLogin = CreateUserLogin(password);

            newUser.DateJoined = DateTime.Now;

            // Sets a default image for new users. Change later if we decide to allow uploads at sign up.

            await _gameManager.AddGamesIfNotExistsAsync(CreateIgdbIdArray(user.Games));

            newUser.Games = _gameManager.GetByIgdbIds(CreateIgdbIdArray(user.Games));

            _unitOfWork.Users.Add(newUser);
            _unitOfWork.Commit();
        }
Beispiel #6
0
 public void Add(UserRating userRating)
 {
     _unitOfWork.UserRatings.Add(userRating);
     _unitOfWork.Commit();
 }