albums-social/app/models.py

70 lines
2.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Albums.social
# Copyright (C) 2018 Gergely Polonkai
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from datetime import datetime
from flask_security import UserMixin
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy_utils.types.choice import ChoiceType
db = SQLAlchemy()
class User(db.Model, UserMixin):
"""Model for the User accounts
"""
__tablename__ = 'users'
#: Email address is visible only to site administrators, eg. to contact the user
EMAIL_ADMIN = 'admin'
#: Email address is visible to friends (ie. mutual follows)
EMAIL_FRIENDS = 'friends'
#: Email address is publicly available
EMAIL_PUBLIC = 'public'
EMAIL_VISIBILITY = (
(EMAIL_ADMIN, EMAIL_ADMIN),
(EMAIL_FRIENDS, EMAIL_FRIENDS),
(EMAIL_PUBLIC, EMAIL_PUBLIC),
)
#: The ID of the user. Generated automatically
id = db.Column(db.Integer(), primary_key=True)
#: The handle of the user. This will be used in the global account name
handle = db.Column(db.String(length=255), unique=True)
#: The hashed password of the user
password = db.Column(db.String(length=255))
#: The email address of the user. It may be hashed in which case it can only be used for
#: logging in
email = db.Column(db.String(length=255))
#: Visibility of the users email address
email_visibility = db.Column(ChoiceType(EMAIL_VISIBILITY), default=EMAIL_ADMIN)
#: Active flag. If this is ``False``, the user is disabled and cannot use the API in any way
active = db.Column(db.Boolean())
#: The timestamp of the users registration
registered_at = db.Column(db.DateTime(), default=datetime.utcnow)
#: The timestamp when the user confirmed the registration. While this field is ``None``, the
#: user cannot use the API.
confirmed_at = db.Column(db.DateTime())