Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChatClient/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ChatClient.Models;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Configuration;
Expand All @@ -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();
}
}
10 changes: 5 additions & 5 deletions ChatClient/LoginPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResponseModel<AccessTokenModel>>(request);
var response = App.client.Execute<ResponseModel<AccessTokenModel>>(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");
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions ChatClient/Models/AccessTokenModel.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
20 changes: 20 additions & 0 deletions ChatClient/Models/LoginModel.cs
Original file line number Diff line number Diff line change
@@ -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;
}

}
}
19 changes: 19 additions & 0 deletions ChatClient/Models/ResponseModel.cs
Original file line number Diff line number Diff line change
@@ -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<T>
{

public string code { get; set;}


public string message { get; set;}

public T? options { get; set; }
}
}
21 changes: 21 additions & 0 deletions ChatClient/Models/SignupModel.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
8 changes: 4 additions & 4 deletions ChatClient/RegisterPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResponseModel<JsonObject>>(request);
var response = App.client.Execute<ResponseModel<JsonObject>>(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");
}
}
}
Expand Down