diff --git a/ChatClient/App.xaml.cs b/ChatClient/App.xaml.cs index 2def0a7..2696a4f 100644 --- a/ChatClient/App.xaml.cs +++ b/ChatClient/App.xaml.cs @@ -1,4 +1,5 @@ using ChatClient.Models; +using RestSharp; using System; using System.Collections.Generic; using System.Configuration; @@ -17,5 +18,7 @@ public partial class App : Application { public static Frame PageFrame { get; set; } public static AccessTokenModel? AccessToken { get; set; } + + public static RestClient client = new RestClient(); } } diff --git a/ChatClient/LoginPage.xaml.cs b/ChatClient/LoginPage.xaml.cs index c3757e0..9fcf0a8 100644 --- a/ChatClient/LoginPage.xaml.cs +++ b/ChatClient/LoginPage.xaml.cs @@ -38,20 +38,20 @@ private void LoginBtnClick(object sender, RoutedEventArgs e) string password = PasswordTextBox.Password; LoginModel model = new LoginModel(id, password); - RestClient client = new RestClient(); + RestRequest request = new RestRequest("http://localhost:3000/signIn", Method.Post); request.AddBody(model); - var response = client.Execute>(request); + var response = App.client.Execute>(request); - if (response.IsSuccessStatusCode && response.Data?.Options != null) + if (response.IsSuccessStatusCode && response.Data?.options != null) { - App.AccessToken = response.Data.Options; + App.AccessToken = response.Data.options; App.PageFrame.Navigate(new ChatPage()); } else { - MessageBox.Show(response.Data?.Message ?? "Unknown error"); + MessageBox.Show(response.Data?.message ?? "Unknown error"); } } } diff --git a/ChatClient/Models/AccessTokenModel.cs b/ChatClient/Models/AccessTokenModel.cs new file mode 100644 index 0000000..769b0d5 --- /dev/null +++ b/ChatClient/Models/AccessTokenModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; + +namespace ChatClient.Models +{ + public class AccessTokenModel + { + //[JsonPropertyName("token")] + public string Token { get; set; } + public string RefreshToken { get; set; } + } +} diff --git a/ChatClient/Models/LoginModel.cs b/ChatClient/Models/LoginModel.cs new file mode 100644 index 0000000..d8e0436 --- /dev/null +++ b/ChatClient/Models/LoginModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ChatClient.Models +{ + public class LoginModel + { + public string Id { get; set; } + public string Password { get; set; } + + public LoginModel(string id, string password){ + Id = id; + Password = password; + } + + } +} diff --git a/ChatClient/Models/ResponseModel.cs b/ChatClient/Models/ResponseModel.cs new file mode 100644 index 0000000..9144249 --- /dev/null +++ b/ChatClient/Models/ResponseModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ChatClient.Models +{ + public class ResponseModel + { + + public string code { get; set;} + + + public string message { get; set;} + + public T? options { get; set; } + } +} diff --git a/ChatClient/Models/SignupModel.cs b/ChatClient/Models/SignupModel.cs new file mode 100644 index 0000000..70d506a --- /dev/null +++ b/ChatClient/Models/SignupModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ChatClient.Models +{ + public class SignupModel + { + public string id { get; set; } + public string name { get; set; } + + public string Password { get; set; } + public SignupModel(string id, string Password, string name) { + this.id = id; + this.Password = Password; + this.name = name; + } + } +} diff --git a/ChatClient/RegisterPage.xaml.cs b/ChatClient/RegisterPage.xaml.cs index 7e30bd2..70f1cbd 100644 --- a/ChatClient/RegisterPage.xaml.cs +++ b/ChatClient/RegisterPage.xaml.cs @@ -47,19 +47,19 @@ private void RegisterBtnClick(object sender, RoutedEventArgs e) } SignupModel model = new SignupModel(id, password, username); - RestClient client = new RestClient(); + RestRequest request = new RestRequest("http://localhost:3000/signUp", Method.Post); request.AddBody(model); - var response = client.Execute>(request); + var response = App.client.Execute>(request); - if (response.IsSuccessStatusCode && response.Data?.Options != null) + if (response.IsSuccessStatusCode && response.Data?.options != null) { App.PageFrame.GoBack(); } else { - MessageBox.Show(response.Data?.Message ?? "Unknown error"); + MessageBox.Show(response.Data?.message ?? "Unknown error"); } } }