public static async Task <UserInfo> GetUserInfoAsync(UserInfoKey userInfoKey)
        {
            Dictionary <string, string> datas = new Dictionary <string, string>();

            datas.Add("userId", userInfoKey.UserId);
            return(await HttpConnector.Instance.GetAsync <UserInfo> ("Api/Account/GetUserInfo", datas));
        }
        private async Task <bool> RetreiveOnlineUserInfoAsync()
        {
            bool result = false;

            try
            {
                var userInfoKey = new UserInfoKey(); // no need userId here
                var userInfo    = await UserInfoWebService.GetUserInfoAsync(userInfoKey);

                if (userInfo != null)
                {
                    var dbContext       = Resolver.Resolve <ISQLite>().GetConnection();
                    var userInfoService = new UserInfoService(dbContext);
                    var userInfoList    = userInfoService.FindUserInfos();
                    if (userInfoList != null && userInfoList.Count > 0)
                    { // delete old userInfo
                        var userInfoKeyList = new List <UserInfoKey>();
                        foreach (var key in userInfoList)
                        {
                            userInfoKeyList.Add(key);
                        }
                        userInfoService.DeleteUserInfoList(userInfoKeyList);
                    }
                    userInfoService.UpdateUserInfo(userInfo);
                    UserData.Instance.UserInfo = userInfo;
                    _userId = userInfo.UserId;
                    result  = true;
                }
            }
            catch (Exception except)
            {
            }
            return(result);
        }
