diff options
| author | stilbruch <stilbruch@protonmail.com> | 2022-03-23 12:30:23 -0500 |
|---|---|---|
| committer | stilbruch <stilbruch@protonmail.com> | 2022-03-23 12:30:23 -0500 |
| commit | c57ebef076438c83a0e408227341398249566ff1 (patch) | |
| tree | d4e943e771a127d285baaee14867f48040f23c8d /app/tables/user.py | |
| parent | 43755d0b6d1f65fd65862454be81bd0f5d7ff7dd (diff) | |
| download | Strengthy-c57ebef076438c83a0e408227341398249566ff1.tar.xz Strengthy-c57ebef076438c83a0e408227341398249566ff1.zip | |
User registration and login now works
Diffstat (limited to 'app/tables/user.py')
| -rw-r--r-- | app/tables/user.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/tables/user.py b/app/tables/user.py new file mode 100644 index 0000000..d384fdb --- /dev/null +++ b/app/tables/user.py @@ -0,0 +1,25 @@ +from app import db, login_manager +from flask_login import UserMixin +from werkzeug.security import generate_password_hash, check_password_hash + +@login_manager.user_loader +def get_user(user_id): + return User.query.get(user_id) + +class User(db.Model, UserMixin): + __tablename__ = 'users' + id = db.Column(db.Integer, primary_key=True) + username = db.Column(db.String(80), unique=True, nullable=False) + password = db.Column(db.String(80)) + email = db.Column(db.String(120), unique=True, nullable=False) + + def __init__(self, username, password, email): + self.username = username + self.password = generate_password_hash(password) + self.email = email + + def __repr__(self): + return f'<User {self.username}>' + + def verify_password(self, pwd): + return check_password_hash(self.password, pwd) |
