158 lines
4.5 KiB
Lua
158 lines
4.5 KiB
Lua
|
|
local PasswordUpdateView = {}
|
||
|
|
|
||
|
|
local M = PasswordUpdateView
|
||
|
|
|
||
|
|
function PasswordUpdateView.new(type, callback)
|
||
|
|
setmetatable(M, { __index = BaseWindow })
|
||
|
|
local self = setmetatable({}, { __index = M })
|
||
|
|
self.class = "PasswordUpdateView"
|
||
|
|
self._callback = callback
|
||
|
|
self._close_destroy = true
|
||
|
|
-- self.codeType = type
|
||
|
|
self.codeType = 0
|
||
|
|
self:init("ui://Lobby/PasswordSet")
|
||
|
|
|
||
|
|
return self
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:init(url)
|
||
|
|
BaseWindow.init(self, url)
|
||
|
|
self.login_type = self._view:GetController("type")
|
||
|
|
self.login_type.selectedIndex = self.codeType
|
||
|
|
|
||
|
|
local btn_login = self._view:GetChild("btn_login")
|
||
|
|
btn_login.onClick:Add(handler(self, function()
|
||
|
|
self:Bind()
|
||
|
|
end))
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:Bind()
|
||
|
|
if self.codeType == 0 then
|
||
|
|
local passwd = self:CheckInputPasswd()
|
||
|
|
if not passwd then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
local loddyctr = ControllerManager.GetController(LoddyController)
|
||
|
|
local _data = {}
|
||
|
|
_data.password = passwd
|
||
|
|
_data.type = 3
|
||
|
|
ViewUtil.ShowModalWait2()
|
||
|
|
loddyctr:UpdateUserInfo(_data, function(res)
|
||
|
|
ViewUtil.CloseModalWait2()
|
||
|
|
if (res.ReturnCode == 0) then
|
||
|
|
DataManager.SelfUser.havaPsw = true
|
||
|
|
self.login_type.selectedIndex = 1
|
||
|
|
if self._callback then self._callback() end
|
||
|
|
else
|
||
|
|
ViewUtil.ErrorTip(res.ReturnCode, "提交失败")
|
||
|
|
end
|
||
|
|
self:Close()
|
||
|
|
end)
|
||
|
|
else
|
||
|
|
local myPwd = self:CheckInputPasswd2()
|
||
|
|
if not myPwd then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
local passwd = self:CheckInputPasswd()
|
||
|
|
if not passwd then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
local loddyctr = ControllerManager.GetController(LoddyController)
|
||
|
|
local _data = {}
|
||
|
|
_data.password = passwd
|
||
|
|
_data.type = 3
|
||
|
|
ViewUtil.ShowModalWait2()
|
||
|
|
loddyctr:UpdateUserInfo(_data, function(res)
|
||
|
|
ViewUtil.CloseModalWait2()
|
||
|
|
if (res.ReturnCode == 0) then
|
||
|
|
DataManager.SelfUser.havaPsw = true
|
||
|
|
self.login_type.selectedIndex = 1
|
||
|
|
if self._callback then self._callback() end
|
||
|
|
else
|
||
|
|
ViewUtil.ErrorTip(res.ReturnCode, "提交失败")
|
||
|
|
end
|
||
|
|
self:Close()
|
||
|
|
end)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:Destroy()
|
||
|
|
UpdateBeat:Remove(self.OnUpdate, self)
|
||
|
|
getmetatable(M).__index.Destroy(self)
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:CheckInputId()
|
||
|
|
local uid = self._view:GetChild("phone_input").text
|
||
|
|
if not (string.len(uid) >= 6) then
|
||
|
|
ViewUtil.ShowTips("请输入正确的用户ID")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
return uid
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:CheckInputPasswd2()
|
||
|
|
local tex_passwd = self._view:GetChild("my_input").text
|
||
|
|
if string.len(tex_passwd) < 8 then
|
||
|
|
ViewUtil.ShowTips("旧密码最少八位")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
return tex_passwd
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:CheckInputPasswd()
|
||
|
|
local tex_frist_passwd = self._view:GetChild("phone_input").text
|
||
|
|
local tex_confrim_passwd = self._view:GetChild("code_input").text
|
||
|
|
|
||
|
|
if string.len(tex_frist_passwd) < 8 then
|
||
|
|
ViewUtil.ShowTips("密码最少八位")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
local flg_xiaozimu = false
|
||
|
|
local flg_dazimu = false
|
||
|
|
local fla_shuzi = false
|
||
|
|
for i = 1, #tex_frist_passwd do
|
||
|
|
local oneChar = string.sub(tex_frist_passwd, 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) and fla_shuzi) then
|
||
|
|
ViewUtil.ShowTips("密码必须同时包含字母和数字")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
if tex_frist_passwd ~= tex_confrim_passwd then
|
||
|
|
ViewUtil.ShowTips("确认密码必须和输入密码保持一致")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
|
||
|
|
return tex_confrim_passwd
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:CheckInputPhone()
|
||
|
|
local phone = self._view:GetChild("phone_input").text
|
||
|
|
if not (string.len(phone) == 11) then
|
||
|
|
ViewUtil.ShowTips("请输入正确的电话号码")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
return phone
|
||
|
|
end
|
||
|
|
|
||
|
|
function M:CheckInputPhoneCode()
|
||
|
|
local code = self._view:GetChild("code_input").text
|
||
|
|
if string.len(code) ~= 6 then
|
||
|
|
ViewUtil.ShowTips("请输入正确的验证码")
|
||
|
|
return
|
||
|
|
end
|
||
|
|
return code
|
||
|
|
end
|
||
|
|
|
||
|
|
return M
|