mirror of
https://github.com/simple-login/app.git
synced 2025-02-22 23:02:55 +08:00
add EmailChange model
This commit is contained in:
parent
5d9fea82eb
commit
5d52a784f2
2 changed files with 64 additions and 0 deletions
|
@ -224,6 +224,10 @@ def _expiration_1h():
|
|||
return arrow.now().shift(hours=1)
|
||||
|
||||
|
||||
def _expiration_12h():
|
||||
return arrow.now().shift(hours=12)
|
||||
|
||||
|
||||
def _expiration_5m():
|
||||
return arrow.now().shift(minutes=5)
|
||||
|
||||
|
@ -563,3 +567,20 @@ class DeletedAlias(db.Model, ModelMixin):
|
|||
email = db.Column(db.String(128), unique=True, nullable=False)
|
||||
|
||||
|
||||
class EmailChange(db.Model, ModelMixin):
|
||||
"""Used when user wants to update their email"""
|
||||
|
||||
user_id = db.Column(
|
||||
db.ForeignKey(User.id, ondelete="cascade"),
|
||||
nullable=False,
|
||||
unique=True,
|
||||
index=True,
|
||||
)
|
||||
new_email = db.Column(db.String(128), unique=True, nullable=False)
|
||||
code = db.Column(db.String(128), unique=True, nullable=False)
|
||||
expired = db.Column(ArrowType, nullable=False, default=_expiration_12h)
|
||||
|
||||
user = db.relationship(User)
|
||||
|
||||
def is_expired(self):
|
||||
return self.expired < arrow.now()
|
||||
|
|
43
migrations/versions/3ebfbaeb76c0_.py
Normal file
43
migrations/versions/3ebfbaeb76c0_.py
Normal file
|
@ -0,0 +1,43 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 3ebfbaeb76c0
|
||||
Revises: 0a89c670fc7a
|
||||
Create Date: 2019-11-18 19:29:43.277973
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '3ebfbaeb76c0'
|
||||
down_revision = '0a89c670fc7a'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('email_change',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
sa.Column('created_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False),
|
||||
sa.Column('updated_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.Column('new_email', sa.String(length=128), nullable=False),
|
||||
sa.Column('code', sa.String(length=128), nullable=False),
|
||||
sa.Column('expired', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('code'),
|
||||
sa.UniqueConstraint('new_email')
|
||||
)
|
||||
op.create_index(op.f('ix_email_change_user_id'), 'email_change', ['user_id'], unique=True)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_email_change_user_id'), table_name='email_change')
|
||||
op.drop_table('email_change')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in a new issue