/// <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(); }
private async void RegistrationPost(object sender, RoutedEventArgs e) { var serverPublicKey = await GetPubKey(); var model = new UserModel(); model.Email = _rsaService.Encrypt(Email.Text, serverPublicKey); model.Password = _rsaService.Encrypt(Password.Text, serverPublicKey); var responseGuid = await _httpClient.PostAsJsonAsync("user/Register", model); responseGuid.EnsureSuccessStatusCode(); MessageBox.Show($"Регистрация прошла успешно."); this.Close(); }