Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download 1.72 KB
Copy Edit Web IDE Raw Blame History
Mendalas authored 2019-06-12 18:24 . add api
from flask_sqlalchemy import SQLAlchemy
from api import app
from passlib.apps import custom_app_context as pwd_context
from itsdangerous import (TimedJSONWebSignatureSerializer
as Serializer, BadSignature, SignatureExpired)
db = SQLAlchemy(app)
class User(db.Model):
__tablename__ = 'users'
phone = db.Column(db.String(32), primary_key=True)
username = db.Column(db.String(128))
password_hash = db.Column(db.String(128))
position = db.Column(db.String(255))
eid = db.Column(db.String(255))
right = db.Column(db.Integer)
def hash_password(self, password):
self.password_hash = pwd_context.encrypt(password)
def verify_password(self, password):
return pwd_context.verify(password, self.password_hash)
def generate_auth_token(self, expiration=600):
s = Serializer(app.config['SECRET_KEY'], expires_in=expiration)
return s.dumps({'phone':})
def verify_auth_token(token):
s = Serializer(app.config['SECRET_KEY'])
data = s.loads(token)
except SignatureExpired:
return None # valid token, but expired
except BadSignature:
return None # invalid token
user = User.query.get(data['phone'])
return user
def to_json(self):
return {
"username": self.username,
"position": self.position,
"eid": self.eid,
"right": self.right
if __name__ == '__main__':
user = User(phone=123,username="admin")

Comment ( 0 )

Sign in for post a comment