|
|
@ -55,24 +55,32 @@ class Address(Base):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
__abstract__ = True
|
|
|
|
__abstract__ = True
|
|
|
|
|
|
|
|
|
|
|
|
localpart = db.Column(db.String(80), primary_key=True, nullable=False)
|
|
|
|
localpart = db.Column(db.String(80), nullable=False)
|
|
|
|
|
|
|
|
|
|
|
|
@declarative.declared_attr
|
|
|
|
@declarative.declared_attr
|
|
|
|
def domain_name(cls):
|
|
|
|
def domain_name(cls):
|
|
|
|
return db.Column(db.String(80), db.ForeignKey(Domain.name),
|
|
|
|
return db.Column(db.String(80), db.ForeignKey(Domain.name),
|
|
|
|
primary_key=True, nullable=False)
|
|
|
|
nullable=False)
|
|
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
# This field is redundant with both localpart and domain name.
|
|
|
|
return '{0}@{1}'.format(self.localpart, self.domain_name)
|
|
|
|
# It is however very useful for quick lookups without joining tables,
|
|
|
|
|
|
|
|
# especially when the mail server il reading the database.
|
|
|
|
def get_id(self):
|
|
|
|
@declarative.declared_attr
|
|
|
|
return str(self)
|
|
|
|
def address(cls):
|
|
|
|
|
|
|
|
updater = lambda context: "{0}@{1}".format(
|
|
|
|
|
|
|
|
context.current_parameters["localpart"],
|
|
|
|
|
|
|
|
context.current_parameters["domain_name"],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return db.Column(db.String(255),
|
|
|
|
|
|
|
|
primary_key=True, nullable=False,
|
|
|
|
|
|
|
|
default=updater)
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
def get_by_email(cls, email):
|
|
|
|
def get_by_email(cls, email):
|
|
|
|
localpart, domain = email.split('@', maxsplit=1)
|
|
|
|
return cls.query.filter_by(address=email).first()
|
|
|
|
# Get the user object
|
|
|
|
|
|
|
|
return cls.query.filter_by(domain_name=domain, localpart=localpart).first()
|
|
|
|
def __str__(self):
|
|
|
|
|
|
|
|
return self.address
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class User(Address):
|
|
|
|
class User(Address):
|
|
|
@ -102,6 +110,9 @@ class User(Address):
|
|
|
|
is_active = True
|
|
|
|
is_active = True
|
|
|
|
is_anonymous = False
|
|
|
|
is_anonymous = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_id(self):
|
|
|
|
|
|
|
|
return self.address
|
|
|
|
|
|
|
|
|
|
|
|
pw_context = context.CryptContext(
|
|
|
|
pw_context = context.CryptContext(
|
|
|
|
["sha512_crypt", "sha256_crypt", "md5_crypt"]
|
|
|
|
["sha512_crypt", "sha256_crypt", "md5_crypt"]
|
|
|
|
)
|
|
|
|
)
|
|
|
|