Advertisement
Guest User

Untitled

a guest
Dec 25th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using RestSharp;
  16. using RestSharp.Authenticators;
  17. using Newtonsoft.Json.Linq;
  18.  
  19.  
  20. namespace BD
  21. {
  22.     /// <summary>
  23.     /// Логика взаимодействия для StartPage.xaml
  24.     /// </summary>
  25.     public partial class StartPage : Page
  26.     {
  27.  
  28.  
  29.  
  30.         public StartPage()
  31.         {
  32.             InitializeComponent();
  33.            
  34.         }
  35.        
  36.        
  37.        // private void StartPage_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  38.      //   {
  39.       //      Environment.Exit(0);
  40.      //   }
  41.  
  42.  
  43.         private void Signin_Click(object sender, RoutedEventArgs e)
  44.         {
  45.  
  46.             var client = new RestClient("http://95.85.24.237:8081");
  47.             var request = new RestRequest("/user/auth", Method.POST);
  48.             request.RequestFormat = RestSharp.DataFormat.Json;
  49.  
  50.             request.AddBody(new LogUser
  51.             {
  52.                 username = firstNameTxtBox.Text,
  53.                 password = lastNameTxtBox.Password,
  54.             });
  55.  
  56.             IRestResponse response = client.Execute(request);
  57.             var content = response.Content;
  58.  
  59.             if (content.Contains("Error"))
  60.             {
  61.                 MessageBox.Show("Неверный логин или пароль. Пожалуйста, проверьте их и повторите попытку");
  62.                 return;
  63.             }
  64.  
  65.             var obj = JObject.Parse(content);
  66.             var tokenU = (string)obj["sectoken"];
  67.             var idUs = (string)obj["user"]["id"];
  68.  
  69.  
  70.             Token.id = long.Parse(idUs);
  71.             Token.token = tokenU;
  72.             Token.name = firstNameTxtBox.Text;
  73.  
  74.  
  75.             MainWindow mw;
  76.             // hide main form
  77.             if (MainWindow.flag)
  78.             {
  79.                  mw = ((MainWindow)Application.Current.MainWindow);
  80.                 mw.Hide();
  81.             }
  82.             else
  83.             {
  84.                 mw = new MainWindow();
  85.                 mw = MainWindow.mainWindow;
  86.                 mw.Hide();
  87.             }
  88.          
  89.             // show other form
  90.             ProfileUser profileUser = new ProfileUser();
  91.    
  92.            
  93.             profileUser.Show();
  94.  
  95.             ProfileUser.prf = profileUser;
  96.  
  97.            // MessageBox.Show(Token.id);
  98.  
  99.           //  mw.Close();
  100.  
  101.         }
  102.  
  103.         private void Button_Click(object sender, RoutedEventArgs e)
  104.         {
  105.             NavigationService ns = NavigationService.GetNavigationService(this);
  106.             ns.Navigate(new Uri("RegistrationPage.xaml", UriKind.Relative));
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement