it sends a magic link when you log in

This commit is contained in:
2020-05-09 22:59:22 -05:00
parent edb476ec41
commit 64bca1fd97
10 changed files with 137 additions and 28 deletions

View File

@ -1,10 +1,21 @@
from nanoid import generate
class Model:
def __init__(self, connection, cursor):
self.connection = connection
self.cursor = cursor
def emailExists(self, email):
self.cursor.execute("SELECT * FROM accounts WHERE email = %(email)s", {"email": email})
return len(self.cursor.fetchall()) > 0
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