From 8aac152ee628ed037a8876a3f5fd2ae8e15d0b14 Mon Sep 17 00:00:00 2001 From: ParticleG Date: Thu, 12 Jan 2023 18:07:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=96=B0=E7=9A=84=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=92=8C=E9=89=B4=E6=9D=83API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/net.lua | 152 ++++++-------------------------------- parts/scenes/login.lua | 1 + parts/scenes/net_menu.lua | 5 +- 3 files changed, 26 insertions(+), 132 deletions(-) diff --git a/parts/net.lua b/parts/net.lua index d5d29c4c..05e4aa46 100644 --- a/parts/net.lua +++ b/parts/net.lua @@ -119,121 +119,7 @@ local function getMsg(request,timeout) end end end -function NET.getCode(email) - if not TASK.lock('getCode') then return end - TASK.new(function() - WAIT{ - quit=function() - TASK.unlock('getCode') - HTTP.deletePool('getCode') - end, - timeout=12.6, - } - local res=getMsg({ - pool='getCode', - path='/techmino/api/v1/auth/verify/email', - body={email=email}, - },12.6) - - if res and res.code==200 then - MES.new('info',text.checkEmail,5) - end - - WAIT.interrupt() - end) -end -function NET.codeLogin(email,code) - if not TASK.lock('codeLogin') then return end - TASK.new(function() - WAIT{ - quit=function() - TASK.unlock('codeLogin') - HTTP.deletePool('codeLogin') - end, - timeout=6.26, - } - - local res=getMsg({ - pool='codeLogin', - path='/techmino/api/v1/auth/login/email', - body={ - email=email, - code=code, - }, - },6.26) - - if res then - if res.code==200 then - USER.rToken=res.data.refreshToken - USER.aToken=res.data.accessToken - saveUser() - NET.ws_connect() - SCN.swapTo('net_menu') - elseif res.code==201 then - USER.rToken=res.data.refreshToken - USER.aToken=res.data.accessToken - saveUser() - SCN.pop()SCN.push('net_menu') - SCN.go('reset_password',nil,code) - end - end - - WAIT.interrupt() - end) -end -function NET.setPW(code,pw) - if not TASK.lock('setPW') then return end - TASK.new(function() - WAIT{ - quit=function() - TASK.unlock('setPW') - HTTP.deletePool('setPW') - end, - timeout=6.26, - } - - local salt do - local res=getMsg({ - pool='pwLogin', - path='/techmino/api/v1/auth/seed/email', - body={ - email=USER.email, - }, - },6.26) - - if res and res.code==200 then - salt=res.data - else - WAIT.interrupt() - return - end - end - - pw=HASH.pbkdf2(HASH.sha3_256,pw,salt,260) - - local res=getMsg({ - pool='setPW', - method='PUT', - path='/techmino/api/v1/auth/reset/email', - body={ - email=USER.email, - code=code, - newPassword=pw, - }, - },6.26) - - if res then - if res.code==200 then - USER.password=pw - saveUser() - SCN.back() - end - end - - WAIT.interrupt() - end) -end function NET.autoLogin() if not TASK.lock('autoLogin') then return end TASK.new(function() @@ -248,19 +134,21 @@ function NET.autoLogin() if USER.aToken then local res=getMsg({ pool='autoLogin', - path='/techmino/api/v1/auth/check', + url='cafuuchino1.3322.org:8081', + path='/studio26f/api/v1/auth/check', headers={["x-access-token"]=USER.aToken}, },6.26) - if res then - if res.code==200 then - USER.uid=res.data - saveUser() - NET.ws_connect() - SCN.go('net_menu') - WAIT.interrupt() - return + if res and math.floor(res.code/100)==2 then + USER.uid=res.data.playerId + if res.data.accessToken then + USER.aToken=res.data.accessToken end + saveUser() + NET.ws_connect() + SCN.go('net_menu') + WAIT.interrupt() + return else WAIT.interrupt() return @@ -275,7 +163,8 @@ function NET.getUserInfo(uid) TASK.new(function() local res=getMsg({ pool='getInfo', - path='/techmino/api/v1/player/info?playerId='..uid, + url='cafuuchino1.3322.org:8081', + path='/studio26f/api/v1/player/info?playerId='..uid, },6.26) if res and res.code==200 and type(res.data)=='table' then @@ -287,7 +176,8 @@ function NET.getAvatar(uid) TASK.new(function() local res=getMsg({ pool='getInfo', - path='/techmino/api/v1/player/avatar?playerId='..uid, + url='cafuuchino1.3322.org:8081', + path='/studio26f/api/v1/player/avatar?playerId='..uid, },6.26) if res and res.code==200 and type(res.data)=='string' then @@ -657,7 +547,7 @@ end function NET.ws_connect() if WS.status('game')=='dead' then - WS.connect('game','',{['x-access-token']=USER.aToken},6) + WS.connect('game','',{['x-access-token']=USER.oToken},6) TASK.removeTask_code(NET.ws_update) TASK.new(NET.ws_update) end @@ -683,11 +573,15 @@ function NET.ws_update() local res=getMsg({ pool='getUID', path='/techmino/api/v1/auth/check', - headers={["x-access-token"]=USER.aToken}, + headers={["x-access-token"]=USER.oToken}, },6.26) - if res and res.code==200 then - USER.uid=res.data + if res and math.floor(res.code/100)==2 then + USER.uid=res.data.playerId + if res.data.accessToken then + USER.oToken=res.data.accessToken + end + saveUser() else TEST.yieldUntilNextScene() GAME.playing=false diff --git a/parts/scenes/login.lua b/parts/scenes/login.lua index ce8e8cb6..5005ce87 100644 --- a/parts/scenes/login.lua +++ b/parts/scenes/login.lua @@ -10,6 +10,7 @@ local function _submit() else USER.aToken=tickets:sub(1,64) USER.oToken=tickets:sub(65) + NET.autoLogin() end end local function _paste() diff --git a/parts/scenes/net_menu.lua b/parts/scenes/net_menu.lua index 54937f1f..ce29d6c3 100644 --- a/parts/scenes/net_menu.lua +++ b/parts/scenes/net_menu.lua @@ -21,11 +21,10 @@ scene.widgetList={ WIDGET.newButton{name='logout',x=880, y=40,w=180, h=60,color='dR', code=function() if tryBack() then + print('logout') USER.__data.uid=false - USER.__data.email=false - USER.__data.password=false - USER.__data.rToken=false USER.__data.aToken=false + USER.__data.oToken=false love.filesystem.remove('conf/user') SCN.back() end