Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using RestSharp;
- using RestSharp.Authenticators;
- using Newtonsoft.Json.Linq;
- namespace BD
- {
- /// <summary>
- /// Логика взаимодействия для StartPage.xaml
- /// </summary>
- public partial class StartPage : Page
- {
- public StartPage()
- {
- InitializeComponent();
- }
- // private void StartPage_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- // {
- // Environment.Exit(0);
- // }
- private void Signin_Click(object sender, RoutedEventArgs e)
- {
- var client = new RestClient("http://95.85.24.237:8081");
- var request = new RestRequest("/user/auth", Method.POST);
- request.RequestFormat = RestSharp.DataFormat.Json;
- request.AddBody(new LogUser
- {
- username = firstNameTxtBox.Text,
- password = lastNameTxtBox.Password,
- });
- IRestResponse response = client.Execute(request);
- var content = response.Content;
- if (content.Contains("Error"))
- {
- MessageBox.Show("Неверный логин или пароль. Пожалуйста, проверьте их и повторите попытку");
- return;
- }
- var obj = JObject.Parse(content);
- var tokenU = (string)obj["sectoken"];
- var idUs = (string)obj["user"]["id"];
- Token.id = long.Parse(idUs);
- Token.token = tokenU;
- Token.name = firstNameTxtBox.Text;
- MainWindow mw;
- // hide main form
- if (MainWindow.flag)
- {
- mw = ((MainWindow)Application.Current.MainWindow);
- mw.Hide();
- }
- else
- {
- mw = new MainWindow();
- mw = MainWindow.mainWindow;
- mw.Hide();
- }
- // show other form
- ProfileUser profileUser = new ProfileUser();
- profileUser.Show();
- ProfileUser.prf = profileUser;
- // MessageBox.Show(Token.id);
- // mw.Close();
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- NavigationService ns = NavigationService.GetNavigationService(this);
- ns.Navigate(new Uri("RegistrationPage.xaml", UriKind.Relative));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement