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.
82 lines
2.6 KiB
82 lines
2.6 KiB
8 months ago
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text.RegularExpressions;
|
||
|
using TMPro;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
|
||
|
public class ChangePwdManager : 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 AccountInput;
|
||
|
public TMP_InputField OldPwdInput;
|
||
|
public TMP_InputField PwdInput;
|
||
|
public TMP_InputField PwdSureInput;
|
||
|
public Button SureBtn;
|
||
|
public Button CancelBtn;
|
||
|
|
||
|
private string Api = "/api/Account/ChangePassword";
|
||
|
private ChangePasswordData data = new ChangePasswordData();
|
||
|
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(OldPwdInput.text) && !Regex.IsMatch(OldPwdInput.text, PasswordRegex))
|
||
|
{
|
||
|
var errormsg = PanelsManager.Instance.LoginErrorHintsDic[LoginErrorHints.pwdInvalid];
|
||
|
TipPanelManager.GetInstance.Show(errormsg);
|
||
|
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.oldPassword = OldPwdInput.text;
|
||
|
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)
|
||
|
{
|
||
|
AccountInput.text = account;
|
||
|
AccountInput.interactable = false;
|
||
|
OldPwdInput.text = "";
|
||
|
PwdInput.text = "";
|
||
|
PwdSureInput.text = "";
|
||
|
}
|
||
|
}
|