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(40)gc.printf(text.errorMsg,100,200,SCR.w0-100)
|
||||
setFont(20)
|
||||
gc.print(SYSTEM.."-"..VERSION,100,660)
|
||||
gc.print(SYSTEM.."-"..VERSION_NAME,100,660)
|
||||
gc.print("scene:"..SCN.cur,400,660)
|
||||
gc.printf(err[1],626,360,1260-626)
|
||||
gc.print("TRACEBACK",626,426)
|
||||
|
||||
@@ -4,7 +4,7 @@ local ins,rem=table.insert,table.remove
|
||||
|
||||
local debugMesList={}
|
||||
local debugMesHistory={
|
||||
"Version: "..VERSION,
|
||||
"Version: "..VERSION_NAME,
|
||||
os.date("Launched at %Y/%m/%d %H:%M"),
|
||||
}
|
||||
local LOG={}
|
||||
|
||||
@@ -166,9 +166,10 @@ end
|
||||
do--httpRequest
|
||||
client=LOADLIB("NETlib")
|
||||
httpRequest=
|
||||
client and function(tick,api,method,header,body)
|
||||
client and function(tick,path,method,header,body)
|
||||
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",
|
||||
header=header,
|
||||
body=body,
|
||||
@@ -302,8 +303,7 @@ do--json
|
||||
end
|
||||
|
||||
function json.encode(val)
|
||||
local a,b=pcall(encode,val)
|
||||
if a then return b else return""end
|
||||
return pcall(encode,val)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
@@ -530,8 +530,7 @@ do--json
|
||||
return res
|
||||
end
|
||||
function json.decode(str)
|
||||
local a,b=pcall(decode,str)
|
||||
if a then return b else return""end
|
||||
return pcall(decode,str)
|
||||
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)
|
||||
function love.conf(t)
|
||||
t.identity="Techmino"--Saving folder
|
||||
@@ -12,7 +13,7 @@ function love.conf(t)
|
||||
end
|
||||
|
||||
local W=t.window
|
||||
W.title="Techmino "..VERSION
|
||||
W.title="Techmino "..VERSION_NAME
|
||||
W.icon="media/image/icon.png"
|
||||
W.width,W.height=1280,720
|
||||
W.minwidth,W.minheight=640,360
|
||||
|
||||
6
main.lua
6
main.lua
@@ -197,11 +197,11 @@ do
|
||||
if S.extraRate then
|
||||
S.finesseRate=5*(S.piece-S.extraRate)
|
||||
end
|
||||
if S.version~=VERSION then
|
||||
S.version=VERSION
|
||||
if S.version~=VERSION_NAME then
|
||||
S.version=VERSION_NAME
|
||||
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)
|
||||
if R[n]then
|
||||
R[n]=0
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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.",
|
||||
|
||||
|
||||
@@ -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.",
|
||||
|
||||
|
||||
@@ -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.",
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ return{
|
||||
diffPassword="两次密码不一致",
|
||||
registerSuccessed="注册成功!",
|
||||
registerFailed="注册失败",
|
||||
loginSuccessed="登录成功!",
|
||||
loginFailed="登录失败",
|
||||
|
||||
errorMsg="Techmino遭受了雷击,需要重新启动.\n我们已收集了一些错误信息,你可以向作者进行反馈.",
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user