使用新的登录和鉴权API
This commit is contained in:
152
parts/net.lua
152
parts/net.lua
@@ -119,121 +119,7 @@ local function getMsg(request,timeout)
|
|||||||
end
|
end
|
||||||
end
|
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()
|
function NET.autoLogin()
|
||||||
if not TASK.lock('autoLogin') then return end
|
if not TASK.lock('autoLogin') then return end
|
||||||
TASK.new(function()
|
TASK.new(function()
|
||||||
@@ -248,19 +134,21 @@ function NET.autoLogin()
|
|||||||
if USER.aToken then
|
if USER.aToken then
|
||||||
local res=getMsg({
|
local res=getMsg({
|
||||||
pool='autoLogin',
|
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},
|
headers={["x-access-token"]=USER.aToken},
|
||||||
},6.26)
|
},6.26)
|
||||||
|
|
||||||
if res then
|
if res and math.floor(res.code/100)==2 then
|
||||||
if res.code==200 then
|
USER.uid=res.data.playerId
|
||||||
USER.uid=res.data
|
if res.data.accessToken then
|
||||||
saveUser()
|
USER.aToken=res.data.accessToken
|
||||||
NET.ws_connect()
|
|
||||||
SCN.go('net_menu')
|
|
||||||
WAIT.interrupt()
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
saveUser()
|
||||||
|
NET.ws_connect()
|
||||||
|
SCN.go('net_menu')
|
||||||
|
WAIT.interrupt()
|
||||||
|
return
|
||||||
else
|
else
|
||||||
WAIT.interrupt()
|
WAIT.interrupt()
|
||||||
return
|
return
|
||||||
@@ -275,7 +163,8 @@ function NET.getUserInfo(uid)
|
|||||||
TASK.new(function()
|
TASK.new(function()
|
||||||
local res=getMsg({
|
local res=getMsg({
|
||||||
pool='getInfo',
|
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)
|
},6.26)
|
||||||
|
|
||||||
if res and res.code==200 and type(res.data)=='table' then
|
if res and res.code==200 and type(res.data)=='table' then
|
||||||
@@ -287,7 +176,8 @@ function NET.getAvatar(uid)
|
|||||||
TASK.new(function()
|
TASK.new(function()
|
||||||
local res=getMsg({
|
local res=getMsg({
|
||||||
pool='getInfo',
|
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)
|
},6.26)
|
||||||
|
|
||||||
if res and res.code==200 and type(res.data)=='string' then
|
if res and res.code==200 and type(res.data)=='string' then
|
||||||
@@ -657,7 +547,7 @@ end
|
|||||||
|
|
||||||
function NET.ws_connect()
|
function NET.ws_connect()
|
||||||
if WS.status('game')=='dead' then
|
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.removeTask_code(NET.ws_update)
|
||||||
TASK.new(NET.ws_update)
|
TASK.new(NET.ws_update)
|
||||||
end
|
end
|
||||||
@@ -683,11 +573,15 @@ function NET.ws_update()
|
|||||||
local res=getMsg({
|
local res=getMsg({
|
||||||
pool='getUID',
|
pool='getUID',
|
||||||
path='/techmino/api/v1/auth/check',
|
path='/techmino/api/v1/auth/check',
|
||||||
headers={["x-access-token"]=USER.aToken},
|
headers={["x-access-token"]=USER.oToken},
|
||||||
},6.26)
|
},6.26)
|
||||||
|
|
||||||
if res and res.code==200 then
|
if res and math.floor(res.code/100)==2 then
|
||||||
USER.uid=res.data
|
USER.uid=res.data.playerId
|
||||||
|
if res.data.accessToken then
|
||||||
|
USER.oToken=res.data.accessToken
|
||||||
|
end
|
||||||
|
saveUser()
|
||||||
else
|
else
|
||||||
TEST.yieldUntilNextScene()
|
TEST.yieldUntilNextScene()
|
||||||
GAME.playing=false
|
GAME.playing=false
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ local function _submit()
|
|||||||
else
|
else
|
||||||
USER.aToken=tickets:sub(1,64)
|
USER.aToken=tickets:sub(1,64)
|
||||||
USER.oToken=tickets:sub(65)
|
USER.oToken=tickets:sub(65)
|
||||||
|
NET.autoLogin()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function _paste()
|
local function _paste()
|
||||||
|
|||||||
@@ -21,11 +21,10 @@ scene.widgetList={
|
|||||||
WIDGET.newButton{name='logout',x=880, y=40,w=180, h=60,color='dR',
|
WIDGET.newButton{name='logout',x=880, y=40,w=180, h=60,color='dR',
|
||||||
code=function()
|
code=function()
|
||||||
if tryBack() then
|
if tryBack() then
|
||||||
|
print('logout')
|
||||||
USER.__data.uid=false
|
USER.__data.uid=false
|
||||||
USER.__data.email=false
|
|
||||||
USER.__data.password=false
|
|
||||||
USER.__data.rToken=false
|
|
||||||
USER.__data.aToken=false
|
USER.__data.aToken=false
|
||||||
|
USER.__data.oToken=false
|
||||||
love.filesystem.remove('conf/user')
|
love.filesystem.remove('conf/user')
|
||||||
SCN.back()
|
SCN.back()
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user