yunque9/lua_probject/base_project/Game/View/Lobby/IDPasswordAlone.lua

142 lines
4.5 KiB
Lua
Raw Normal View History

2025-08-29 20:15:02 +08:00
local IDPasswordAlone = {}
local M = IDPasswordAlone
2025-08-30 20:29:56 +08:00
--黑体字提示
local Tips1 = { { "当前账号未设置密码,为了您的账号安全请设置密码", "若您为旧用户或者当前账号不属于你,点击左上角可以找回账号" }, { "请输入正确的账号和密码,若忘记请联系客服人员" } }
--红字提示
local Tips1 = { { "注:初始账号将强制要求设置密码" }, { "注:找回账号功能会删除现有账户,请勿随便使用" } }
2025-09-03 17:11:10 +08:00
function IDPasswordAlone.new(data,callback)
2025-08-29 20:15:02 +08:00
setmetatable(M, { __index = BaseWindow })
local self = setmetatable({}, { __index = M })
self.class = "IDPasswordAlone"
self._callback = callback
self._close_zone = false
self._close_destroy = true
2025-09-03 17:11:10 +08:00
self._data = data
2025-08-29 20:15:02 +08:00
local url = "ui://Lobby/win_id_password_alone"
self:init(url)
return self
end
function M:init(url)
BaseWindow.init(self, url)
2025-08-30 20:29:56 +08:00
local text_id = self._view:GetChild("tex_phone")
local tex_passwd = self._view:GetChild("tex_passwd")
text_id.text = DataManager.SelfUser.account_id
2025-08-29 20:15:02 +08:00
2025-08-30 20:29:56 +08:00
local ctr_retrieve = self._view:GetController('retrieve')
ctr_retrieve.onChanged:Set(function(context)
if ctr_retrieve.selectedIndex == 0 then
text_id.text = DataManager.SelfUser.account_id
tex_passwd.text = ""
else
text_id.text = ""
tex_passwd.text = ""
end
end)
2025-08-29 20:15:02 +08:00
local btn_ok = self._view:GetChild("btn_ok")
btn_ok.onClick:Set(function()
2025-08-30 20:29:56 +08:00
if ctr_retrieve.selectedIndex == 0 then
self:Bind()
else
self:Retrieve()
end
2025-08-29 20:15:02 +08:00
end)
2025-09-03 17:11:10 +08:00
if self._data and self._data.only_retrieve then
ctr_retrieve.selectedIndex = 1
self._view:GetChild("btn_retrieve").visible = false
self._view:GetChild("btn_close").visible = true
self._close_zone = true
end
2025-08-29 20:15:02 +08:00
end
function M:Destroy()
BaseWindow.Destroy(self)
end
--绑定
function M:Bind()
local tex_passwd = self._view:GetChild("tex_passwd")
local password = tex_passwd.text
if string.len(password) < 6 then
ViewUtil.ShowTips("请输入5位以上的密码")
return
end
local flg_xiaozimu = false
local flg_dazimu = false
local fla_shuzi = false
for i = 1, #password do
local oneChar = string.sub(password, i, i)
print("lingmeng Bind", oneChar, string.byte(oneChar))
if string.byte(oneChar) >= 65 and string.byte(oneChar) <= 90 then
flg_dazimu = true
elseif string.byte(oneChar) >= 97 and string.byte(oneChar) <= 122 then
flg_xiaozimu = true
elseif string.byte(oneChar) >= 48 and string.byte(oneChar) <= 57 then
fla_shuzi = true
end
end
if not (flg_xiaozimu or flg_dazimu) then
ViewUtil.ShowTips("密码必须包含字母")
return
end
2025-08-30 20:29:56 +08:00
local _data = {}
2025-08-29 20:15:02 +08:00
ViewUtil.ShowModalWait(self._root_view, "正在提交...")
local loddyctr = ControllerManager.GetController(LoddyController)
_data.password = password
_data.type = 3
loddyctr:UpdateUserInfo(_data, function(res)
ViewUtil.CloseModalWait()
if (res.ReturnCode == 0) then
DataManager.SelfUser.password = "123"
if self._callback then self._callback() end
else
ViewUtil.ErrorTip(res.ReturnCode, "提交失败")
end
self:Close()
end)
end
2025-08-30 20:29:56 +08:00
--找回账号
function M:Retrieve()
local tex_phone = self._view:GetChild("tex_phone")
local text_id = tex_phone.text
local tex_passwd = self._view:GetChild("tex_passwd")
local password = tex_passwd.text
local _data = {}
ViewUtil.ShowModalWait(self._root_view, "正在提交...")
local loddyctr = ControllerManager.GetController(LoddyController)
_data.password = password
_data.id = tonumber(text_id)
loddyctr:RetrievePassword(_data, function(res)
ViewUtil.CloseModalWait()
if res.ReturnCode == 0 then
PlayerPrefs.DeleteKey('session_id')
2025-08-30 21:23:22 +08:00
ViewUtil.CloseModalWait()
local _curren_msg = MsgWindow.new(self._root_view, "您的账号已经切换,请重新登录", MsgWindow.MsgMode.OnlyOk, nil, nil,
{ closeZone = true })
_curren_msg.onOk:Add(
function()
Application.Quit()
end
)
_curren_msg:Show()
2025-08-30 20:29:56 +08:00
else
ViewUtil.ErrorTip(res.ReturnCode, "找回账号失败,请联系客服人员")
end
end)
end
2025-08-29 20:15:02 +08:00
return M