培训考核三期,新版培训,网页版培训登录器
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.

89 lines
2.7 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class LostPwdManager : MonoBehaviour
{
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_InputField PhoneInput;
public TMP_InputField NameInput;
public TMP_InputField PwdInput;
public TMP_InputField PwdSureInput;
public Button SureBtn;
public Button CancelBtn;
private string NowAccount = "";
private string Api = "/api/SSO/ForgetPassword";
private LostPasswordData data = new LostPasswordData();
void Start()
{
SureBtn.onClick.AddListener(SureBtn_Click);
CancelBtn.onClick.AddListener(Cancel_Click);
}
private void Cancel_Click()
{
PanelsManager.Instance.GotoLoginWindow();
}
private void SureBtn_Click()
{
if (string.IsNullOrEmpty(PhoneInput.text.Trim()))
{
TipPanelManager.GetInstance.Show("手机号不能为空!");
return;
}
if (string.IsNullOrEmpty(NameInput.text.Trim()))
{
TipPanelManager.GetInstance.Show("姓名不能为空!");
return;
}
if (!string.IsNullOrEmpty(PwdInput.text) && !Regex.IsMatch(PwdInput.text, PasswordRegex))
{
var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.pwdInvalid];
TipPanelManager.GetInstance.Show(errormsg);
return;
}
if (PwdInput.text != PwdSureInput.text)
{
var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.pwdNeedSame];
TipPanelManager.GetInstance.Show(errormsg);
return;
}
data.phoneNumber = PhoneInput.text.Trim();
data.realName = NameInput.text.Trim();
data.newPassword = PwdInput.text;
HTTPRequestManager.Instance.PatchJson(
Api, data, LostPwdSuccessed, LostPwdError);
}
private void LostPwdError(int code, string message)
{
TipPanelManager.GetInstance.Show("重置密码失败!是否继续?", cancel: () =>
{
PanelsManager.Instance.GotoLoginWindow();
});
}
private void LostPwdSuccessed()
{
TipPanelManager.GetInstance.Show($"密码修改成功!,请重新登录", () =>
{
PanelsManager.Instance.GotoLoginWindow();
});
}
internal void OnShow(string account)
{
NowAccount = account;
PhoneInput.text = "";
PhoneInput.ActivateInputField();
NameInput.text = "";
PwdInput.text = "";
PwdSureInput.text = "";
}
}