コード例 #1
0
        private void UpdateUser(UserConfiguration userConfig)
        {
            LoadDevices();

            // Update other pages
            if (accountpage != null)
            {
                accountpage.LoadUserConfiguration(userConfig);
            }

            SendCurrentUser();

            // Login Server user (set login file)
            Login(userConfig);

            // Restart Message monitor
            StartMessageMonitor();
            messageCenter.ClearMessages();

            // Load the Profile Image (Nav Menu)
            LoadProfileImage(userConfig);

            // Raise CurrentUserChanged Event
            CurrentUserChanged?.Invoke(userConfig);
        }
コード例 #2
0
        public async Task AuthenticateUser(string providerToken, string providerAuthCode)
        {
            try
            {
                if (string.IsNullOrEmpty(providerToken))
                {
                    throw new ArgumentNullException(nameof(providerToken));
                }
                if (string.IsNullOrEmpty(providerAuthCode))
                {
                    throw new ArgumentNullException(nameof(providerAuthCode));
                }

                ResetUser();

                var auth = JObject.Parse($"{{'id_token':'{providerToken}','authorization_code':'{providerAuthCode}'}}").ToString();

                NetworkIndicator.ToggleVisibility(true);

                var authResponse = await HttpClient.PostAsync(Routes.LoginGoogle, new StringContent (auth, Encoding.UTF8, Routes.Json));

                if (authResponse.IsSuccessStatusCode)
                {
                    var azureUser = JsonConvert.DeserializeObject <AzureAppServiceUser> (await authResponse.Content.ReadAsStringAsync());

                    Keychain.SaveItemToKeychain(AzureAppServiceUser.AuthenticationHeader, "azure", azureUser.AuthenticationToken);

                    _httpClient = null;

                    var userConfigJson = await HttpClient.GetStringAsync(Routes.AuthenticateUser);

                    authUser = JsonConvert.DeserializeObject <AuthUserConfig> (userConfigJson);

                    authUser.SaveToKeychain(Keychain);

                    Log.Debug(authUser.ToString());

                    _user = null;

                    CurrentUserChanged?.Invoke(this, User);
                }
                else
                {
                    Log.Error(auth);
                    Log.Error(authResponse?.ToString());
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
            finally
            {
                NetworkIndicator.ToggleVisibility(false);
            }
        }
コード例 #3
0
        public void ResetUser()
        {
            _user = null;

            Keychain.RemoveItemFromKeychain(AzureAppServiceUser.AuthenticationHeader);

            AuthUserConfig.RemoveFromKeychain(Keychain);

            Settings.SetContentToken <AvContent> (string.Empty);

            _httpClient = null;

            ContentClient.Shared.ResetClient();

            CurrentUserChanged?.Invoke(this, null);
        }
コード例 #4
0
        public void ResetCurrentUser()
        {
            ResetCurrentUserLogin();

            var oldUser = CurrentUser;

            CurrentUser = new User(
                null,
                null,
                -1,
                null,
                UserStoreType.Unknown);

            CurrentUserChanged?.Invoke(this,
                                       new UserChangedEventArgs(oldUser, CurrentUser));
        }
コード例 #5
0
        public bool SetCurrentUserTemporary(string login,
                                            string token, int id)
        {
            ResetCurrentUserLogin();

            var oldUser = CurrentUser;

            CurrentUser = new User(
                login,
                token,
                id,
                null,
                UserStoreType.Temporary);

            CurrentUserChanged?.Invoke(this,
                                       new UserChangedEventArgs(oldUser, CurrentUser));

            return(true);
        }
コード例 #6
0
        public bool SetCurrentUser(string login)
        {
            if (!IsExistUser(login))
            {
                return(false);
            }

            if (!GetUser(login, out var currentUser))
            {
                return(false);
            }

            SetCurrentUserLogin(login);

            var oldUser = CurrentUser;

            CurrentUser = currentUser;

            CurrentUserChanged?.Invoke(this,
                                       new UserChangedEventArgs(oldUser, CurrentUser));

            return(true);
        }
コード例 #7
0
ファイル: Storage.cs プロジェクト: DashaTyshch/CSharp04
 public void SetCurrentUser(User user)
 {
     CurrentUserChanged?.Invoke(user);
 }
コード例 #8
0
 void SendCurrentUserChanged(UserConfiguration userConfig)
 {
     CurrentUserChanged?.Invoke(userConfig);
 }