implemented register and login function
This commit is contained in:
@@ -434,7 +434,7 @@ function love.errorhandler(msg)
|
|||||||
setFont(100)gc.print(":(",100,40,0,1.2)
|
setFont(100)gc.print(":(",100,40,0,1.2)
|
||||||
setFont(40)gc.printf(text.errorMsg,100,200,SCR.w0-100)
|
setFont(40)gc.printf(text.errorMsg,100,200,SCR.w0-100)
|
||||||
setFont(20)
|
setFont(20)
|
||||||
gc.print(SYSTEM.."-"..VERSION,100,660)
|
gc.print(SYSTEM.."-"..VERSION_NAME,100,660)
|
||||||
gc.print("scene:"..SCN.cur,400,660)
|
gc.print("scene:"..SCN.cur,400,660)
|
||||||
gc.printf(err[1],626,360,1260-626)
|
gc.printf(err[1],626,360,1260-626)
|
||||||
gc.print("TRACEBACK",626,426)
|
gc.print("TRACEBACK",626,426)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ local ins,rem=table.insert,table.remove
|
|||||||
|
|
||||||
local debugMesList={}
|
local debugMesList={}
|
||||||
local debugMesHistory={
|
local debugMesHistory={
|
||||||
"Version: "..VERSION,
|
"Version: "..VERSION_NAME,
|
||||||
os.date("Launched at %Y/%m/%d %H:%M"),
|
os.date("Launched at %Y/%m/%d %H:%M"),
|
||||||
}
|
}
|
||||||
local LOG={}
|
local LOG={}
|
||||||
|
|||||||
@@ -166,9 +166,10 @@ end
|
|||||||
do--httpRequest
|
do--httpRequest
|
||||||
client=LOADLIB("NETlib")
|
client=LOADLIB("NETlib")
|
||||||
httpRequest=
|
httpRequest=
|
||||||
client and function(tick,api,method,header,body)
|
client and function(tick,path,method,header,body)
|
||||||
local task,err=client.httpraw{
|
local task,err=client.httpraw{
|
||||||
url="http://47.103.200.40/"..api,
|
-- url="http://47.103.200.40/"..path,
|
||||||
|
url="http://127.0.0.1:10026"..path,
|
||||||
method=method or"GET",
|
method=method or"GET",
|
||||||
header=header,
|
header=header,
|
||||||
body=body,
|
body=body,
|
||||||
@@ -302,8 +303,7 @@ do--json
|
|||||||
end
|
end
|
||||||
|
|
||||||
function json.encode(val)
|
function json.encode(val)
|
||||||
local a,b=pcall(encode,val)
|
return pcall(encode,val)
|
||||||
if a then return b else return""end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
@@ -530,8 +530,7 @@ do--json
|
|||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
function json.decode(str)
|
function json.decode(str)
|
||||||
local a,b=pcall(decode,str)
|
return pcall(decode,str)
|
||||||
if a then return b else return""end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
5
conf.lua
5
conf.lua
@@ -1,4 +1,5 @@
|
|||||||
VERSION="Alpha V0.12.2"
|
VERSION_CODE=1202
|
||||||
|
VERSION_NAME="Alpha V0.12.2"
|
||||||
love.setDeprecationOutput(false)
|
love.setDeprecationOutput(false)
|
||||||
function love.conf(t)
|
function love.conf(t)
|
||||||
t.identity="Techmino"--Saving folder
|
t.identity="Techmino"--Saving folder
|
||||||
@@ -12,7 +13,7 @@ function love.conf(t)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local W=t.window
|
local W=t.window
|
||||||
W.title="Techmino "..VERSION
|
W.title="Techmino "..VERSION_NAME
|
||||||
W.icon="media/image/icon.png"
|
W.icon="media/image/icon.png"
|
||||||
W.width,W.height=1280,720
|
W.width,W.height=1280,720
|
||||||
W.minwidth,W.minheight=640,360
|
W.minwidth,W.minheight=640,360
|
||||||
|
|||||||
6
main.lua
6
main.lua
@@ -197,11 +197,11 @@ do
|
|||||||
if S.extraRate then
|
if S.extraRate then
|
||||||
S.finesseRate=5*(S.piece-S.extraRate)
|
S.finesseRate=5*(S.piece-S.extraRate)
|
||||||
end
|
end
|
||||||
if S.version~=VERSION then
|
if S.version~=VERSION_NAME then
|
||||||
S.version=VERSION
|
S.version=VERSION_NAME
|
||||||
newVersionLaunch=true
|
newVersionLaunch=true
|
||||||
|
|
||||||
if not VERSION:find("0.12")or VERSION:find("0.12.0")then
|
if not VERSION_NAME:find("0.12")or VERSION_NAME:find("0.12.0")then
|
||||||
local function delRecord(n)
|
local function delRecord(n)
|
||||||
if R[n]then
|
if R[n]then
|
||||||
R[n]=0
|
R[n]=0
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ SETTING={
|
|||||||
}
|
}
|
||||||
|
|
||||||
STAT={
|
STAT={
|
||||||
version=VERSION,
|
version=VERSION_NAME,
|
||||||
run=0,game=0,time=0,
|
run=0,game=0,time=0,
|
||||||
key=0,rotate=0,hold=0,
|
key=0,rotate=0,hold=0,
|
||||||
extraPiece=0,finesseRate=0,
|
extraPiece=0,finesseRate=0,
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ return{
|
|||||||
diffPassword="Passwords don't match",
|
diffPassword="Passwords don't match",
|
||||||
registerSuccessed="Successfully registered!",
|
registerSuccessed="Successfully registered!",
|
||||||
registerFailed="Registration failed",
|
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.",
|
errorMsg="An error has occurred and Techmino needs to restart.\nError info has been created, and you can send it to the author.",
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ return{
|
|||||||
diffPassword="Les mots de passe ne se correspondent pas",
|
diffPassword="Les mots de passe ne se correspondent pas",
|
||||||
registerSuccessed="Enregistré avec succès !",
|
registerSuccessed="Enregistré avec succès !",
|
||||||
registerFailed="Erreur d'enregistrement",
|
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.",
|
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.",
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ return{
|
|||||||
diffPassword="Las contraseñas no coinciden",
|
diffPassword="Las contraseñas no coinciden",
|
||||||
registerSuccessed="¡Registro exitoso!",
|
registerSuccessed="¡Registro exitoso!",
|
||||||
registerFailed="Registro fallido.",
|
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.",
|
errorMsg="Ha ocurrido un error y Techmino necesita reiniciarse.\nSe creó un registro de error, puedes enviarlo al autor.",
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ return{
|
|||||||
diffPassword="两次密码不一致",
|
diffPassword="两次密码不一致",
|
||||||
registerSuccessed="注册成功!",
|
registerSuccessed="注册成功!",
|
||||||
registerFailed="注册失败",
|
registerFailed="注册失败",
|
||||||
|
loginSuccessed="登录成功!",
|
||||||
|
loginFailed="登录失败",
|
||||||
|
|
||||||
errorMsg="Techmino遭受了雷击,需要重新启动.\n我们已收集了一些错误信息,你可以向作者进行反馈.",
|
errorMsg="Techmino遭受了雷击,需要重新启动.\n我们已收集了一些错误信息,你可以向作者进行反馈.",
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ function Tmr.load()
|
|||||||
LOADED=true
|
LOADED=true
|
||||||
SFX.play("welcome_sfx")
|
SFX.play("welcome_sfx")
|
||||||
VOC.play("welcome_voc")
|
VOC.play("welcome_voc")
|
||||||
httpRequest(TICK.httpREQ_launch,"api/game")
|
httpRequest(TICK.httpREQ_launch,"/tech/api/v1/app/info")
|
||||||
end
|
end
|
||||||
if S.tar then
|
if S.tar then
|
||||||
S.cur=S.cur+1
|
S.cur=S.cur+1
|
||||||
|
|||||||
@@ -7,15 +7,19 @@ function keyDown.login(key)
|
|||||||
elseif #password==0 then
|
elseif #password==0 then
|
||||||
LOG.print(text.noPassword)return
|
LOG.print(text.noPassword)return
|
||||||
end
|
end
|
||||||
local data=urlencode.encode{
|
local success,data=json.encode({
|
||||||
username=username,
|
username=username,
|
||||||
password=password,
|
password=password,
|
||||||
}
|
})
|
||||||
|
if not success then
|
||||||
|
LOG.print(text.jsonError,"warn")
|
||||||
|
return
|
||||||
|
end
|
||||||
httpRequest(
|
httpRequest(
|
||||||
TICK.httpREQ_register,
|
TICK.httpREQ_login,
|
||||||
"api/account/register",
|
"/tech/api/v1/users",
|
||||||
"POST",
|
"GET",
|
||||||
{["Content-Type"]="application/x-www-form-urlencoded"},
|
{["Content-Type"]="application/json"},
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
elseif key=="escape"then
|
elseif key=="escape"then
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ function Pnt.main()
|
|||||||
gc.draw(IMG.title_color,60,30,nil,1.3)
|
gc.draw(IMG.title_color,60,30,nil,1.3)
|
||||||
setFont(30)
|
setFont(30)
|
||||||
gc.print(SYSTEM,610,50)
|
gc.print(SYSTEM,610,50)
|
||||||
gc.print(VERSION,610,90)
|
gc.print(VERSION_NAME,610,90)
|
||||||
gc.print(sceneTemp.tip,50,660)
|
gc.print(sceneTemp.tip,50,660)
|
||||||
local L=text.modes[STAT.lastPlay]
|
local L=text.modes[STAT.lastPlay]
|
||||||
setFont(25)
|
setFont(25)
|
||||||
|
|||||||
@@ -13,16 +13,20 @@ function keyDown.register(key)
|
|||||||
elseif password~=password2 then
|
elseif password~=password2 then
|
||||||
LOG.print(text.diffPassword)return
|
LOG.print(text.diffPassword)return
|
||||||
end
|
end
|
||||||
local data=urlencode.encode{
|
local success,data=json.encode({
|
||||||
username=username,
|
username=username,
|
||||||
email=email,
|
email=email,
|
||||||
password=password,
|
password=password,
|
||||||
}
|
})
|
||||||
|
if not success then
|
||||||
|
LOG.print(text.jsonError,"warn")
|
||||||
|
return
|
||||||
|
end
|
||||||
httpRequest(
|
httpRequest(
|
||||||
TICK.httpREQ_register,
|
TICK.httpREQ_register,
|
||||||
"api/account/register",
|
"/tech/api/v1/users",
|
||||||
"POST",
|
"POST",
|
||||||
{["Content-Type"]="application/x-www-form-urlencoded"},
|
{["Content-Type"]="application/json"},
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
elseif key=="escape"then
|
elseif key=="escape"then
|
||||||
|
|||||||
@@ -87,26 +87,31 @@ function Tick.autoPause(data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function Tick.httpREQ_launch(data)
|
function Tick.httpREQ_launch(data)
|
||||||
local res,err=client.poll(data.task)
|
local response,request_error=client.poll(data.task)
|
||||||
if res then
|
if response then
|
||||||
if res.code==200 then
|
if response.code==200 then
|
||||||
err,res=json.decode(res.body)
|
local success,content=json.decode(response.body)
|
||||||
if res then
|
if success then
|
||||||
LOG.print(res.notice,360,COLOR.sky)
|
LOG.print(content.notice,360,COLOR.sky)
|
||||||
if VERSION==res.version then
|
if VERSION_CODE==content.version_code then
|
||||||
LOG.print(text.versionIsNew,360,COLOR.sky)
|
LOG.print(text.versionIsNew,360,COLOR.sky)
|
||||||
else
|
else
|
||||||
LOG.print(string.gsub(text.versionIsOld,"$1",res.version),"warn")
|
LOG.print(string.gsub(text.versionIsOld,"$1",content.version_name),"warn")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
LOG.print(text.jsonError..": "..err,"warn")
|
LOG.print(text.jsonError,"warn")
|
||||||
end
|
end
|
||||||
else
|
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
|
end
|
||||||
return true
|
return true
|
||||||
elseif err then
|
elseif request_error then
|
||||||
LOG.print(text.getNoticeFail..": "..err,"warn")
|
LOG.print(text.getNoticeFail..": "..request_error,"warn")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
data.time=data.time+1
|
data.time=data.time+1
|
||||||
@@ -116,25 +121,58 @@ function Tick.httpREQ_launch(data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
function Tick.httpREQ_register(data)
|
function Tick.httpREQ_register(data)
|
||||||
local res,err=client.poll(data.task)
|
local response,request_error=client.poll(data.task)
|
||||||
if res then
|
if response then
|
||||||
if res.code==200 then
|
if response.code==200 then
|
||||||
err,res=json.decode(res.body)
|
local success,content=json.decode(response.body)
|
||||||
if res then
|
if success then
|
||||||
if res.status then
|
LOG.print(text.registerSuccessed..": "..content.message)
|
||||||
LOG.print(text.registerSuccessed)
|
|
||||||
else
|
else
|
||||||
LOG.print(text.registerFailed..": "..res.msg)
|
LOG.print(text.jsonError,"warn")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
LOG.print(text.jsonError..": "..err,"warn")
|
local success,content=json.decode(response.body)
|
||||||
end
|
if success then
|
||||||
|
LOG.print(text.netErrorCode..response.code..": "..content.message,"warn")
|
||||||
else
|
else
|
||||||
LOG.print(text.netErrorCode..res.code,"warn")
|
LOG.print(text.netErrorCode..response.code,"warn")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
elseif err then
|
elseif request_error then
|
||||||
LOG.print(text.registerFailed..": "..err,"warn")
|
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
|
return true
|
||||||
end
|
end
|
||||||
data.time=data.time+1
|
data.time=data.time+1
|
||||||
|
|||||||
Reference in New Issue
Block a user