-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuserModel.py
More file actions
30 lines (24 loc) · 914 Bytes
/
userModel.py
File metadata and controls
30 lines (24 loc) · 914 Bytes
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
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import json
from settings import app
# binding the instance to a very specific Flask application
db = SQLAlchemy(app)
class User(db.Model):
__tablename__ = "users"
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(10), unique=True, nullable=False)
password = db.Column(db.String(80), nullable=False)
def __repr__(self):
return str({"user": self.username})
def match_user(username, password):
user = User.query.filter_by(username=username).filter_by(password=password).first()
if user is None:
return False
return True
def get_all_users():
return User.query.all()
def create_user(username, password):
new_user = User(username=username, password=password)
db.session.add(new_user)
db.session.commit()