46 lines
880 B
Python
46 lines
880 B
Python
from wtforms import Form, BooleanField, StringField, PasswordField, validators
|
|
from flask_login import UserMixin
|
|
|
|
from objects import glob
|
|
|
|
class LoginForm(Form):
|
|
email = StringField("Email", [
|
|
validators.DataRequired(),
|
|
validators.Length(min=6, max=64)
|
|
])
|
|
|
|
password = PasswordField("Password", [
|
|
validators.DataRequired(),
|
|
validators.Length(min=4)
|
|
])
|
|
|
|
class User(UserMixin):
|
|
id = -1
|
|
email = ""
|
|
password = ""
|
|
firstname = ""
|
|
surname = ""
|
|
def __init__(self, login):
|
|
self.fetch_from_db(login)
|
|
|
|
def fetch_from_db(self, login):
|
|
conn = glob.get_sql_connection()
|
|
cur = conn.cursor()
|
|
|
|
cur.execute("""
|
|
SELECT *
|
|
FROM Bruker
|
|
WHERE Epost = %s
|
|
AND Passord = %s
|
|
LIMIT 1;
|
|
""", login)
|
|
|
|
user = cur.fetchone()
|
|
|
|
cur.close()
|
|
|
|
if user is None:
|
|
raise Exception("Invalid login")
|
|
|
|
self.id, self.email, self.password, self.firstname, self.surname = user
|