todo stage1
This commit is contained in:
54
MySolution/ToDoApp/SubWindow/JoinWindow.xaml
Normal file
54
MySolution/ToDoApp/SubWindow/JoinWindow.xaml
Normal file
@@ -0,0 +1,54 @@
|
||||
<Window x:Class="ToDoApp.SubWindow.JoinWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:ToDoApp.SubWindow"
|
||||
mc:Ignorable="d"
|
||||
Title="가입" Height="300" Width="300" ResizeMode="NoResize" WindowStyle="ToolWindow" WindowStartupLocation="CenterScreen"
|
||||
Icon="../Resource/ToDo.png"
|
||||
Loaded="Window_Loaded">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="2*"/>
|
||||
<RowDefinition Height="2*"/>
|
||||
<RowDefinition Height="2*"/>
|
||||
<RowDefinition Height="2*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="2*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<TextBlock Text="사용자" Width="80" TextAlignment="Center" VerticalAlignment="Center" Margin="5"/>
|
||||
<TextBox x:Name="tbName" Width="150" VerticalAlignment="Center" Margin="5"
|
||||
KeyDown="tb_KeyDown"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<TextBlock Text="비밀번호" Width="80" TextAlignment="Center" VerticalAlignment="Center" Margin="5"/>
|
||||
<PasswordBox x:Name="pbPassword" Width="150" VerticalAlignment="Center" Margin="5"
|
||||
PasswordChanged="PasswordChanged"
|
||||
KeyDown="tb_KeyDown"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<TextBlock Text="비밀번호 확인" Width="80" TextAlignment="Center" VerticalAlignment="Center" Margin="5"/>
|
||||
<PasswordBox x:Name="pbVerification" Width="150" VerticalAlignment="Center" Margin="5"
|
||||
PasswordChanged="PasswordChanged"
|
||||
KeyDown="tb_KeyDown"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<TextBlock Text="이메일" Width="80" TextAlignment="Center" VerticalAlignment="Center" Margin="5"/>
|
||||
<TextBox x:Name="tbEmail" Width="150" VerticalAlignment="Center" Margin="5"
|
||||
TextChanged="tbEmail_TextChanged"
|
||||
KeyDown="tb_KeyDown"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock x:Name="tbMessage" Grid.Row="4" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Red" Visibility="Collapsed"/>
|
||||
|
||||
<Button x:Name="btnJoin" Grid.Row="5" Width="150" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Content="가입"
|
||||
Click="btnJoin_Click"/>
|
||||
</Grid>
|
||||
</Window>
|
165
MySolution/ToDoApp/SubWindow/JoinWindow.xaml.cs
Normal file
165
MySolution/ToDoApp/SubWindow/JoinWindow.xaml.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
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.Shapes;
|
||||
using System.Xml.Linq;
|
||||
using ToDoApp.Model;
|
||||
using ToDoApp.Service;
|
||||
|
||||
namespace ToDoApp.SubWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// JoinWindow.xaml에 대한 상호 작용 논리
|
||||
/// </summary>
|
||||
public partial class JoinWindow : Window
|
||||
{
|
||||
public JoinWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private bool VerifyInfo()
|
||||
{
|
||||
if (!CheckName(tbName.Text))
|
||||
return false;
|
||||
|
||||
if (!CheckPassword(pbPassword.Password, pbVerification.Password))
|
||||
return false;
|
||||
|
||||
if (!CheckEmail(tbEmail.Text))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool CheckName(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
tbMessage.Text = "사용자 이름을 입력하세요.";
|
||||
tbMessage.Visibility = Visibility.Visible;
|
||||
return false;
|
||||
}
|
||||
|
||||
User? user = UserService.Instance.FindUser(name);
|
||||
if (user != null)
|
||||
{
|
||||
tbMessage.Text = "사용할 수 없는 이름입니다.";
|
||||
tbMessage.Visibility = Visibility.Visible;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
tbMessage.Visibility = Visibility.Collapsed;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckPassword(string password, string verification)
|
||||
{
|
||||
if (string.IsNullOrEmpty(password) || string.IsNullOrEmpty(verification))
|
||||
{
|
||||
tbMessage.Text = "비밀번호를 입력하세요.";
|
||||
tbMessage.Visibility = Visibility.Visible;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (password != verification)
|
||||
{
|
||||
tbMessage.Text = "비밀번호가 일치하지 않습니다.";
|
||||
tbMessage.Visibility = Visibility.Visible;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
tbMessage.Visibility = Visibility.Collapsed;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckEmail(string email)
|
||||
{
|
||||
if (string.IsNullOrEmpty(email))
|
||||
return true;
|
||||
|
||||
try
|
||||
{
|
||||
MailAddress addr = new MailAddress(email);
|
||||
if (addr.Address != email)
|
||||
{
|
||||
tbMessage.Text = "이메일 형식이 올바르지 않습니다.";
|
||||
tbMessage.Visibility = Visibility.Visible;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
tbMessage.Visibility = Visibility.Collapsed;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
tbMessage.Text = "이메일 형식이 올바르지 않습니다.";
|
||||
tbMessage.Visibility = Visibility.Visible;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void btnJoin_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!VerifyInfo())
|
||||
{
|
||||
MessageBox.Show("가입할 수 없습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
User user = new User()
|
||||
{
|
||||
Name = tbName.Text,
|
||||
Email = tbEmail.Text,
|
||||
Password = pbPassword.Password,
|
||||
CreateDate = DateTime.Now,
|
||||
Status = UserStatus.Valid
|
||||
};
|
||||
|
||||
UserService.Instance.CreateUser(user);
|
||||
|
||||
MessageBox.Show("가입되었습니다.");
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void PasswordChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CheckPassword(pbPassword.Password, pbVerification.Password);
|
||||
}
|
||||
|
||||
private void tbEmail_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
CheckEmail(tbEmail.Text);
|
||||
}
|
||||
|
||||
private void tb_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key != Key.Enter)
|
||||
return;
|
||||
|
||||
btnJoin_Click(this, null);
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
tbName.Focus();
|
||||
}
|
||||
}
|
||||
}
|
40
MySolution/ToDoApp/SubWindow/LoginWindow.xaml
Normal file
40
MySolution/ToDoApp/SubWindow/LoginWindow.xaml
Normal file
@@ -0,0 +1,40 @@
|
||||
<Window x:Class="ToDoApp.SubWindow.LoginWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:ToDoApp.SubWindow"
|
||||
mc:Ignorable="d"
|
||||
Title="로그인" Height="180" Width="300" ResizeMode="NoResize" WindowStyle="ToolWindow" WindowStartupLocation="CenterScreen"
|
||||
Icon="../Resource/ToDo.png"
|
||||
Loaded="Window_Loaded">
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<TextBlock Text="사용자" Width="80" TextAlignment="Center" VerticalAlignment="Center" Margin="5"/>
|
||||
<TextBox x:Name="tbName" Width="150" VerticalAlignment="Center" Margin="5"
|
||||
KeyDown="tb_KeyDown"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<TextBlock Text="비밀번호" Width="80" TextAlignment="Center" VerticalAlignment="Center" Margin="5"/>
|
||||
<PasswordBox Width="150" x:Name="pbPassword" VerticalAlignment="Center" Margin="5"
|
||||
KeyDown="tb_KeyDown"/>
|
||||
</StackPanel>
|
||||
|
||||
<Button x:Name="btnLogin" Grid.Row="2" Width="150" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Content="로그인"
|
||||
Click="btnLogin_Click"/>
|
||||
|
||||
<Button x:Name="btnJoin" Grid.Row="3" Width="150" HorizontalAlignment="Center" VerticalAlignment="Center"
|
||||
Content="가입"
|
||||
Click="btnJoin_Click"/>
|
||||
</Grid>
|
||||
</Window>
|
73
MySolution/ToDoApp/SubWindow/LoginWindow.xaml.cs
Normal file
73
MySolution/ToDoApp/SubWindow/LoginWindow.xaml.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
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.Shapes;
|
||||
using ToDoApp.Model;
|
||||
using ToDoApp.Service;
|
||||
|
||||
namespace ToDoApp.SubWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// LoginWindow.xaml에 대한 상호 작용 논리
|
||||
/// </summary>
|
||||
public partial class LoginWindow : Window
|
||||
{
|
||||
public User User { get; set; }
|
||||
|
||||
public LoginWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private bool CheckLogin(string name, string password)
|
||||
{
|
||||
if (!UserService.Instance.CheckUserLogin(name, password))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
private void btnLogin_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!CheckLogin(tbName.Text, pbPassword.Password))
|
||||
{
|
||||
MessageBox.Show("로그인 정보가 올바르지 않습니다.");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.User = UserService.Instance.FindUser(tbName.Text);
|
||||
|
||||
this.DialogResult = true;
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void btnJoin_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
JoinWindow dlg = new JoinWindow();
|
||||
dlg.ShowDialog();
|
||||
}
|
||||
|
||||
private void tb_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key != Key.Enter)
|
||||
return;
|
||||
|
||||
btnLogin_Click(this, null);
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
tbName.Focus();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user