capsul-flask/capsulflask/model.py

22 lines
546 B
Python

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, ))
token = generate()
self.cursor.execute("INSERT INTO logintokens (email, token) VALUES (%s, %s)", (email, token))
self.connection.commit()
return token