oops, missed one file
This commit is contained in:
parent
426fad7b10
commit
838348a0fb
@ -1,33 +0,0 @@
|
||||
|
||||
from nanoid import generate
|
||||
|
||||
|
||||
class Model:
|
||||
def __init__(self, connection, cursor):
|
||||
self.connection = connection
|
||||
self.cursor = cursor
|
||||
|
||||
def login(self, email):
|
||||
self.cursor.execute("SELECT * FROM accounts WHERE email = %s", (email, ))
|
||||
if len(self.cursor.fetchall()) == 0:
|
||||
self.cursor.execute("INSERT INTO accounts (email) VALUES (%s)", (email, ))
|
||||
|
||||
self.cursor.execute("SELECT token FROM logintokens WHERE email = %s", (email, ))
|
||||
if len(self.cursor.fetchall()) > 2:
|
||||
return None
|
||||
|
||||
token = generate()
|
||||
self.cursor.execute("INSERT INTO logintokens (email, token) VALUES (%s, %s)", (email, token))
|
||||
self.connection.commit()
|
||||
|
||||
return token
|
||||
|
||||
def consumeToken(self, token):
|
||||
self.cursor.execute("SELECT email FROM logintokens WHERE token = %s", (token, ))
|
||||
rows = self.cursor.fetchall()
|
||||
if len(rows) > 0:
|
||||
email = rows[0][0]
|
||||
self.cursor.execute("DELETE FROM logintokens WHERE email = %s", (email, ))
|
||||
self.connection.commit()
|
||||
return email
|
||||
return None
|
Loading…
Reference in New Issue
Block a user