Пример #1
0
        public async Task <bool> LoginAsync(LoginPayload payload)
        {
            using var http = _httpFactory.CreateClient(Constants.AUTH_CLIENT_NAME);
            try
            {
                var res = await http.PostAsJsonAsync($"{http.BaseAddress}/login", payload);

                if (res.IsSuccessStatusCode)
                {
                    var auth = await res.Content.ReadFromJsonAsync <AuthResponse>();

                    _localstorage.SetItem(Constants.ACCESS_TOKEN_NAME, auth.Token);
                    _localstorage.SetItem(Constants.USER_DATA_NAME, auth.User);
                }
                else
                {
                    var content = await res.Content.ReadFromJsonAsync <ErrorResponse>();

                    Console.Error.WriteLine($"Failed to Login: {content?.Message}");
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                return(false);
            }
            return(true);
        }
        public void SetCredentials(string username, string token)
        {
            Username = username;
            Token    = token;

            _localStorage.SetItem(INDEX_USERNAME, Username);
            _localStorage.SetItem(INDEX_TOKEN, Token);
        }
Пример #3
0
        public void CreateNewNote(string Title, string Note)
        {
            var note = new Note {
                Id    = GetRandomString(5),
                Title = Title ?? "",
                Notes = Note ?? ""
            };

            Notes.Add(note);
            LocalStorage.SetItem("notes", Notes);
        }
Пример #4
0
        public void ResetCurrencyCount()
        {
            foreach (var currencyModel in storedCurrencies)
            {
                currencyModel.Value.Count = 0;
            }

            localStorage.SetItem(storageKey, storedCurrencies);
            CurrencyTotal = this.GetCurrencyTotal();
            this.NotifyStateChanged();
        }
Пример #5
0
 private void SaveSettings()
 {
     if (_settings != null)
     {
         if (_userProvider.Username != null)
         {
             _localStorage.SetItem("SettingsData." + _userProvider.Username, _settings);
         }
         else
         {
             _localStorage.SetItem("SettingsData", _settings);
         }
     }
 }
Пример #6
0
        public void SetCredentials(string token)
        {
            _localStorage.SetItem(TokenKey, token);

            _httpClient.DefaultRequestHeaders.Remove("Authorization");
            _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token}");
        }
Пример #7
0
 private void SaveRouteData()
 {
     if (_routeData != null)
     {
         _localStorage.SetItem("RouteData." + _userProvider.Username, _routeData);
     }
 }
        public void SetCurrentCulture(string cultureCode)
        {
            var culture = new CultureInfo(cultureCode);

            SetCurrentCultureForApplication(culture);
            _syncLocalStorageService.SetItem(LocalStorageKeys.CURRENT_CULTURE, cultureCode);
        }
Пример #9
0
 private void SaveShipData()
 {
     if (_shipData != null)
     {
         _localStorage.SetItem("ShipData." + _userProvider.Username, _shipData);
     }
 }
 public void SaveContent(string content)
 {
     lock (thisLock)
     {
         string path = GetFileName();
         localStorage.SetItem(path, Encrypt(content));
     }
 }
Пример #11
0
        public async Task <bool> SetDetailsAsync(string token)
        {
            var initialCheck = !StartingDetailsChecked;

            try
            {
                var request = new HttpRequestMessage
                {
                    RequestUri = new Uri(_config["base_url"] + "/my/account"),
                    Method     = HttpMethod.Get
                };
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);

                var httpResponse = await _http.SendAsync(request);

                var userResponse = await httpResponse.Content.ReadFromJsonAsync <DetailsResponse>(_serializerOptions);

                if (userResponse != null)
                {
                    Username    = userResponse.User.Username;
                    UserDetails = userResponse.User;
                    Token       = token;

                    _http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                    _localStorage.SetItem("Token", Token);

                    StartingDetailsChecked = true;
                    UserUpdated?.Invoke(this, new UserEventArgs
                    {
                        UserDetails    = userResponse.User,
                        IsFullRefresh  = true,
                        IsInitialCheck = initialCheck
                    });

                    return(true);
                }
            }
            catch (Exception) { }

            if (initialCheck)
            {
                UserUpdated?.Invoke(this, new UserEventArgs
                {
                    UserDetails    = null,
                    IsFullRefresh  = true,
                    IsInitialCheck = initialCheck
                });
            }

            StartingDetailsChecked = true;
            return(false);
        }
Пример #12
0
        public override void AfterDispatch(object action)
        {
            if (action is LoadTodosSuccessAction)
            {
                var state = Store !.Features["Todos"].GetState();

                if (state is TodosState todosState)
                {
                    _localStorage.SetItem <IEnumerable <TodoDTO> >("todos",
                                                                   todosState.CurrentTodos ?? new List <TodoDTO>());
                }
            }
        }
Пример #13
0
        public void Save()
        {
            _localStorage.SetItem("UserProfile", _profile);

            _profile.IsDirty = false;
        }
Пример #14
0
 public static void AddDemoDataKey(this ISyncLocalStorageService localStorage)
 => localStorage.SetItem(key_hasDemoData, true);
Пример #15
0
 public void Save <T>(string key, T data)
 {
     _syncLocalStorageService.SetItem(key, data);
 }
Пример #16
0
 public static void AddHasFirstTimeLaunchKey(this ISyncLocalStorageService localStorage)
 => localStorage.SetItem(key_firstTimeLaunch, false);
Пример #17
0
 public void SetGuestUserName(string name)
 {
     _syncLocalStorageService.SetItem(_localStorageKey, name);
     OnAuthenticationStateChanged();
 }
Пример #18
0
 internal void SetVisible(string id, bool isVisible)
 {
     if (isVisible)
     {
         localStorage.RemoveItem(VisibleKey(id));
     }
     else
     {
         localStorage.SetItem(VisibleKey(id), isVisible);
     }
 }
Пример #19
0
        public void SetLocal(string key, object entryObj)
        {
            string jsonSerialize = JsonSerializer.Serialize(entryObj);

            _syncLocalStorageService.SetItem(key, _encryptionService.Encrypt(jsonSerialize));
        }
 public void Write(string text)
 {
     localStorage.SetItem("TEXT", text);
 }
Пример #21
0
        private void SetCurrentCareerInLocalStorage(Career career)
        {
            CareerDto careerDto = _mapper.Map <CareerDto>(career);

            _localStorageService.SetItem(LocalStorageKeys.CURRENT_CAREER, careerDto);
        }
Пример #22
0
        private void WriteCartItemsToLocalStorage()
        {
            listeners.ForEach(action => action());

            localStorage.SetItem(LocalStorageConstants.CartItems, cartItems);
        }
 public static void SetAuthorizationTokens(this ISyncLocalStorageService localStorage, string tokenType, string accessToken, string refreshToken)
 {
     localStorage.SetItem(LocalStorageConstants.TokenType, tokenType);
     localStorage.SetItem(LocalStorageConstants.AccessToken, accessToken);
     localStorage.SetItem(LocalStorageConstants.RefreshToken, refreshToken);
 }