From e44bae66d5ddb687841d22f5714557a5333e8e61 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Tue, 13 Apr 2021 01:26:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E9=82=AE=E7=AE=B1=E6=A0=BC=E5=BC=8F=E5=88=A4=E5=AE=9A?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/gametoolfunc.lua | 11 +++++++++++ parts/scenes/login.lua | 4 ++-- parts/scenes/register.lua | 13 +------------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/parts/gametoolfunc.lua b/parts/gametoolfunc.lua index c8108d37..44f3b301 100644 --- a/parts/gametoolfunc.lua +++ b/parts/gametoolfunc.lua @@ -500,6 +500,17 @@ function legalGameTime()--Check if today's playtime is legal end return true end +function legalEmail(e) + e=SPLITSTR(e,"@") + if #e~=2 then return false end + if e[1]:sub(-1)=="."or e[2]:sub(-1)=="."then return false end + local e1,e2=SPLITSTR(e[1],"."),SPLITSTR(e[2],".") + if #e1*#e2==0 then return false end + for _,v in next,e1 do if #v==0 then return false end end + for _,v in next,e2 do if #v==0 then return false end end + return true +end + function mergeStat(stat,delta)--Merge delta stat. to global stat. for k,v in next,delta do if type(v)=="table"then diff --git a/parts/scenes/login.lua b/parts/scenes/login.lua index c5ff15d8..6d2d0dd2 100644 --- a/parts/scenes/login.lua +++ b/parts/scenes/login.lua @@ -1,7 +1,7 @@ local function login() local email= WIDGET.active.email.value local password= WIDGET.active.password.value - if #email==0 or not email:match("^[a-zA-Z0-9_]+@[a-zA-Z0-9_-]+%.[a-zA-Z0-9_]+$")then + if not legalEmail(email)then LOG.print(text.wrongEmail)return elseif #password==0 then LOG.print(text.noPassword)return @@ -14,7 +14,7 @@ local scene={} scene.widgetList={ WIDGET.newText{name="title", x=80, y=50,font=70,align="L"}, WIDGET.newButton{name="register", x=1140, y=100,w=170,h=80,color="lY",code=function()SCN.swapTo("register","swipeR")end}, - WIDGET.newInputBox{name="email", x=380, y=200,w=500,h=60,regex="[0-9A-Za-z@._-]"}, + WIDGET.newInputBox{name="email", x=380, y=200,w=500,h=60}, WIDGET.newInputBox{name="password", x=380, y=300,w=626,h=60,secret=true,regex="[ -~]"}, WIDGET.newKey{name="login", x=1140, y=540,w=170,h=80,font=40,code=login}, WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80,font=40,code=backScene}, diff --git a/parts/scenes/register.lua b/parts/scenes/register.lua index 8be9bf1c..1a6f0007 100644 --- a/parts/scenes/register.lua +++ b/parts/scenes/register.lua @@ -1,16 +1,5 @@ local scene={} -local function legalEmail(e) - e=SPLITSTR(e,"@") - if #e~=2 then return false end - if e[1]:sub(-1)=="."or e[2]:sub(-1)=="."then return false end - local e1,e2=SPLITSTR(e[1],"."),SPLITSTR(e[2],".") - if #e1*#e2==0 then return false end - for _,v in next,e1 do if #v==0 then return false end end - for _,v in next,e2 do if #v==0 then return false end end - return true -end - local function register() local username= WIDGET.active.username.value local email= WIDGET.active.email.value @@ -32,7 +21,7 @@ scene.widgetList={ WIDGET.newText{name="title", x=80, y=50,font=70,align="L"}, WIDGET.newButton{name="login", x=1140, y=100,w=170,h=80,color="lY",code=function()SCN.swapTo("login","swipeL")end}, WIDGET.newInputBox{name="username", x=380, y=200,w=500,h=60,regex="[0-9A-Za-z_]"}, - WIDGET.newInputBox{name="email", x=380, y=300,w=626,h=60,regex="[0-9A-Za-z@._-]"}, + WIDGET.newInputBox{name="email", x=380, y=300,w=626,h=60}, WIDGET.newInputBox{name="password", x=380, y=400,w=626,h=60,secret=true,regex="[ -~]"}, WIDGET.newInputBox{name="password2",x=380, y=500,w=626,h=60,secret=true,regex="[ -~]"}, WIDGET.newKey{name="register", x=1140, y=540,w=170,h=80,font=40,code=register},