/// <summary> /// Авторизация /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void AuthorizedClick(object sender, RoutedEventArgs e) { var loginModel = new UserModel(); loginModel.Email = Email.Text; loginModel.Password = Password.Text; loginModel.Key = Key.Text; var pubKey = await GetPubKey(); loginModel.Email = _rsaService.Encrypt(loginModel.Email, pubKey); loginModel.Password = _rsaService.Encrypt(loginModel.Password, pubKey); loginModel.Key = _rsaService.Encrypt(loginModel.Key, pubKey); var responseBool = await _httpClient.PostAsJsonAsync("user/login", loginModel); if (!responseBool.IsSuccessStatusCode) { var textError = await responseBool.Content.ReadAsStringAsync(); MessageBox.Show($"Вы ввели неверные данные:\n{textError}"); return; } var cookie = responseBool.Headers.GetValues(StorageSession.GetCookieName); StorageSession.Create(); StorageSession.SetCookie(cookie); StorageSession.SetKey(Key.Text); var window = new MessageWindows(); Close(); window.ShowDialog(); }
public static StorageSession SetCookie(IEnumerable <string> cookie) { if (Context == null) { var res = new StorageSession(); res.Cookie = cookie; Context = res; } else { Context.Cookie = cookie; } return(Context); }
public static StorageSession SetKey(string key) { if (Context == null) { var res = new StorageSession(); res.Key = key; Context = res; } else { Context.Key = key; } return(Context); }
public static StorageSession Create() { Context = Context ?? new StorageSession(); return(Context); }