Advertisement
Guest User

Untitled

a guest
Apr 11th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. class User(db.Document, UserMixin):
  2. username = db.StringField(max_length=80)
  3. email = db.StringField(max_length=255, unique=True)
  4. password = db.StringField(max_length=255, required=True)
  5. active = db.BooleanField(default=True)
  6.  
  7. def __init__(self, *args, **kwargs):
  8. super(db.Document, self).__init__(self)
  9. try:
  10. self.username = kwargs['username']
  11. self.email = kwargs['email']
  12. self.password = kwargs['password']
  13. except:
  14. flash('Bad arguments for User')
  15.  
  16. @staticmethod
  17. def salt_password(password):
  18. return generate_password_hash(password)
  19.  
  20. @property
  21. def is_authenticated(self):
  22. return True
  23.  
  24. @property
  25. def is_active(self):
  26. return self.active
  27.  
  28. @property
  29. def is_anonymous(self):
  30. return False
  31.  
  32. def get_id(self):
  33. return unicode(self._id)
  34.  
  35. def __repr__(self):
  36. return '<User %r>' % (self.username)
  37.  
  38. def check_pwd(self, password):
  39. return check_password_hash(self.password, password)
  40.  
  41. class User(db.Document, UserMixin):
  42. _id = db.ObjectIdField(default=bson.ObjectId())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement