forked from won-hj/mon2tor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Models.py
28 lines (20 loc) · 1.14 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
from flask_sqlalchemy import SQLAlchemy
from werkzeug.security import generate_password_hash, check_password_hash
db = SQLAlchemy() #SQLAlchemy 인스턴스 생성
class User(db.Model): #데이터 모델(SQL table)을 나타내는 객체
__tablename__ = 'user_table' #테이블 이름
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(32), unique=True, nullable=False)
userid = db.Column(db.String(32), unique=True, nullable=False)
password = db.Column(db.String(128), nullable=False)
def __init__(self, userid, email, password): #User클래스 생성자
self.userid = userid
self.email = email
self.set_password(password)
def set_password(self, password): # 비밀번호를 해싱해서 저장
self.password = generate_password_hash(password)
def check_password(self, password): # return compare(해싱된 비밀번호,입력된 비밀번호)
return check_password_hash(self.password, password)
from werkzeug.security import check_password_hash
def check_password(self, password):
return check_password_hash(self.password, password)