账号绑定

This commit is contained in:
chenxi 2023-05-31 22:23:04 +08:00
parent 4a1fc3e0ab
commit 35a6bc5fa7
6 changed files with 106 additions and 24 deletions

View File

@ -788,4 +788,20 @@ function BIReport:postAccountDelete(loginType)
self:report(EVENT_NAME_ACCOUNT_OPT, args) self:report(EVENT_NAME_ACCOUNT_OPT, args)
end end
function BIReport:postAccountBindClick(loginType)
local args = {
login_type = loginType,
event_type = BIReport.ACCOUNT_OPT_TYPE.BIND_CLICK,
}
self:report(EVENT_NAME_ACCOUNT_OPT, args)
end
function BIReport:postAccountBindFinish(loginType)
local args = {
login_type = loginType,
event_type = BIReport.ACCOUNT_OPT_TYPE.BIND_FINISH,
}
self:report(EVENT_NAME_ACCOUNT_OPT, args)
end
return BIReport return BIReport

View File

@ -33,6 +33,7 @@ EventManager.CUSTOM_EVENT = {
GO_CHAPTER = "GO_CHAPTER", -- 跳转主线章节 GO_CHAPTER = "GO_CHAPTER", -- 跳转主线章节
CLOSE_BOX_HERO_UI = "CLOSE_BOX_HERO_UI", CLOSE_BOX_HERO_UI = "CLOSE_BOX_HERO_UI",
CLOSE_BOX_OPEN_UI = "CLOSE_BOX_OPEN_UI", CLOSE_BOX_OPEN_UI = "CLOSE_BOX_OPEN_UI",
BIND_ACCOUNT_SUCCESS = "BIND_ACCOUNT_SUCCESS",
-- BORAD_TOUCH_BEGIN = "BORAD_TOUCH_BEGIN", -- BORAD_TOUCH_BEGIN = "BORAD_TOUCH_BEGIN",
-- BORAD_TOUCH_OVER = "BORAD_TOUCH_OVER" -- BORAD_TOUCH_OVER = "BORAD_TOUCH_OVER"
} }

View File

