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
9 changes: 8 additions & 1 deletion ChatClient/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using ChatClient.Models;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace ChatClient
{
Expand All @@ -13,5 +16,9 @@ namespace ChatClient
/// </summary>
public partial class App : Application
{
public static Frame PageFrame { get; set; }
public static AccessTokenModel? AccessToken { get; set; }

public static RestClient client = new RestClient();
}
}
2 changes: 1 addition & 1 deletion ChatClient/ChatRoomControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ private void AddPersonBtnClick(object sender, RoutedEventArgs e)

}
}
}
}
23 changes: 21 additions & 2 deletions ChatClient/LoginPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using ChatClient.Models;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -27,12 +29,29 @@ public LoginPage()

private void RegisterBtnClick(object sender, RoutedEventArgs e)
{

App.PageFrame.Navigate(new RegisterPage());
}

private void LoginBtnClick(object sender, RoutedEventArgs e)
{
string id = IDTextBox.Text;
string password = PasswordTextBox.Password;

LoginModel model = new LoginModel(id, password);
RestRequest request = new RestRequest("http://localhost:3000/user/signIn", Method.Post);
request.AddBody(model);

var response = App.client.Execute<ResponseModel<AccessTokenModel>>(request);

if (response.IsSuccessStatusCode && response.Data?.Options != null)
{
App.AccessToken = response.Data.Options;
App.PageFrame.Navigate(new ChatPage());
}
else
{
MessageBox.Show(response.Data?.Message ?? "Unknown error");
}
}
}
}
2 changes: 1 addition & 1 deletion ChatClient/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
Title="MainWindow" Height="450" Width="800" MinWidth="300" MinHeight="500">
<Grid>
<md:Snackbar VerticalAlignment="Top"></md:Snackbar>
<Frame x:Name="PageFrame"></Frame>
<Frame x:Name="PageFrame" NavigationUIVisibility="Hidden"></Frame>
</Grid>
</Window>
2 changes: 2 additions & 0 deletions ChatClient/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
App.PageFrame = PageFrame;
PageFrame.Navigate(new LoginPage());
}
}
}
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
{
internal class LoginModel
{
public string Id { get; set; }
public string Password { get; set; }

public LoginModel(string id, string password) {
Id = id;
Password = password;
}

}
}
Expand Down
16 changes: 16 additions & 0 deletions ChatClient/Models/ResponseModel.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.Threading.Tasks;

namespace ChatClient.Models
{
internal class ResponseModel<T>
{
public string Code { get; set; }
public string Message { get; set; }

public T? Options { get; set; }
}
}
24 changes: 24 additions & 0 deletions ChatClient/Models/SignupModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChatClient.Models
{
internal 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)
{
Id = id;
Name = name;
Password = password;
}
}
}
2 changes: 1 addition & 1 deletion ChatClient/RegisterPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<Label Content="비밀번호"></Label>
<PasswordBox x:Name="PasswordTextBox"/>
<Grid Height="12"></Grid>
<Label Content="비밀번호"></Label>
<Label Content="비밀번호 확인"></Label> <!-- 숙제 -->
<PasswordBox x:Name="PasswordConfirmTextBox"/>
<Grid Height="24"></Grid>
<Grid>
Expand Down
32 changes: 30 additions & 2 deletions ChatClient/RegisterPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
using System;
using ChatClient.Models;
using RestSharp;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -27,12 +31,36 @@ public RegisterPage()

private void BackBtnClick(object sender, RoutedEventArgs e)
{

App.PageFrame.GoBack();
}

private void RegisterBtnClick(object sender, RoutedEventArgs e)
{
string id = IDTextBox.Text;
string username = UsernameTextBox.Text;
string password = PasswordTextBox.Password;
string passwordConfirm = PasswordConfirmTextBox.Password;


if (password != passwordConfirm)
{
MessageBox.Show("비밀번호랑 비밀번호 확인이 달라요!");
}
// TODO: 서버에 회원가입 요청 보내기
SignupModel model = new SignupModel(id, password, username);
RestRequest request = new RestRequest("http://localhost:3000/user/signUp", Method.Post);
request.AddBody(model);

var response = App.client.Execute<ResponseModel<JsonObject>>(request);

if (response.IsSuccessStatusCode && response.Data?.Options != null)
{
App.PageFrame.GoBack();
}
else
{
MessageBox.Show(response.Data?.Message ?? "Unknown error");
}
}
}
}