Esempio n. 1
0
 public async Task<int> NewFitBitUser(FitBitUser new_user)
 {
     var collection = _model.GetFitBitUserCollection();
     if (GetFitBitUserByName(new_user.user_name)== null)
     {
         await collection.InsertOneAsync(new_user);
     }
     return 1;
 }
Esempio n. 2
0
        public async Task<int> ModifyFitBitUser(FitBitUser user)
        {
            var collection = _model.GetFitBitUserCollection();

            var filter = new BsonDocument("user_name", user.user_name);
            var updateDocument = new BsonDocument { { "user_name", user.user_name }, { "access_token", user.access_token }, { "refresh_token", user.refresh_token }, { "expires_in", user.expires_in }, { "token_type", user.token_type } };
            var update = new BsonDocument("$set", updateDocument);
            var result = await collection.UpdateOneAsync(filter, update);

            //TODO: handle excpetion case
            return 1;
        }
Esempio n. 3
0
        private async Task<FitBitUser> getNewUser(OAuth2AccessToken token) {

            //get the user name by using the access token being currently recieved
            FitbitClient client = GetFitbitClient(token.Token, token.RefreshToken);
            FitbitResponse<UserProfile> response = await client.GetUserProfileAsync();

            // Create a new user with the access token recieved and user name 
            FitBitUser user = new FitBitUser();
            user.user_name = response.Data.FullName;
            user.access_token = token.Token;
            user.token_type = token.TokenType;
            user.expires_in = token.ExpiresIn;
            user.refresh_token = token.RefreshToken;

            return user;
        }
Esempio n. 4
0
 public async Task<ActionResult> GetUserProfile(string user_name="")
 {
     MongoDataModel dm = new MongoDataModel(ConfigurationManager.AppSettings["MongoDefaultDatabase"].ToString());
     FitBitDataService FitData = new FitBitDataService(dm);
     FitBitUser user = new FitBitUser();
     FitbitResponse<UserProfile> response = null;
     Boolean flag = true;
     while (flag)
     {
         if (user_name.Length < 1)
         {
             user_name = "Pranay Pradhananga" ;
         }
         user = FitData.GetFitBitUserByName(user_name);
         FitbitClient client = GetFitbitClient(user.access_token, user.refresh_token);
         response = await client.GetUserProfileAsync();
         if (response.Data != null)
             flag = false;
         else
             user = await RefreshToken(user.refresh_token, user_name);
     }
     return View(response.Data);
 }