Beispiel #3
0
        /// <summary>
        /// Update the user's information
        /// </summary>
        /// <param name="key">User info key</param>
        /// <param name="str">User information that needs to be updated</param>
        /// <param name="accountID">account id of the user</param>
        public void UpdateUserInfo(UserInfoKey key, String str, int accountID)
        {
            MySqlConnection conn = new MySqlConnection(connStr);
            MySqlCommand    comm = new MySqlCommand();

            comm.Connection = conn;
            String keyString = key.ToString();

            comm.CommandText = key != UserInfoKey.PASSWORD ?
                               "UPDATE ACCOUNT SET " + keyString + " = @" + keyString + " WHERE ACCOUNT_ID = @ACCOUNTID":
                               "UPDATE ACCOUNT SET " + keyString + " = SHA2(CONCAT(@" + keyString + ", SALT), 256) WHERE ACCOUNT_ID = @ACCOUNTID";
            comm.Parameters.AddWithValue("@" + keyString, str);
            comm.Parameters.AddWithValue("@ACCOUNTID", accountID);

            try
            {
                conn.Open();
                comm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            conn.Close();
        }
        public UserInfo GetUserInfo(UserInfoKey key)
        {
            UserInfo userInfo = null;
            string   cacheKey = key == null ? "UserInfoKey_null" : key.GetCacheKey();

            if (key != null && !TryGetCacheData(cacheKey, out userInfo))
            {
                userInfo = GetUserInfoManager().GetUserInfo(key);
                SetCacheData(_cacheName, cacheKey, userInfo);
            }
            return(userInfo);
        }
Beispiel #5
0
        /// <summary>
        /// Delete data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        public void Delete(UserInfoKey key)
        {
            if (key == null || string.IsNullOrWhiteSpace(key.UserId))
            {
                return;
            }

            var row = _dbContext.Table <UserInfoRow>().Where(m => m.UserId == key.UserId).FirstOrDefault();

            if (row != null)
            {
                _dbContext.Delete(row);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Get data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        /// <returns>read data</returns>
        public UserInfo Get(UserInfoKey key)
        {
            if (key == null || string.IsNullOrWhiteSpace(key.UserId))
            {
                return(null);
            }

            var row = _dbContext.UserInfo.Where(m => m.UserId == key.UserId).FirstOrDefault();

            if (row != null)
            {
                return(UserInfoTransformer.ToBean(row));
            }
            return(null);
        }
Beispiel #7
0
        /// <summary>
        /// Delete data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        public void Delete(UserInfoKey key)
        {
            if (key == null || string.IsNullOrWhiteSpace(key.UserId))
            {
                return;
            }

            var row = _dbContext.UserInfo.Where(m => m.UserId == key.UserId).FirstOrDefault();

            if (row != null)
            {
                _dbContext.UserInfo.Remove(row);
                _dbContext.SaveChanges();
            }
        }
 public void DeleteUserInfo(UserInfoKey key)
 {
     BeginTransaction();
     try
     {
         GetUserInfoManager().DeleteUserInfo(key);
         CommitTransaction();
         //invalidate cache
         InvalidateCache(_cacheName);
     }
     catch
     {
         RollbackTransaction();
         throw;
     }
     finally
     {
         EndTransaction();
     }
 }
        private async Task <TUnitType> GetExerciseUnit()
        {
            TUnitType unit = TUnitType.Metric;

            try
            {
                if (_trainingExercise != null && _trainingExercise.TrainingExerciseSets != null &&
                    _trainingExercise.TrainingExerciseSets.Count > 0)
                {
                    unit = _trainingExercise.TrainingExerciseSets[0].Unit;
                }
                else
                {
                    if (_userInfo == null)
                    {
                        var userInfoKey = new UserInfoKey()
                        {
                            UserId = _trainingExercise.UserId
                        };
                        if (_trainingExercise.UserId == UserData.Instance.UserInfo.UserId)
                        {
                            var userInfoService = new UserInfoService(_dbContext);
                            _userInfo = userInfoService.GetUserInfo(userInfoKey);
                        }
                        else
                        {
                            _userInfo = await UserInfoWebService.GetUserInfoAsync(userInfoKey);
                        }
                    }
                    if (_userInfo != null)
                    {
                        unit = _userInfo.Unit;
                    }
                }
            }
            catch
            {
            }
            return(unit);
        }
Beispiel #10
0
        private async Task <bool> PreLoadDataAsync()
        {
            bool result = false;

            try
            {
                var countryService = new CountryService(_dbContext);
                _countries = countryService.FindCountries();
                if (_countries == null || _countries.Count == 0)
                {
                    //find country in server if not present in database (this viewModel can be display directly after user login)
                    _countries = await CountryWebService.FindCountriesAsync();

                    //populate country in local database
                    if (_countries != null && _countries.Count > 0)
                    {
                        countryService.UpdateCountryList(_countries);
                    }
                }

                var userInfoKey = new UserInfoKey()
                {
                    UserId = _userId
                };
                _userInfo = await UserInfoWebService.GetUserInfoAsync(userInfoKey);

                if (_userInfo != null && _countries != null && _countries.Count > 0)
                {
                    result = true;
                }
            }
            catch
            {
            }
            return(result);
        }
Beispiel #11
0
 internal void DeleteUserInfo(UserInfoKey key)
 {
     _userInfoModule.Delete(key);
 }
Beispiel #12
0
 internal UserInfo GetUserInfo(UserInfoKey key)
 {
     return(_userInfoModule.Get(key));
 }
Beispiel #13
0
        public async Task <IActionResult> ConfirmUserEmail(string id)
        {
            if (!string.IsNullOrWhiteSpace(id))
            {
                var appUser = await _identityUserManager.FindByIdAsync(id);

                if (appUser != null && !appUser.EmailConfirmed)
                {
                    appUser.EmailConfirmed = true;
                    await _identityUserManager.UpdateAsync(appUser);

                    //Add user role
                    var userKey = new UserKey()
                    {
                        Id = id
                    };
                    var user = _usersService.GetUser(userKey);
                    if (user != null)
                    {
                        //Verify role exist
                        var roleKey = new RoleKey();
                        roleKey.Id = "1"; //User
                        var role = _rolesService.GetRole(roleKey);
                        if (role != null)
                        {
                            user.Role = role;
                            user      = _usersService.UpdateUser(user);
                        }
                    }

                    //Add empty user profil (for correct connect error on mobile application)
                    var userInfoKey = new UserInfoKey()
                    {
                        UserId = id
                    };
                    var userInfo = _userInfosService.GetUserInfo(userInfoKey);
                    if (userInfo == null)
                    {
                        userInfo = new UserInfo()
                        {
                            UserId = id,
                            Unit   = TUnitType.Metric
                        };
                        _userInfosService.UpdateUserInfo(userInfo);
                    }

                    try
                    {
                        string reportData = await _reportService.CreateReportForAdminNewUserAccountCreatedAsync(user.Id);

                        await _emailSender.SendEmailAsync(appUser.Email, Translation.CONFIRM_USER_ACCOUNT, reportData);

                        await _emailSender.SendEmailAsync(appUser.Email, "Account validated",
                                                          "Your account validated by admin");
                    }
                    catch (Exception except)
                    {
                        _logger.LogError(0, except, "can't send email");
                    }
                }
            }
            return(RedirectToAction("Index"));
        }
Beispiel #14
0
 public bool Equals(UserInfoKey other)
 {
     return(AccessToken == other.AccessToken);
 }