-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodels.py
35 lines (28 loc) · 1.21 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from flask import Flask
from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from database import Base
from werkzeug.security import generate_password_hash, check_password_hash
from app import db
class User(db.Model):
__tablename__ = 'user'
id = db.Column(db.Integer, primary_key=True)
first_name = db.Column(db.String(length=50))
last_name = db.Column(db.String(length=50))
email = db.Column(db.String(length=120), unique=True)
password = db.Column(db.String(length=100))
hash = db.Column(db.String(length=100)) # used for remembering login device
def __init__(self, first_name, last_name, email, password):
self.first_name = first_name
self.last_name = last_name
self.email = email
self.password = generate_password_hash(password)
self.generate_hash()
def generate_hash(self):
self.hash = str(uuid.uuid1())
def __repr__(self):
return '<User: email {}>'.format(self.email)
def set_password(self, password):
self.password = generate_password_hash(password)
def check_password(self, password):
return check_password_hash(self.password, password)