-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.py
37 lines (29 loc) · 871 Bytes
/
user.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
36
37
from flask_login import UserMixin
from db import get_db
class User(UserMixin):
def __init__(self, id_, name, email, profile_pic):
self.id = id_
self.name = name
self.email = email
self.profile_pic = profile_pic
@staticmethod
def get(user_id):
db = get_db()
user = db.execute(
'SELECT * FROM user WHERE id = ?', (user_id,)
).fetchone()
if not user:
return None
user = User(
id_=user[0], name=user[1], email=user[2], profile_pic=user[3]
)
return user
@staticmethod
def create(id_, name, email, profile_pic):
db = get_db()
db.execute(
'INSERT INTO user (id, name, email, profile_pic)'
'VALUES (?, ?, ?, ?)',
(id_, name, email, profile_pic)
)
db.commit()