Keep the dirty email after registering

This commit is contained in:
Adrià Casajús 2022-11-30 18:28:15 +01:00
parent f728b0175a
commit 9d4bb68f71
No known key found for this signature in database
GPG key ID: F0033226A5AFC9B9
7 changed files with 41 additions and 1 deletions

View file

@ -92,6 +92,7 @@ def auth_register():
return jsonify(error="request body cannot be empty"), 400
email = canonicalize_email(data.get("email"))
dirty_email = sanitize_email(data.get("email"))
password = data.get("password")
if DISABLE_REGISTRATION:
@ -112,7 +113,7 @@ def auth_register():
return jsonify(error="password too long"), 400
LOG.d("create user %s", email)
user = User.create(email=email, name="", password=password)
user = User.create(email=email, dirty_email=dirty_email, name="", password=password)
Session.flush()
# create activation code

View file

@ -23,6 +23,7 @@ def change_email():
user = email_change.user
user.email = email_change.new_email
user.dirty_email = email_change.dirty_email or email_change.new_email
EmailChange.delete(email_change.id)
ResetPasswordCode.filter_by(user_id=user.id).delete()

View file

@ -85,6 +85,7 @@ def register():
LOG.d("create user %s", email)
user = User.create(
email=email,
dirty_email=sanitized_email,
name="",
password=form.password.data,
referral=get_referral(),

View file

@ -57,6 +57,7 @@ from app.utils import (
random_string,
CSRFValidationForm,
canonicalize_email,
sanitize_email,
)
@ -170,6 +171,7 @@ def setting():
60
), # todo: make sure the code is unique
new_email=new_email,
dirty_email=sanitize_email(change_email_form.email.data),
)
Session.commit()
send_change_email_confirmation(current_user, email_change)

View file

@ -43,6 +43,7 @@ def fake_data():
# Create a user
user = User.create(
email="john@wick.com",
dirty_email="john@wick.com",
name="John Wick",
password="password",
activated=True,
@ -234,6 +235,7 @@ def fake_data():
user2 = User.create(
email="winston@continental.com",
dirty_email="winston@continental.com",
password="password",
activated=True,
referral_id=referral.id,

View file

@ -320,6 +320,7 @@ class User(Base, ModelMixin, UserMixin, PasswordOracle):
FLAG_FREE_OLD_ALIAS_LIMIT = 1 << 2
email = sa.Column(sa.String(256), unique=True, nullable=False)
dirty_email = sa.Column(sa.String(256), unique=False, nullable=True)
name = sa.Column(sa.String(128), nullable=True)
is_admin = sa.Column(sa.Boolean, nullable=False, default=False)
@ -2064,6 +2065,7 @@ class EmailChange(Base, ModelMixin):
index=True,
)
new_email = sa.Column(sa.String(256), unique=True, nullable=False)
dirty_email = sa.Column(sa.String(256), unique=False, nullable=True)
code = sa.Column(sa.String(128), unique=True, nullable=False)
expired = sa.Column(ArrowType, nullable=False, default=_expiration_12h)

View file

@ -0,0 +1,31 @@
"""empty message
Revision ID: 74fe25b66e9b
Revises: 2c2093c82bc0
Create Date: 2022-11-30 18:21:44.235063
"""
import sqlalchemy_utils
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '74fe25b66e9b'
down_revision = '2c2093c82bc0'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('email_change', sa.Column('dirty_email', sa.String(length=256), nullable=True))
op.add_column('users', sa.Column('dirty_email', sa.String(length=256), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('users', 'dirty_email')
op.drop_column('email_change', 'dirty_email')
# ### end Alembic commands ###