From a9306d24951fe4171bd7843af904bd1e4551b163 Mon Sep 17 00:00:00 2001 From: Mili Date: Sat, 4 Mar 2023 01:33:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E5=86=8C=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E5=AE=8C=E5=96=84MailSender?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunGame.Core/Api/Transmittal/MailSender.cs | 2 +- FunGame.Core/Api/Utility/General.cs | 2 +- FunGame.Core/Api/Utility/INIHelper.cs | 17 ++++- .../Library/Common/Network/MailObject.cs | 6 +- FunGame.Core/Library/Constant/SQLConstant.cs | 44 ------------ FunGame.Core/Library/Constant/TypeEnum.cs | 4 +- FunGame.Core/Library/Exception/Exception.cs | 5 ++ .../Library/SQLScript/Common/Common.cs | 56 +++++++++++++++ FunGame.Core/Library/SQLScript/Entity/User.cs | 45 ++++++++++++ FunGame.Core/Service/MailManager.cs | 24 +++++-- .../Controller/RegisterController.cs | 25 +++---- FunGame.Desktop/Library/Base/BaseReg.cs | 51 +++++++++++++ FunGame.Desktop/Library/Interface/IReg.cs | 7 -- FunGame.Desktop/Model/RegisterModel.cs | 40 +++++++---- FunGame.Desktop/UI/Login/Login.cs | 6 +- .../UI/Register/Register.Designer.cs | 37 +++++++--- FunGame.Desktop/UI/Register/Register.cs | 71 ++++++++++++++++++- 17 files changed, 335 insertions(+), 107 deletions(-) delete mode 100644 FunGame.Core/Library/Constant/SQLConstant.cs create mode 100644 FunGame.Core/Library/SQLScript/Common/Common.cs create mode 100644 FunGame.Core/Library/SQLScript/Entity/User.cs create mode 100644 FunGame.Desktop/Library/Base/BaseReg.cs delete mode 100644 FunGame.Desktop/Library/Interface/IReg.cs diff --git a/FunGame.Core/Api/Transmittal/MailSender.cs b/FunGame.Core/Api/Transmittal/MailSender.cs index d728c18..5819dfd 100644 --- a/FunGame.Core/Api/Transmittal/MailSender.cs +++ b/FunGame.Core/Api/Transmittal/MailSender.cs @@ -23,7 +23,7 @@ namespace Milimoe.FunGame.Core.Api.Transmittal _SmtpClientInfo = new SmtpClientInfo(SenderMailAddress, SenderName, SenderPassword, Host, Port, OpenSSL); } - public MailObject CreateMail(string Subject, string Body, MailPriority Priority, bool HTML, string[] ToList, string[] CCList, string[] BCCList) + public MailObject CreateMail(string Subject, string Body, MailPriority Priority, bool HTML, string[] ToList, string[]? CCList = null, string[]? BCCList = null) { return new MailObject(this, Subject, Body, Priority, HTML, ToList, CCList, BCCList); } diff --git a/FunGame.Core/Api/Utility/General.cs b/FunGame.Core/Api/Utility/General.cs index 581f5cb..eee4658 100644 --- a/FunGame.Core/Api/Utility/General.cs +++ b/FunGame.Core/Api/Utility/General.cs @@ -179,7 +179,7 @@ namespace Milimoe.FunGame.Core.Api.Utility DateTime now = DateTime.Now; return type switch { - TimeType.DateOnly => now.Date.ToString(""), + TimeType.DateOnly => now.Date.ToString("D"), TimeType.TimeOnly => now.ToString("T"), TimeType.Year4 => now.Year.ToString(), TimeType.Year2 => "'" + now.ToString("yy"), diff --git a/FunGame.Core/Api/Utility/INIHelper.cs b/FunGame.Core/Api/Utility/INIHelper.cs index 8b8cb08..3119a71 100644 --- a/FunGame.Core/Api/Utility/INIHelper.cs +++ b/FunGame.Core/Api/Utility/INIHelper.cs @@ -8,7 +8,7 @@ namespace Milimoe.FunGame.Core.Api.Utility /* * 声明API函数 */ - [LibraryImport("kernel32", StringMarshalling = StringMarshalling.Utf16)] + [LibraryImport("kernel32", EntryPoint = "WritePrivateProfileStringW", StringMarshalling = StringMarshalling.Utf16)] private static partial long WritePrivateProfileString(string section, string key, string val, string filePath); [LibraryImport("Kernel32.dll", EntryPoint = "GetPrivateProfileStringW", StringMarshalling = StringMarshalling.Utf16)] private static partial int GetPrivateProfileString(string section, string key, string def, char[] val, int size, string filePath); @@ -83,6 +83,11 @@ namespace Milimoe.FunGame.Core.Api.Utility WriteINI("Server", "Notice", "This is the FunGame Server's Notice."); WriteINI("Server", "Key", ""); WriteINI("Server", "Status", "1"); + /** + * ServerMail + */ + WriteINI("ServerMail", "OfficialMail", ""); + WriteINI("ServerMail", "SupportMail", ""); /** * Socket */ @@ -97,6 +102,16 @@ namespace Milimoe.FunGame.Core.Api.Utility WriteINI("MySQL", "DBName", "fungame"); WriteINI("MySQL", "DBUser", "root"); WriteINI("MySQL", "DBPassword", "pass"); + /** + * Mailer + */ + WriteINI("Mailer", "UseMailSender", "false"); + WriteINI("Mailer", "MailAddress", ""); + WriteINI("Mailer", "Name", ""); + WriteINI("Mailer", "Password", ""); + WriteINI("Mailer", "Host", ""); + WriteINI("Mailer", "Port", "587"); + WriteINI("Mailer", "OpenSSL", "true"); break; } } diff --git a/FunGame.Core/Library/Common/Network/MailObject.cs b/FunGame.Core/Library/Common/Network/MailObject.cs index 2d9ef2e..71819ee 100644 --- a/FunGame.Core/Library/Common/Network/MailObject.cs +++ b/FunGame.Core/Library/Common/Network/MailObject.cs @@ -12,10 +12,10 @@ namespace Milimoe.FunGame.Core.Library.Common.Network public MailPriority Priority { get; } = MailPriority.Normal; public bool HTML { get; } = false; public string[] ToList { get; } = Array.Empty(); - public string[] CCList { get; } = Array.Empty(); - public string[] BCCList { get; } = Array.Empty(); + public string[]? CCList { get; } = Array.Empty(); + public string[]? BCCList { get; } = Array.Empty(); - public MailObject(MailSender Sender, string Subject, string Body, MailPriority Priority, bool HTML, string[] ToList, string[] CCList, string[] BCCList) + public MailObject(MailSender Sender, string Subject, string Body, MailPriority Priority, bool HTML, string[] ToList, string[]? CCList = null, string[]? BCCList = null) { this.Sender = Sender.SmtpClientInfo.SenderMailAddress; this.SenderName = Sender.SmtpClientInfo.SenderName; diff --git a/FunGame.Core/Library/Constant/SQLConstant.cs b/FunGame.Core/Library/Constant/SQLConstant.cs deleted file mode 100644 index 056e691..0000000 --- a/FunGame.Core/Library/Constant/SQLConstant.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace Milimoe.FunGame.Core.Library.Constant -{ - public class SQLConstant - { - /** - * Commands - */ - public const string Command_Select = "Select"; - public const string Command_Update = "Update"; - public const string Command_Delete = "Delete"; - public const string Command_Insert = "Insert"; - public const string Command_Set = "Set"; - public const string Command_Where = "Where"; - public const string Command_From = "From"; - public const string Command_All = "*"; - public const string Command_Into = "Into"; - public const string Command_Values = "Values"; - public const string Command_And = "And"; - public const string Command_Or = "Or"; - - /** - * Tables - */ - public const string Table_Users = "Users"; - public const string Table_ServerLoginLogs = "ServerLoginLogs"; - - /** - * Select - */ - public const string Select_Users = $"{Command_Select} {Command_All} {Command_From} {Table_Users}"; - - /** - * Update - */ - - /** - * Insert - */ - public static string Insert_ServerLoginLogs(string ServerName, string ServerKey) - { - return $"{Command_Insert} {Command_Into} {Table_ServerLoginLogs} (ServerName, ServerKey, LoginTime) {Command_Values} ('{ServerName}', '{ServerKey}', '{DateTime.Now}')"; - } - } -} diff --git a/FunGame.Core/Library/Constant/TypeEnum.cs b/FunGame.Core/Library/Constant/TypeEnum.cs index c231407..89129f9 100644 --- a/FunGame.Core/Library/Constant/TypeEnum.cs +++ b/FunGame.Core/Library/Constant/TypeEnum.cs @@ -58,7 +58,9 @@ Disconnect, HeartBeat, IntoRoom, - Chat + Chat, + Reg, + CheckReg } public enum SocketRuntimeType diff --git a/FunGame.Core/Library/Exception/Exception.cs b/FunGame.Core/Library/Exception/Exception.cs index 7b446e7..7948380 100644 --- a/FunGame.Core/Library/Exception/Exception.cs +++ b/FunGame.Core/Library/Exception/Exception.cs @@ -124,4 +124,9 @@ { public override string Message => "无法发送邮件 (#10025)"; } + + public class SmtpHelperException : Exception + { + public override string Message => "无法创建Smtp服务 (#10026)"; + } } diff --git a/FunGame.Core/Library/SQLScript/Common/Common.cs b/FunGame.Core/Library/SQLScript/Common/Common.cs new file mode 100644 index 0000000..539abff --- /dev/null +++ b/FunGame.Core/Library/SQLScript/Common/Common.cs @@ -0,0 +1,56 @@ +namespace Milimoe.FunGame.Core.Library.SQLScript +{ + public class Constant + { + /** + * Commands + */ + public const string Command_Select = "Select"; + public const string Command_Update = "Update"; + public const string Command_Delete = "Delete"; + public const string Command_Insert = "Insert"; + public const string Command_Set = "Set"; + public const string Command_Where = "Where"; + public const string Command_From = "From"; + public const string Command_All = "*"; + public const string Command_Into = "Into"; + public const string Command_Values = "Values"; + public const string Command_And = "And"; + public const string Command_Or = "Or"; + } +} + +namespace Milimoe.FunGame.Core.Library.SQLScript.Common +{ + public class ServerLoginLogs + { + public const string TableName = "ServerLoginLogs"; + public const string Column_ServerName = "ServerName"; + public const string Column_ServerKey = "ServerKey"; + public const string Column_LoginTime = "LoginTime"; + + public static string Insert_ServerLoginLogs(string ServerName, string ServerKey) + { + return $"{Constant.Command_Insert} {Constant.Command_Into} {TableName} ({Column_ServerName}, {Column_ServerKey}, {Column_LoginTime}) {Constant.Command_Values} ('{ServerName}', '{ServerKey}', '{DateTime.Now}')"; + } + } + + public class RegVerifyCodes + { + public const string TableName = "RegVerifyCodes"; + public const string Column_Username = "Username"; + public const string Column_Email = "Email"; + public const string Column_RegVerifyCode = "RegVerifyCode"; + public const string Column_RegTime = "RegTime"; + + public static string Insert_RegVerifyCodes(string Username, string Email, string RegVerifyCodes) + { + return $"{Constant.Command_Insert} {Constant.Command_Into} {TableName} ({Column_Username}, {Column_Email}, {Column_RegVerifyCode}, {Column_RegTime}) {Constant.Command_Values} ('{Username}', '{Email}', '{RegVerifyCodes}', '{DateTime.Now}')"; + } + + public static string Select_RegVerifyCode(string Username, string Email, string RegVerifyCode) + { + return $"{Constant.Command_Select} {Constant.Command_All} {Constant.Command_From} {TableName} {Constant.Command_Where} {Column_Username} = '{Username}' and {Column_Email} = '{Email}' and {Column_RegVerifyCode} = '{RegVerifyCode}'"; + } + } +} diff --git a/FunGame.Core/Library/SQLScript/Entity/User.cs b/FunGame.Core/Library/SQLScript/Entity/User.cs new file mode 100644 index 0000000..08250ec --- /dev/null +++ b/FunGame.Core/Library/SQLScript/Entity/User.cs @@ -0,0 +1,45 @@ +namespace Milimoe.FunGame.Core.Library.SQLScript.Entity +{ + public class UserQuery + { + public const string TableName= "User"; + public const string Column_UID = "UID"; + public const string Column_Username = "Username"; + public const string Column_Password = "Password"; + public const string Column_RegTime = "RegTime"; + public const string Column_LastTime = "LastTime"; + public const string Column_LastIP = "LastIP"; + public const string Column_Email = "Email"; + public const string Column_Nickname = "Nickname"; + public const string Column_IsAdmin = "IsAdmin"; + public const string Column_IsOperator = "IsOperator"; + public const string Column_IsEnable = "IsEnable"; + public const string Column_OnlineState = "OnlineState"; + public const string Column_Credits = "Credits"; + public const string Column_Materials = "Materials"; + public const string Column_GameTime = "GameTime"; + public const string Select_Users = $"{Constant.Command_Select} {Constant.Command_All} {Constant.Command_From} {TableName}"; + + public static string Select_Users_LoginQuery(string Username, string Password) + { + return $"{Select_Users} {Constant.Command_Where} {Column_Username} = '{Username}' and {Column_Password} = '{Password}'"; + } + + public static string Select_Users_Where(string Where) + { + return $"{Select_Users} {Constant.Command_Where} {Where}'"; + } + + public static string CheckLogin(string Username, string IP) + { + return @$"{Constant.Command_Update} {TableName} {Constant.Command_Set} {Column_LastTime} = '{DateTime.Now}', {Column_LastIP} = '{IP}' + {Constant.Command_Where} {Column_Username} = '{Username}'"; + } + + public static string Register(string UserName, string Password, string Email) + { + return @$"{Constant.Command_Insert} {Constant.Command_Into} {TableName} ({Column_Username}, {Column_Password}, {Column_Email}, {Column_RegTime}) + {Constant.Command_Values} ('{UserName}', '{Password}', {Email}, '{DateTime.Now}')"; + } + } +} diff --git a/FunGame.Core/Service/MailManager.cs b/FunGame.Core/Service/MailManager.cs index 7edc08e..c39e983 100644 --- a/FunGame.Core/Service/MailManager.cs +++ b/FunGame.Core/Service/MailManager.cs @@ -37,22 +37,32 @@ namespace Milimoe.FunGame.Core.Service MailMessage Msg = new() { Subject = Mail.Subject, - SubjectEncoding = General.DefaultEncoding, + SubjectEncoding = System.Text.Encoding.UTF8, Body = Mail.Body, - BodyEncoding = General.DefaultEncoding, - From = new MailAddress(Mail.Sender, Mail.SenderName, General.DefaultEncoding), + BodyEncoding = System.Text.Encoding.UTF8, + From = new MailAddress(Mail.Sender, Mail.SenderName, System.Text.Encoding.UTF8), IsBodyHtml = Mail.HTML, Priority = Mail.Priority }; foreach (string To in Mail.ToList) { - Msg.To.Add(To); + if (To.Trim() != "") Msg.To.Add(To); } - foreach (string CC in Mail.CCList) + if (Mail.CCList != null) { - Msg.CC.Add(CC); + foreach (string CC in Mail.CCList) + { + if (CC.Trim() != "") Msg.CC.Add(CC); + } } - Smtp.Send(Msg); + if (Mail.BCCList != null) + { + foreach (string BCC in Mail.BCCList) + { + if (BCC.Trim() != "") Msg.Bcc.Add(BCC); + } + } + Smtp.SendMailAsync(Msg); return MailSendResult.Success; } catch (Exception e) diff --git a/FunGame.Desktop/Controller/RegisterController.cs b/FunGame.Desktop/Controller/RegisterController.cs index 97f6618..a0c0726 100644 --- a/FunGame.Desktop/Controller/RegisterController.cs +++ b/FunGame.Desktop/Controller/RegisterController.cs @@ -1,21 +1,22 @@ -using Milimoe.FunGame.Desktop.Library.Interface; +using Milimoe.FunGame.Core.Library.Common.Event; +using Milimoe.FunGame.Desktop.Library.Component; +using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Model; -using Milimoe.FunGame.Desktop.UI; namespace Milimoe.FunGame.Desktop.Controller { - public class RegisterController : IReg + public class RegisterController { - RegisterModel RegisterModel { get; } - - public RegisterController(Register Register) + public static bool Reg(params object[]? objs) { - RegisterModel = new RegisterModel(Register); - } - - public bool Reg() - { - return RegisterModel.Reg(); + RunTime.Register?.OnBeforeRegEvent(new GeneralEventArgs()); + bool result = RegisterModel.Reg(objs); + if (!result) + { + ShowMessage.ErrorMessage("注册失败!!", "注册失败", 5); + RunTime.Register?.OnFailedRegEvent(new GeneralEventArgs()); + } + return result; } } } diff --git a/FunGame.Desktop/Library/Base/BaseReg.cs b/FunGame.Desktop/Library/Base/BaseReg.cs new file mode 100644 index 0000000..5c626dd --- /dev/null +++ b/FunGame.Desktop/Library/Base/BaseReg.cs @@ -0,0 +1,51 @@ +using Milimoe.FunGame.Core.Interface; +using Milimoe.FunGame.Core.Library.Common.Event; +using Milimoe.FunGame.Core.Library.Constant; +using Milimoe.FunGame.Desktop.Library.Component; + +namespace Milimoe.FunGame.Desktop.Library.Base +{ + public class BaseReg : GeneralForm, IRegEventHandler + { + public event IEventHandler.BeforeEventHandler? BeforeReg; + public event IEventHandler.AfterEventHandler? AfterReg; + public event IEventHandler.SucceedEventHandler? SucceedReg; + public event IEventHandler.FailedEventHandler? FailedReg; + + public EventResult OnAfterRegEvent(GeneralEventArgs e) + { + if (AfterReg != null) + { + return AfterReg(this, e); + } + else return EventResult.NoEventImplement; + } + + public EventResult OnBeforeRegEvent(GeneralEventArgs e) + { + if (BeforeReg != null) + { + return BeforeReg(this, e); + } + else return EventResult.NoEventImplement; + } + + public EventResult OnFailedRegEvent(GeneralEventArgs e) + { + if (FailedReg != null) + { + return FailedReg(this, e); + } + else return EventResult.NoEventImplement; + } + + public EventResult OnSucceedRegEvent(GeneralEventArgs e) + { + if (SucceedReg != null) + { + return SucceedReg(this, e); + } + else return EventResult.NoEventImplement; + } + } +} diff --git a/FunGame.Desktop/Library/Interface/IReg.cs b/FunGame.Desktop/Library/Interface/IReg.cs deleted file mode 100644 index ab0afe3..0000000 --- a/FunGame.Desktop/Library/Interface/IReg.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Milimoe.FunGame.Desktop.Library.Interface -{ - public interface IReg - { - public bool Reg(); - } -} diff --git a/FunGame.Desktop/Model/RegisterModel.cs b/FunGame.Desktop/Model/RegisterModel.cs index 6c994ae..7f1737c 100644 --- a/FunGame.Desktop/Model/RegisterModel.cs +++ b/FunGame.Desktop/Model/RegisterModel.cs @@ -1,23 +1,33 @@ -using Milimoe.FunGame.Desktop.Library; -using Milimoe.FunGame.Desktop.Library.Interface; -using Milimoe.FunGame.Desktop.UI; +using Milimoe.FunGame.Core.Library.Constant; +using Milimoe.FunGame.Core.Library.Exception; +using Milimoe.FunGame.Desktop.Library; namespace Milimoe.FunGame.Desktop.Model { - public class RegisterModel : IReg + public class RegisterModel { - private readonly Register Register; - private Core.Library.Common.Network.Socket? Socket; - - public RegisterModel(Register register) + public static bool Reg(params object[]? objs) { - Register = register; - Socket = RunTime.Socket; - } - - public bool Reg() - { - return true; + try + { + Core.Library.Common.Network.Socket? Socket = RunTime.Socket; + if (Socket != null && objs != null) + { + string username = ""; + string email = ""; + if (objs.Length > 0) username = (string)objs[0]; + if (objs.Length > 1) email = (string)objs[1]; + if (Socket.Send(SocketMessageType.Reg, username, email) == SocketResult.Success) + { + return true; + } + } + } + catch (Exception e) + { + e.GetErrorInfo(); + } + return false; } } } diff --git a/FunGame.Desktop/UI/Login/Login.cs b/FunGame.Desktop/UI/Login/Login.cs index 906e38d..c00c761 100644 --- a/FunGame.Desktop/UI/Login/Login.cs +++ b/FunGame.Desktop/UI/Login/Login.cs @@ -19,8 +19,10 @@ namespace Milimoe.FunGame.Desktop.UI protected override void BindEvent() { base.BindEvent(); - SucceedLogin += SucceedLoginEvent; + BeforeLogin += BeforeLoginEvent; + AfterLogin += AfterLoginEvent; FailedLogin += FailedLoginEvent; + SucceedLogin += SucceedLoginEvent; } private bool Login_Handler() @@ -56,7 +58,7 @@ namespace Milimoe.FunGame.Desktop.UI /// private void RegButton_Click(object sender, EventArgs e) { - OpenForm.SingleForm(Core.Library.Constant.FormType.Register, Core.Library.Constant.OpenFormType.Dialog); + OpenForm.SingleForm(FormType.Register, OpenFormType.Dialog); } private void FastLogin_Click(object sender, EventArgs e) diff --git a/FunGame.Desktop/UI/Register/Register.Designer.cs b/FunGame.Desktop/UI/Register/Register.Designer.cs index 51e7a13..30d9936 100644 --- a/FunGame.Desktop/UI/Register/Register.Designer.cs +++ b/FunGame.Desktop/UI/Register/Register.Designer.cs @@ -46,6 +46,15 @@ this.TransparentRect.SuspendLayout(); this.SuspendLayout(); // + // Title + // + this.Title.Font = new System.Drawing.Font("LanaPixel", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); + this.Title.Location = new System.Drawing.Point(4, 4); + this.Title.Size = new System.Drawing.Size(391, 47); + this.Title.TabIndex = 8; + this.Title.Text = "FunGame Register"; + this.Title.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // // ExitButton // this.ExitButton.Anchor = System.Windows.Forms.AnchorStyles.None; @@ -60,6 +69,7 @@ this.ExitButton.ForeColor = System.Drawing.Color.Red; this.ExitButton.Location = new System.Drawing.Point(453, 4); this.ExitButton.Name = "ExitButton"; + this.ExitButton.RelativeForm = null; this.ExitButton.Size = new System.Drawing.Size(47, 47); this.ExitButton.TabIndex = 7; this.ExitButton.TextAlign = System.Drawing.ContentAlignment.TopLeft; @@ -80,21 +90,12 @@ this.MinButton.ForeColor = System.Drawing.Color.Black; this.MinButton.Location = new System.Drawing.Point(401, 4); this.MinButton.Name = "MinButton"; + this.MinButton.RelativeForm = null; this.MinButton.Size = new System.Drawing.Size(47, 47); this.MinButton.TabIndex = 6; this.MinButton.TextAlign = System.Drawing.ContentAlignment.TopLeft; this.MinButton.UseVisualStyleBackColor = false; // - // Title - // - this.Title.Font = new System.Drawing.Font("LanaPixel", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point); - this.Title.Location = new System.Drawing.Point(4, 4); - this.Title.Name = "Title"; - this.Title.Size = new System.Drawing.Size(391, 47); - this.Title.TabIndex = 8; - this.Title.Text = "FunGame Register"; - this.Title.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; - // // Username // this.Username.Font = new System.Drawing.Font("LanaPixel", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); @@ -160,6 +161,7 @@ this.RegButton.TabIndex = 4; this.RegButton.Text = "注册"; this.RegButton.UseVisualStyleBackColor = true; + this.RegButton.Click += new System.EventHandler(this.RegButton_Click); // // GoToLogin // @@ -170,6 +172,7 @@ this.GoToLogin.TabIndex = 5; this.GoToLogin.Text = "登录"; this.GoToLogin.UseVisualStyleBackColor = true; + this.GoToLogin.Click += new System.EventHandler(this.GoToLogin_Click); // // EmailText // @@ -214,6 +217,19 @@ this.TransparentRect.Size = new System.Drawing.Size(503, 319); this.TransparentRect.TabIndex = 13; this.TransparentRect.TabStop = false; + this.TransparentRect.Controls.SetChildIndex(this.UsernameText, 0); + this.TransparentRect.Controls.SetChildIndex(this.CheckPassword, 0); + this.TransparentRect.Controls.SetChildIndex(this.PasswordText, 0); + this.TransparentRect.Controls.SetChildIndex(this.Password, 0); + this.TransparentRect.Controls.SetChildIndex(this.CheckPasswordText, 0); + this.TransparentRect.Controls.SetChildIndex(this.Username, 0); + this.TransparentRect.Controls.SetChildIndex(this.RegButton, 0); + this.TransparentRect.Controls.SetChildIndex(this.GoToLogin, 0); + this.TransparentRect.Controls.SetChildIndex(this.Title, 0); + this.TransparentRect.Controls.SetChildIndex(this.Email, 0); + this.TransparentRect.Controls.SetChildIndex(this.ExitButton, 0); + this.TransparentRect.Controls.SetChildIndex(this.EmailText, 0); + this.TransparentRect.Controls.SetChildIndex(this.MinButton, 0); // // Register // @@ -222,7 +238,6 @@ this.BackColor = System.Drawing.Color.WhiteSmoke; this.ClientSize = new System.Drawing.Size(503, 319); this.Controls.Add(this.TransparentRect); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "Register"; this.Opacity = 0.9D; diff --git a/FunGame.Desktop/UI/Register/Register.cs b/FunGame.Desktop/UI/Register/Register.cs index 8def1c8..a14564d 100644 --- a/FunGame.Desktop/UI/Register/Register.cs +++ b/FunGame.Desktop/UI/Register/Register.cs @@ -1,14 +1,66 @@ -using Milimoe.FunGame.Desktop.Library.Component; +using Milimoe.FunGame.Core.Library.Common.Event; +using Milimoe.FunGame.Core.Library.Constant; +using Milimoe.FunGame.Core.Library.Exception; +using Milimoe.FunGame.Desktop.Controller; +using Milimoe.FunGame.Desktop.Library; +using Milimoe.FunGame.Desktop.Library.Base; +using Milimoe.FunGame.Desktop.Library.Component; namespace Milimoe.FunGame.Desktop.UI { - public partial class Register : GeneralForm + public partial class Register : BaseReg { public Register() { InitializeComponent(); } + protected override void BindEvent() + { + base.BindEvent(); + SucceedReg += SucceedRegEvent; + } + + private bool Reg_Handler() + { + try + { + string username = UsernameText.Text.Trim(); + string password = PasswordText.Text.Trim(); + string checkpassword = CheckPasswordText.Text.Trim(); + string email = EmailText.Text.Trim(); + if (username == "" || password == "" || checkpassword == "") + { + ShowMessage.ErrorMessage("账号或密码不能为空!"); + UsernameText.Focus(); + return false; + } + if (password != checkpassword) + { + ShowMessage.ErrorMessage("两个密码不相同,请重新输入!"); + CheckPasswordText.Focus(); + return false; + } + if (email == "") + { + ShowMessage.ErrorMessage("邮箱不能为空!"); + UsernameText.Focus(); + return false; + } + if (!RegisterController.Reg(username, email)) + { + ShowMessage.Message("注册失败!!", "注册失败"); + return false; + } + } + catch (Exception e) + { + RunTime.WritelnSystemInfo(e.GetErrorInfo()); + return false; + } + return true; + } + /// /// 关闭窗口 /// @@ -18,5 +70,20 @@ namespace Milimoe.FunGame.Desktop.UI { Dispose(); } + + private EventResult SucceedRegEvent(object sender, GeneralEventArgs e) + { + return EventResult.Success; + } + + private void RegButton_Click(object sender, EventArgs e) + { + Reg_Handler(); + } + + private void GoToLogin_Click(object sender, EventArgs e) + { + Dispose(); + } } }