You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
172 lines
6.3 KiB
172 lines
6.3 KiB
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.Text.RegularExpressions; |
|
using TMPro; |
|
using UnityEngine; |
|
using UnityEngine.EventSystems; |
|
using UnityEngine.UI; |
|
|
|
public class RegisterManager : MonoBehaviour, IPointerClickHandler |
|
{ |
|
public const string UserNameRegex = @"^[a-zA-Z0-9!@#$%^&*()_\-+=]{4,24}$"; |
|
public const string UserRealNameRegex = @"^[a-zA-Z0-9\u4e00-\u9fa5]{2,10}$"; |
|
public const string CitizenIdentificationNumberRegex = @"^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$"; |
|
public const string PhoneNumberRegex = @"^1\d{10}$"; |
|
public const string PasswordRegex = @"^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,24}$"; |
|
public TMP_Text ShowName; |
|
public Button SureBtn; |
|
public Button CancelBtn; |
|
public TMP_InputField XAccount; //账号 |
|
public TMP_InputField XPwd;//密码 |
|
public TMP_InputField XName; //姓名 |
|
public TMP_InputField XPhone;//电话(默认账号) |
|
public Toggle XSex;//性别 |
|
public OrganizationsLoadPanel XOrg;//组织机构 |
|
public PostsLoadPanel XPosts;//岗位职级 |
|
|
|
public TMP_InputField XIdent; |
|
private string RegistorApi = "/api/Account/SignUp"; |
|
private RegistorUser registorUser; |
|
|
|
public void OnPointerClick(PointerEventData eventData) |
|
{ |
|
if (eventData.button == PointerEventData.InputButton.Left) |
|
{ |
|
//Debug.Log("Left"); |
|
|
|
if (XOrg.Top.isOn) |
|
{ |
|
XOrg.Top.isOn = false; |
|
} |
|
if (XPosts.Top.isOn) |
|
{ |
|
XPosts.Top.isOn = false; |
|
} |
|
} |
|
} |
|
void Start() |
|
{ |
|
SureBtn.onClick.AddListener(SureBtn_Click); |
|
CancelBtn.onClick.AddListener(CancelBtn_Click); |
|
} |
|
private void CancelBtn_Click() |
|
{ |
|
PanelsManager.Instance.GotoLoginWindow(); |
|
} |
|
private void SureBtn_Click() |
|
{ |
|
if (string.IsNullOrEmpty(XName.text.Trim())) |
|
{ |
|
var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.nameNo]; |
|
TipPanelManager.GetInstance.Show(errormsg); |
|
return; |
|
} |
|
if (XOrg.SelectData == null || string.IsNullOrEmpty(XOrg.SelectData.id)) |
|
{ |
|
var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.orgNo]; |
|
TipPanelManager.GetInstance.Show(errormsg); |
|
return; |
|
} |
|
if (string.IsNullOrEmpty(XPhone.text.Trim())) |
|
{ |
|
var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.phoneNo]; |
|
TipPanelManager.GetInstance.Show(errormsg); |
|
return; |
|
} |
|
if (!string.IsNullOrEmpty(XName.text.Trim())) |
|
{ |
|
if (!Regex.IsMatch(XName.text.Trim(), UserRealNameRegex)) |
|
{ |
|
var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.nameInvalid]; |
|
TipPanelManager.GetInstance.Show(errormsg); |
|
return; |
|
} |
|
} |
|
if (!string.IsNullOrEmpty(XAccount.text.Trim())) |
|
{ |
|
if (!Regex.IsMatch(XAccount.text.Trim(), UserNameRegex)) |
|
{ |
|
var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.accountInvalid]; |
|
TipPanelManager.GetInstance.Show(errormsg); |
|
return; |
|
} |
|
} |
|
//if (string.IsNullOrEmpty(XIdent.text.Trim())) |
|
//{ |
|
// var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.identyNo]; |
|
// TipPanelManager.GetInstance.Show(errormsg); |
|
// return; |
|
//} |
|
if (!string.IsNullOrEmpty(XPwd.text) && !Regex.IsMatch(XPwd.text, PasswordRegex)) |
|
{ |
|
var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.pwdInvalid]; |
|
TipPanelManager.GetInstance.Show(errormsg); |
|
return; |
|
} |
|
if (!string.IsNullOrEmpty(XPhone.text) && !Regex.IsMatch(XPhone.text, PhoneNumberRegex)) |
|
{ |
|
var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.phoneInvalid]; |
|
TipPanelManager.GetInstance.Show(errormsg); |
|
return; |
|
} |
|
if (!string.IsNullOrEmpty(XIdent.text) && !Regex.IsMatch(XIdent.text, CitizenIdentificationNumberRegex)) |
|
{ |
|
var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.identyInvalid]; |
|
TipPanelManager.GetInstance.Show(errormsg); |
|
return; |
|
} |
|
|
|
registorUser.realName = XName.text.Trim(); |
|
registorUser.username = string.IsNullOrEmpty(XAccount.text.Trim()) ? XPhone.text.Trim() : XAccount.text.Trim(); |
|
registorUser.organizationId = XOrg.SelectData.id; |
|
registorUser.password = string.IsNullOrEmpty(XPwd.text) ? null : XPwd.text; |
|
registorUser.phoneNumber = XPhone.text.Trim(); |
|
registorUser.citizenIdentificationNumber = XIdent.text.Trim(); |
|
registorUser.postIds = new List<string>(); |
|
foreach (var item in XPosts.SelectDatas) |
|
{ |
|
registorUser.postIds.Add(item.Id); |
|
} |
|
registorUser.roleType = PanelsManager.Instance.NowRoleType; |
|
HTTPRequestManager.Instance.PostJson<RegistorUser, RegistorUser>( |
|
RegistorApi, registorUser, RegistorSuccessed, RegistorError); |
|
|
|
} |
|
|
|
private void RegistorError(int code, string message) |
|
{ |
|
TipPanelManager.GetInstance.Show($"注册失败:\n{message}"); |
|
} |
|
|
|
private void RegistorSuccessed(RegistorUser obj) |
|
{ |
|
//string JY = PanelsManager.Instance.NowRoleType == RoleType.教员 ? "返回登录!" : "等待审核通过后登录!"; |
|
TipPanelManager.GetInstance.Show($"恭喜{obj.username}注册成功,请返回登录!", () => |
|
{ |
|
PanelsManager.Instance.GotoLoginWindow(obj.username); |
|
}); |
|
} |
|
internal void OnShow() |
|
{ |
|
registorUser = new RegistorUser(); |
|
if (PanelsManager.Instance.NowRoleType == RoleType.教员) |
|
{ |
|
ShowName.text = "教员注册"; |
|
} |
|
else |
|
{ |
|
ShowName.text = "学员注册"; |
|
} |
|
|
|
XName.text = ""; |
|
XSex.isOn = true; |
|
XOrg.Reset(); |
|
XPhone.text = ""; |
|
XPwd.text = ""; |
|
XIdent.text = ""; |
|
XPosts.Reset(); |
|
|
|
XName.ActivateInputField(); |
|
} |
|
}
|
|
|