From 4bdd433079024e29d3aac91b735efce750914782 Mon Sep 17 00:00:00 2001 From: Khanh Ngo Date: Sat, 21 Dec 2019 22:26:56 +0700 Subject: [PATCH] Fix migration script and LGTM --- .../versions/3f76448bb6de_add_user_confirmed_column.py | 10 ++++------ powerdnsadmin/models/user.py | 2 +- powerdnsadmin/routes/index.py | 2 +- powerdnsadmin/services/token.py | 3 ++- .../templates/emails/account_verification.html | 3 ++- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/migrations/versions/3f76448bb6de_add_user_confirmed_column.py b/migrations/versions/3f76448bb6de_add_user_confirmed_column.py index c67243c..a560f69 100644 --- a/migrations/versions/3f76448bb6de_add_user_confirmed_column.py +++ b/migrations/versions/3f76448bb6de_add_user_confirmed_column.py @@ -17,12 +17,10 @@ depends_on = None def upgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.add_column('user', sa.Column('confirmed', sa.Boolean(), nullable=True)) - # ### end Alembic commands ### + with op.batch_alter_table('user') as batch_op: + batch_op.add_column(sa.Column('confirmed', sa.Boolean())) def downgrade(): - # ### commands auto generated by Alembic - please adjust! ### - op.drop_column('user', 'confirmed') - # ### end Alembic commands ### + with op.batch_alter_table('user') as batch_op: + batch_op.drop_column('confirmed') diff --git a/powerdnsadmin/models/user.py b/powerdnsadmin/models/user.py index aa7ccad..f2f705c 100644 --- a/powerdnsadmin/models/user.py +++ b/powerdnsadmin/models/user.py @@ -26,7 +26,7 @@ class User(db.Model): lastname = db.Column(db.String(64)) email = db.Column(db.String(128)) otp_secret = db.Column(db.String(16)) - confirmed = db.Column(db.Boolean, default=False) + confirmed = db.Column(db.SmallInteger, default=0) role_id = db.Column(db.Integer, db.ForeignKey('role.id')) def __init__(self, diff --git a/powerdnsadmin/routes/index.py b/powerdnsadmin/routes/index.py index 419eea7..08bf111 100644 --- a/powerdnsadmin/routes/index.py +++ b/powerdnsadmin/routes/index.py @@ -446,7 +446,7 @@ def confirm_email(token): return render_template('email_confirmation.html', status=2) else: # Confirm email is valid - user.update_confirmed(confirmed=True) + user.update_confirmed(confirmed=1) current_app.logger.info( "User email {} confirmed successfully".format(email)) return render_template('email_confirmation.html', status=1) diff --git a/powerdnsadmin/services/token.py b/powerdnsadmin/services/token.py index e4e98ff..2a4f8b4 100644 --- a/powerdnsadmin/services/token.py +++ b/powerdnsadmin/services/token.py @@ -13,6 +13,7 @@ def confirm_token(token, expiration=86400): email = serializer.loads(token, salt=current_app.config['SALT'], max_age=expiration) - except: + except Exception as e: + current_app.logger.debug(e) return False return email diff --git a/powerdnsadmin/templates/emails/account_verification.html b/powerdnsadmin/templates/emails/account_verification.html index 55cfba1..74e02fd 100644 --- a/powerdnsadmin/templates/emails/account_verification.html +++ b/powerdnsadmin/templates/emails/account_verification.html @@ -157,6 +157,7 @@ bgcolor="#3498db"> Verify Email Address @@ -194,7 +195,7 @@ This email was sent from {{ SITE_NAME }} + target="_blank" rel="noopener noreferrer">{{ SITE_NAME }}