Mixonomer/music/model/user.py

43 lines
1.2 KiB
Python
Raw Normal View History

2020-04-30 14:54:05 +01:00
from fireo.models import Model
from fireo.fields import TextField, BooleanField, DateTime, NumberField
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
from werkzeug.security import check_password_hash
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
class User(Model):
class Meta:
collection_name = 'spotify_users'
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
username = TextField(required=True)
password = TextField(required=True)
email = TextField()
type = TextField(default="user")
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
last_login = DateTime()
last_refreshed = DateTime()
locked = BooleanField(default=False, required=True)
validated = BooleanField(default=True, required=True)
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
spotify_linked = BooleanField(default=False, required=True)
access_token = TextField()
refresh_token = TextField()
token_expiry = NumberField()
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
lastfm_username = TextField()
2019-10-23 14:44:17 +01:00
def check_password(self, password):
return check_password_hash(self.password, password)
def to_dict(self):
2020-04-30 14:54:05 +01:00
to_return = super().to_dict()
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
# remove unnecessary and sensitive fields
to_return.pop('password', None)
to_return.pop('access_token', None)
to_return.pop('refresh_token', None)
to_return.pop('token_expiry', None)
to_return.pop('id', None)
to_return.pop('key', None)
2019-10-23 14:44:17 +01:00
2020-04-30 14:54:05 +01:00
return to_return