Advertisement
Guest User

Untitled

a guest
Feb 4th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. class User(UserMixin, db.Model):
  2. """
  3. Create an User table
  4. """
  5.  
  6. __tablename__ = 'users'
  7.  
  8. id = db.Column(db.Integer, primary_key=True)
  9. email = db.Column(db.String(), index=True, unique=True)
  10. username = db.Column(db.String(), index=True, unique=True)
  11. first_name = db.Column(db.String(), index=True)
  12. last_name = db.Column(db.String(), index=True)
  13. password_hash = db.Column(db.String())
  14.  
  15. @property
  16. def password(self):
  17. """
  18. Prevent pasword from being accessed
  19. """
  20. raise AttributeError('password is not a readable attribute.')
  21.  
  22. @password.setter
  23. def password(self, password):
  24. """
  25. Set password to a hashed password
  26. """
  27. self.password_hash = generate_password_hash(password)
  28.  
  29. def verify_password(self, password):
  30. """
  31. Check if hashed password matches actual password
  32. """
  33. return check_password_hash(self.password_hash, password)
  34.  
  35. def __repr__(self):
  36. return '<User: {}>'.format(self.username)
  37.  
  38.  
  39. class Account(db.Model):
  40. """
  41. Create a Service Account table
  42. """
  43.  
  44. __tablename__ = "accounts"
  45.  
  46. id = db.Column(db.Integer, primary_key=True)
  47. service = db.Column(db.String(), index=True)
  48. account_login = db.Column(db.String(), index=True, unique=True)
  49. account_password = db.Column(db.String())
  50. owner_id = db.Column(db.Integer, index=True)
  51.  
  52.  
  53. @property
  54. def password(self):
  55. """
  56. Prevent pasword from being accessed
  57. """
  58. raise AttributeError('password is not a readable attribute.')
  59.  
  60. @password.setter
  61. def password(self, password):
  62. """
  63. Set password to a hashed password
  64. """
  65. self.account_password = generate_password_hash(password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement