Created
October 29, 2015 17:01
-
-
Save pedrovanzella/e67986ee6795f430042a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from microfinance import db | |
from passlib.hash import bcrypt | |
from marshmallow import Schema | |
from marshmallow import post_dump | |
class User(db.Model): | |
id = db.Column(db.Integer, primary_key=True) | |
username = db.Column(db.String(32), | |
index=True, unique=True, nullable=False) | |
password_hash = db.Column(db.String(128), nullable=False) | |
def hash_password(self, password): | |
self.password_hash = bcrypt.encrypt(password) | |
def verify_password(self, password): | |
return bcrypt.verify(password, self.password_hash) | |
class UserSchema(Schema): | |
class Meta: | |
additional = ('username', 'password_hash') | |
@post_dump | |
def wrap_if_many(self, data, many=False): | |
if many: | |
return {'users': data} | |
return data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment