From 5333221ff7b4197cf1aca20d74bb1cc04e686aab Mon Sep 17 00:00:00 2001 From: Jesusaves Date: Thu, 28 Jul 2022 20:37:55 -0300 Subject: "Mail" can now be blank, it'll then use MyUID. If a valid email is provided in a registration but MyUID is repeated, it'll take over the account instead. --- player.py | 14 +++++++++++++- sql.py | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/player.py b/player.py index d035a72..49d5a8a 100644 --- a/player.py +++ b/player.py @@ -816,9 +816,14 @@ def register(args, token): y=json.loads(args) tmp=y["email"] mail=str(tmp) + tmp=y["MyUID"] + leni=len(tmp) + MyUID=str(y["MyUID"]) # Check if email is valid with above regex if not re.search(regex,mail): - raise Exception("Not a valid email") + if leni != 32 or mail != "": + raise Exception("Not a valid email") + mail="_%s@spheres.tmw2.org" % (MyUID) except: return ERR_BAD @@ -832,6 +837,13 @@ def register(args, token): stdout("WARNING: Tried to register email \"%s\" (belongs to account %s)" % (mail, check)) return ERR_BAD + # If email is an UID mail, clobber it + check=sql.query_email("_%s@spheres.tmw2.org" % (MyUID)) + if (check != ""): + passwd=clobber_email(check, "_%s@spheres.tmw2.org" % (MyUID), mail) + stdout("INFO: Set a new email for \"%s\" (%s)" % (check, mail)) + return compress({"userid": userid, "password": passwd}) + stdout("Now registering account") # Register it data=sql.add_player(mail) diff --git a/sql.py b/sql.py index 21aa065..0f79033 100644 --- a/sql.py +++ b/sql.py @@ -247,6 +247,21 @@ def query_email(xmail): return c +def clobber_email(userid, oldmail, newmail): + w = db.cursor(dictionary=True) + w.execute("SELECT `userpw` FROM `login` WHERE `userid`='%s' AND `email`='%s'" % (userid, oldmail)) + r = w.fetchall() + c = "" + for it in r: + c+=str(it) + w.close() + w = db.cursor() + w.execute("UPDATE `login` SET `email` = '%s' WHERE `userid`='%s' AND `email`='%s'" % (newmail, userid, oldmail)) + w.close() + + return c + + def add_player(xmail): # TODO: Generate password using the whole alphabet. # The original string have 32 letters and we're using only 12 -- cgit v1.2.3-60-g2f50