70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
|
# 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 user’s 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 user’s 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())
|