@ -370,7 +370,6 @@ function SDKManager:login(callback, loginType)
Logger.log("三方当前正在登陆中") Logger.log("三方当前正在登陆中")
return return
end end
self.isLogining = true self.isLogining = true
self:_login(function(code, msg) self:_login(function(code, msg)
if code == SDKManager.BF_LOGIN_RESULT.Success then if code == SDKManager.BF_LOGIN_RESULT.Success then
@ -388,7 +387,6 @@ function SDKManager:login(callback, loginType)
self.isLogining = false self.isLogining = false
return return
end end
local userId = loginResult.UserId local userId = loginResult.UserId
local token = loginResult.Token local token = loginResult.Token
local params = {} local params = {}
@ -430,12 +428,9 @@ function SDKManager:logout(callback, loginType)
Logger.log("当前正在登出中") Logger.log("当前正在登出中")
return return
end end
self.isLogouting = true self.isLogouting = true
self:_logout(function(code, msg) self:_logout(function(code, msg)
if (code == SDKManager.BF_LOGIN_RESULT.Success) then if code == SDKManager.BF_LOGIN_RESULT.Success then
if callback then if callback then
callback() callback()
end end
@ -443,9 +438,7 @@ function SDKManager:logout(callback, loginType)
if msg and msg ~= "" then if msg and msg ~= "" then
local jData = json.decode(msg) local jData = json.decode(msg)
if jData then if jData then
local type = jData.loginType Logger.logError("登出失败 result:%s type:%s msg:%s", code, jData.loginType, jData.msg)
local msg = jData.msg
Logger.logError("登出失败 result:%s type:%s msg:%s", code, type, msg)
else else
Logger.logError("登出失败 result:%s", code) Logger.logError("登出失败 result:%s", code)
end end

View File

@ -11,6 +11,17 @@ function AccountManager:showDeleteUI()
return UIManager:showUI("app/ui/game_setting/account_delete_ui") return UIManager:showUI("app/ui/game_setting/account_delete_ui")
end end
function AccountManager:getIsBinded()
local accountInfo = LocalData:getAccountInfo()
if accountInfo.google_id and accountInfo.google_id ~= "" then
return true
end
if accountInfo.apple_id and accountInfo.apple_id ~= "" then
return true
end
return false
end
function AccountManager:deleteAccount() function AccountManager:deleteAccount()
self:sendMessage(ProtoMsgType.FromMsgEnum.DeleteReq, {}, {}, self.onDeleteAccount, BIReport.ITEM_GET_TYPE.NONE) self:sendMessage(ProtoMsgType.FromMsgEnum.DeleteReq, {}, {}, self.onDeleteAccount, BIReport.ITEM_GET_TYPE.NONE)
end end
@ -25,4 +36,50 @@ function AccountManager:onDeleteAccount(result)
end end
end end
function AccountManager:bindAccount()
local loginType = SDKManager.BF_LOGIN_TYPE.GOOGLE
if Platform:isIosPlatform() then
loginType = SDKManager.BF_LOGIN_TYPE.APPLE
end
BIReport:postAccountBindClick(loginType)
SDKManager:login(function(params)
if not params.token then
return
end
local args = {
type = SDKManager.LOGIN_TYPE[loginType],
id = params.id,
token = params.token
}
self:sendMessage(ProtoMsgType.FromMsgEnum.BindReq, args, {}, self.onBindAccount, BIReport.ITEM_GET_TYPE.NONE)
end, loginType)
end
function AccountManager:onBindAccount(result)
if result.err_code == GConst.ERROR_STR.SUCCESS then
local accountInfo = LocalData:getAccountInfo()
local loginType = SDKManager.BF_LOGIN_TYPE.GOOGLE
if Platform:isIosPlatform() then
loginType = SDKManager.BF_LOGIN_TYPE.APPLE
accountInfo.apple_id = result.reqData.id
else
accountInfo.googld_id = result.reqData.id
end
LocalData:setLastLoginInfo(loginType, result.reqData.id, result.reqData.token)
LocalData:setAccountInfo(accountInfo)
LocalData:save()
BIReport:postAccountBindFinish(loginType)
GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.BIND_ACCOUNT_SUCCESS))
EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.BIND_ACCOUNT_SUCCESS)
else -- 一些失败的提示
end
end
function AccountManager:changeAccount()
end
return AccountManager return AccountManager

View File

@ -18,7 +18,9 @@ function GameSettingUI:onLoadRootComplete()
self.uiMap = self.root:genAllChildren() self.uiMap = self.root:genAllChildren()
self:_display() self:_display()
self:_addListeners() self:_addListeners()
self:_bind() self:addEventListener(EventManager.CUSTOM_EVENT.BIND_ACCOUNT_SUCCESS, function()
self:refreshAccountInfo()
end)
end end
function GameSettingUI:onPressBackspace() function GameSettingUI:onPressBackspace()
@ -46,16 +48,27 @@ end
function GameSettingUI:initLoginBtn() function GameSettingUI:initLoginBtn()
self.uiMap["game_setting_ui.bg.google_sign_btn"]:addClickListener(function() self.uiMap["game_setting_ui.bg.google_sign_btn"]:addClickListener(function()
if ModuleManager.AccountManager:getIsBinded() then
end) GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.ACCOUNT_ALREADY_BINDED_DESC))
if DataManager.PlayerData:getIsBinded() then return
self.uiMap["game_setting_ui.bg.google_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACCOUNT_ALREADY_BINDED_DESC))
else
self.uiMap["game_setting_ui.bg.google_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.BIND_ACCOUNT_DESC))
end end
ModuleManager.AccountManager:bindAccount()
end)
self.uiMap["game_setting_ui.bg.google_switch_btn"]:addClickListener(function() self.uiMap["game_setting_ui.bg.google_switch_btn"]:addClickListener(function()
if ModuleManager.AccountManager:getIsBinded() then
ModuleManager.AccountManager:changeAccount()
else
local params = {
content = I18N:getGlobalText(I18N.GlobalConst.CHANGE_ACCOUNT_TIPS_DESC),
boxType = GConst.MESSAGE_BOX_TYPE.MB_OK_CANCEL,
okText = I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_OK),
okFunc = function()
ModuleManager.AccountManager:changeAccount()
end
}
GFunc.showMessageBox(params)
end
end) end)
self.uiMap["game_setting_ui.bg.google_switch_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.CHANGE_ACCOUNT_DESC)) self.uiMap["game_setting_ui.bg.google_switch_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.CHANGE_ACCOUNT_DESC))
@ -64,6 +77,7 @@ function GameSettingUI:initLoginBtn()
deleteTx:addClickListener(function() deleteTx:addClickListener(function()
ModuleManager.AccountManager:showDeleteUI() ModuleManager.AccountManager:showDeleteUI()
end) end)
self:refreshAccountInfo()
end end
function GameSettingUI:_addListeners() function GameSettingUI:_addListeners()
@ -117,9 +131,6 @@ function GameSettingUI:_addListeners()
end) end)
end end
function GameSettingUI:_bind()
end
function GameSettingUI:refreshMusic() function GameSettingUI:refreshMusic()
local offIcon = self.uiMap["game_setting_ui.bg.music_bg.off"] local offIcon = self.uiMap["game_setting_ui.bg.music_bg.off"]
local onIcon = self.uiMap["game_setting_ui.bg.music_bg.on"] local onIcon = self.uiMap["game_setting_ui.bg.music_bg.on"]
@ -138,4 +149,12 @@ function GameSettingUI:refreshVoice()
onIcon:setVisible(status == true) onIcon:setVisible(status == true)
end end
function GameSettingUI:refreshAccountInfo()
if ModuleManager.AccountManager:getIsBinded() then
self.uiMap["game_setting_ui.bg.google_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.ACCOUNT_ALREADY_BINDED_DESC))
else
self.uiMap["game_setting_ui.bg.google_sign_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.BIND_ACCOUNT_DESC))
end
end
return GameSettingUI return GameSettingUI

View File

@ -121,10 +121,6 @@ function PlayerData:getAcountId()
return self:getAccountInfo().id or GConst.EMPTY_STRING return self:getAccountInfo().id or GConst.EMPTY_STRING
end end
function PlayerData:getIsBinded()
return false
end
function PlayerData:addVitGemBuyCount() function PlayerData:addVitGemBuyCount()
self.data.vitGemCount = self.data.vitGemCount + 1 self.data.vitGemCount = self.data.vitGemCount + 1
end end