-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserModel.py
32 lines (25 loc) · 906 Bytes
/
UserModel.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
from flask_sqlalchemy import SQLAlchemy
from settings import app
db = SQLAlchemy(app)
class User(db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), nullable=False, unique=True)
password = db.Column(db.String(80), nullable=False)
def __repr__(self):
return str({
'username': self.username,
'password': self.password
})
@staticmethod
def username_password_match(_username, _password):
user = User.query.filter_by(username=_username).filter_by(password=_password).first()
return user is not None
@staticmethod
def getAllUsers():
return User.query.all()
@staticmethod
def createUser(_username, _password):
new_user = User(username=_username, password=_password)
db.session.add(new_user)
db.session.commit()