todo stage1
This commit is contained in:
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();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user