1. 新增账号注销全流程功能,包括注销页面、验证码校验和注销接口调用 2. 优化邮箱注册校验逻辑,区分已设置密码和未设置密码的账号 3. 重构个人页面登出逻辑,统一登出处理流程 4. 更新多语言文案,补充注销相关提示文本 5. 调整个人信息页面布局,添加注销账号入口
222 lines
6.8 KiB
C#
222 lines
6.8 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Kill.UI.Components;
|
|
using Kill.Managers;
|
|
using System.Threading.Tasks;
|
|
using System;
|
|
using Kill.Network;
|
|
|
|
namespace Kill.UI.Pages
|
|
{
|
|
/// <summary>
|
|
/// 验证码页面
|
|
/// </summary>
|
|
public class SelfVerificationCodePanel : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 验证码使用场景
|
|
/// </summary>
|
|
public enum VerificationScene
|
|
{
|
|
SetPassword, // 设置/重置密码
|
|
CancelAccount // 注销账号
|
|
}
|
|
[Header("显示")]
|
|
public Text countdownText;
|
|
public Text emailText;
|
|
public Text errorText;
|
|
public int countdownSeconds = 60;
|
|
[Header("输入")]
|
|
public VerificationCodeInput codeInput;
|
|
|
|
[Header("按钮")]
|
|
public Button resendBtn;
|
|
|
|
// 倒计时协程
|
|
private Coroutine countdownCoroutine;
|
|
private string countdownTip;
|
|
|
|
public Button backButton;
|
|
Action onSuccessCallback;
|
|
Action onBackCallback;
|
|
public VerificationScene sceneType = VerificationScene.SetPassword;
|
|
/// <summary>
|
|
/// 校验通过的验证码(校验成功后有效)
|
|
/// </summary>
|
|
public string VerifiedCode { get; private set; }
|
|
public void Init(Action onsuccess, Action onback, VerificationScene scene = VerificationScene.SetPassword)
|
|
{
|
|
onSuccessCallback=onsuccess;
|
|
onBackCallback=onback;
|
|
sceneType = scene;
|
|
if(scene==VerificationScene.SetPassword)
|
|
UIManager.Instance.RegisterBackAction(OnBack);
|
|
backButton.onClick.RemoveAllListeners();
|
|
backButton.onClick.AddListener(OnBack);
|
|
if (codeInput != null)
|
|
{
|
|
codeInput.OnCodeCompleted += OnCodeCompleted;
|
|
}
|
|
|
|
if (resendBtn != null)
|
|
resendBtn.onClick.AddListener(OnResend);
|
|
countdownTip = LanguageManager.Instance.GetLanguage("100014");
|
|
// 清空验证码
|
|
if (codeInput != null)
|
|
{
|
|
codeInput.Clear();
|
|
codeInput.Focus();
|
|
}
|
|
resendBtn.gameObject.SetActive(true);
|
|
countdownText.gameObject.SetActive(false);
|
|
emailText.text = DataManager.Instance.userInfo.email;
|
|
countdownText.text = countdownTip.Replace("{0}", countdownSeconds.ToString());
|
|
OnResend();
|
|
}
|
|
|
|
|
|
private void OnDestroy()
|
|
{
|
|
// 停止倒计时
|
|
if (countdownCoroutine != null)
|
|
{
|
|
StopCoroutine(countdownCoroutine);
|
|
countdownCoroutine = null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void OnCodeCompleted(string code)
|
|
{
|
|
Debug.Log($"验证码输入完成: {code}");
|
|
// 可以自动提交
|
|
OnConfirm();
|
|
}
|
|
|
|
|
|
private async Task OnConfirm()
|
|
{
|
|
string code = codeInput != null ? codeInput.GetCode() : "";
|
|
// 注销账号场景:不单独校验验证码,直接使用(由注销接口校验)
|
|
if (sceneType == VerificationScene.CancelAccount)
|
|
{
|
|
VerifiedCode = code;
|
|
onSuccessCallback?.Invoke();
|
|
return;
|
|
}
|
|
// 验证验证码
|
|
VerifyCode(emailText.text, code,
|
|
onSuccess: () =>
|
|
{
|
|
VerifiedCode = code;
|
|
onSuccessCallback?.Invoke();
|
|
},
|
|
onError: (code, message) =>
|
|
{
|
|
// 显示错误
|
|
errorText.text = LanguageManager.Instance.GetLanguage("100017");
|
|
}
|
|
);
|
|
}
|
|
|
|
private async void OnResend()
|
|
{
|
|
LoadingUI.Show();
|
|
|
|
var requestData = new EmailCodeRequest
|
|
{
|
|
email = emailText.text
|
|
};
|
|
|
|
try
|
|
{
|
|
var response = await NetworkCtrl.Instance.Post<NoDataResponse>("/api/v1/auth/email/code", requestData);
|
|
|
|
LoadingUI.Hide();
|
|
|
|
ResponseCodeHandler.HandleResponse(response,
|
|
onSuccess: (data) =>
|
|
{
|
|
Debug.Log("验证码发送成功");
|
|
resendBtn.gameObject.SetActive(false);
|
|
countdownText.gameObject.SetActive(true);
|
|
StartCountdown(countdownSeconds);
|
|
},
|
|
onError: null
|
|
);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoadingUI.Hide();
|
|
Debug.LogError("发送验证码异常: " + ex.Message);
|
|
}
|
|
}
|
|
|
|
private void StartCountdown(int seconds)
|
|
{
|
|
if (countdownCoroutine != null)
|
|
{
|
|
StopCoroutine(countdownCoroutine);
|
|
}
|
|
countdownCoroutine = StartCoroutine(CountdownCoroutine(seconds));
|
|
}
|
|
|
|
private IEnumerator CountdownCoroutine(int seconds)
|
|
{
|
|
int remaining = seconds;
|
|
while (remaining > 0)
|
|
{
|
|
string tip = countdownTip.Replace("{0}", remaining.ToString());
|
|
if (countdownText != null)
|
|
countdownText.text = tip;
|
|
yield return new WaitForSeconds(1);
|
|
remaining--;
|
|
}
|
|
resendBtn.gameObject.SetActive(true);
|
|
countdownText.gameObject.SetActive(false);
|
|
countdownCoroutine = null;
|
|
}
|
|
public void OnBack()
|
|
{
|
|
UIManager.Instance.RegisterBackAction(onBackCallback);
|
|
Destroy(gameObject);
|
|
}
|
|
/// <summary>
|
|
/// 校验验证码
|
|
/// </summary>
|
|
public async void VerifyCode(string email, string code, Action onSuccess, Action<int, string> onError)
|
|
{
|
|
LoadingUI.Show();
|
|
|
|
var requestData = new VerifyCodeRequest
|
|
{
|
|
email = email,
|
|
code = code
|
|
};
|
|
try
|
|
{
|
|
var response = await NetworkCtrl.Instance.Post<NoDataResponse>("/api/v1/auth/email/verify", requestData);
|
|
|
|
LoadingUI.Hide();
|
|
|
|
ResponseCodeHandler.HandleResponse(response,
|
|
onSuccess: (data) =>
|
|
{
|
|
Debug.Log("验证码校验成功");
|
|
onSuccess?.Invoke();
|
|
},
|
|
onError: onError
|
|
);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LoadingUI.Hide();
|
|
Debug.LogError("校验验证码异常: " + ex.Message);
|
|
onError?.Invoke(-1, ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|