implemented register and login function

This commit is contained in:
Particle_G
2020-11-24 02:18:35 +08:00
committed by MrZ626
parent 9265101025
commit 8f2b62ccc0
15 changed files with 106 additions and 52 deletions

View File

@@ -282,7 +282,7 @@ SETTING={
}
STAT={
version=VERSION,
version=VERSION_NAME,
run=0,game=0,time=0,
key=0,rotate=0,hold=0,
extraPiece=0,finesseRate=0,

View File

@@ -85,6 +85,8 @@ return{
diffPassword="Passwords don't match",
registerSuccessed="Successfully registered!",
registerFailed="Registration failed",
loginSuccessed="Successfully logged in!",
loginFailed="Login failed",
errorMsg="An error has occurred and Techmino needs to restart.\nError info has been created, and you can send it to the author.",

View File

@@ -88,6 +88,8 @@ return{
diffPassword="Les mots de passe ne se correspondent pas",
registerSuccessed="Enregistré avec succès !",
registerFailed="Erreur d'enregistrement",
loginSuccessed="Successfully logged in!", -- TODO: Need translation
loginFailed="Login failed", -- TODO: Need translation
errorMsg="Une erreur est survenue et Techmino doit redémarrer.\nDes informations concernant l'erreur ont été créées, et vous pouvez les envoyer au créateur.",

View File

@@ -88,6 +88,8 @@ return{
diffPassword="Las contraseñas no coinciden",
registerSuccessed="¡Registro exitoso!",
registerFailed="Registro fallido.",
loginSuccessed="Successfully logged in!", -- TODO: Need translation
loginFailed="Login failed", -- TODO: Need translation
errorMsg="Ha ocurrido un error y Techmino necesita reiniciarse.\nSe creó un registro de error, puedes enviarlo al autor.",

View File

@@ -86,6 +86,8 @@ return{
diffPassword="两次密码不一致",
registerSuccessed="注册成功!",
registerFailed="注册失败",
loginSuccessed="登录成功!",
loginFailed="登录失败",
errorMsg="Techmino遭受了雷击,需要重新启动.\n我们已收集了一些错误信息,你可以向作者进行反馈.",

View File

@@ -116,7 +116,7 @@ function Tmr.load()
LOADED=true
SFX.play("welcome_sfx")
VOC.play("welcome_voc")
httpRequest(TICK.httpREQ_launch,"api/game")
httpRequest(TICK.httpREQ_launch,"/tech/api/v1/app/info")
end
if S.tar then
S.cur=S.cur+1

View File

@@ -7,15 +7,19 @@ function keyDown.login(key)
elseif #password==0 then
LOG.print(text.noPassword)return
end
local data=urlencode.encode{
local success,data=json.encode({
username=username,
password=password,
}
})
if not success then
LOG.print(text.jsonError,"warn")
return
end
httpRequest(
TICK.httpREQ_register,
"api/account/register",
"POST",
{["Content-Type"]="application/x-www-form-urlencoded"},
TICK.httpREQ_login,
"/tech/api/v1/users",
"GET",
{["Content-Type"]="application/json"},
data
)
elseif key=="escape"then

View File

@@ -24,7 +24,7 @@ function Pnt.main()
gc.draw(IMG.title_color,60,30,nil,1.3)
setFont(30)
gc.print(SYSTEM,610,50)
gc.print(VERSION,610,90)
gc.print(VERSION_NAME,610,90)
gc.print(sceneTemp.tip,50,660)
local L=text.modes[STAT.lastPlay]
setFont(25)

View File

@@ -13,16 +13,20 @@ function keyDown.register(key)
elseif password~=password2 then
LOG.print(text.diffPassword)return
end
local data=urlencode.encode{
local success,data=json.encode({
username=username,
email=email,
password=password,
}
})
if not success then
LOG.print(text.jsonError,"warn")
return
end
httpRequest(
TICK.httpREQ_register,
"api/account/register",
"/tech/api/v1/users",
"POST",
{["Content-Type"]="application/x-www-form-urlencoded"},
{["Content-Type"]="application/json"},
data
)
elseif key=="escape"then

View File

@@ -87,26 +87,31 @@ function Tick.autoPause(data)
end
end
function Tick.httpREQ_launch(data)
local res,err=client.poll(data.task)
if res then
if res.code==200 then
err,res=json.decode(res.body)
if res then
LOG.print(res.notice,360,COLOR.sky)
if VERSION==res.version then
local response,request_error=client.poll(data.task)
if response then
if response.code==200 then
local success,content=json.decode(response.body)
if success then
LOG.print(content.notice,360,COLOR.sky)
if VERSION_CODE==content.version_code then
LOG.print(text.versionIsNew,360,COLOR.sky)
else
LOG.print(string.gsub(text.versionIsOld,"$1",res.version),"warn")
LOG.print(string.gsub(text.versionIsOld,"$1",content.version_name),"warn")
end
else
LOG.print(text.jsonError..": "..err,"warn")
LOG.print(text.jsonError,"warn")
end
else
LOG.print(text.netErrorCode..res.code,"warn")
local success,content=json.decode(response.body)
if success then
LOG.print(text.netErrorCode..response.code..": "..content.message,"warn")
else
LOG.print(text.netErrorCode..response.code,"warn")
end
end
return true
elseif err then
LOG.print(text.getNoticeFail..": "..err,"warn")
elseif request_error then
LOG.print(text.getNoticeFail..": "..request_error,"warn")
return true
end
data.time=data.time+1
@@ -116,25 +121,58 @@ function Tick.httpREQ_launch(data)
end
end
function Tick.httpREQ_register(data)
local res,err=client.poll(data.task)
if res then
if res.code==200 then
err,res=json.decode(res.body)
if res then
if res.status then
LOG.print(text.registerSuccessed)
else
LOG.print(text.registerFailed..": "..res.msg)
end
local response,request_error=client.poll(data.task)
if response then
if response.code==200 then
local success,content=json.decode(response.body)
if success then
LOG.print(text.registerSuccessed..": "..content.message)
else
LOG.print(text.jsonError..": "..err,"warn")
LOG.print(text.jsonError,"warn")
end
else
LOG.print(text.netErrorCode..res.code,"warn")
local success,content=json.decode(response.body)
if success then
LOG.print(text.netErrorCode..response.code..": "..content.message,"warn")
else
LOG.print(text.netErrorCode..response.code,"warn")
end
end
return true
elseif err then
LOG.print(text.registerFailed..": "..err,"warn")
elseif request_error then
LOG.print(text.registerFailed..": "..request_error,"warn")
return true
end
data.time=data.time+1
if data.time==360 then
LOG.print(text.httpTimeout,"message")
return true
end
end
function Tick.httpREQ_login(data)
local response,request_error=client.poll(data.task)
if response then
if response.code==200 then
local success,content=json.decode(response.body)
if success then
-- LOG.print(text.registerSuccessed..": "..content.message)
-- TODO: display a login success message
-- TODO: save {content.token} to storage and a global variable
-- TODO: save {content.user_id} to a global variable
else
LOG.print(text.jsonError,"warn")
end
else
local success,content=json.decode(response.body)
if success then
LOG.print(text.netErrorCode..response.code..": "..content.message,"warn")
else
LOG.print(text.netErrorCode..response.code,"warn")
end
end
return true
elseif request_error then
LOG.print(text.registerFailed..": "..request_error,"warn")
return true
end
data.time=data.time+1