Merge pull request #12 from simple-login/email-notification

Email notification
This commit is contained in:
Son Nguyen Kim 2019-12-30 21:13:22 +01:00 committed by GitHub
commit 43a96201ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 0 deletions

View file

@ -88,6 +88,21 @@
<button class="btn btn-outline-primary">Update Preference</button>
</form>
<hr>
<h3 class="mb-0">Notifications</h3>
<div class="small-text mb-3">Do you want to receive our newsletter?</div>
<form method="post">
<input type="hidden" name="form-name" value="notification-preference">
<div class="form-inline mb-3">
<div class="form-group">
<input type="checkbox" id="notification" name="notification" {% if current_user.notification %} checked {% endif %} class="form-check-input">
<label for="notification">I want to receive your newsletter</label>
</div>
</div>
<button type="submit" class="btn btn-outline-primary">Submit</button>
</form>
<hr>
<h3 class="mb-0">Export Data</h3>
<div class="small-text mb-3">

View file

@ -115,6 +115,15 @@ def setting():
elif request.form.get("form-name") == "change-password":
send_reset_password_email(current_user)
elif request.form.get("form-name") == "notification-preference":
choose = request.form.get("notification")
if choose == "on":
current_user.notification = True
else:
current_user.notification = False
db.session.commit()
flash("Your notification preference has been updated", "success")
elif request.form.get("form-name") == "delete-account":
User.delete(current_user.id)
db.session.commit()

View file

@ -106,6 +106,9 @@ class User(db.Model, ModelMixin, UserMixin):
default=AliasGeneratorEnum.word.value,
server_default=str(AliasGeneratorEnum.word.value),
)
notification = db.Column(
db.Boolean, default=True, nullable=False, server_default="1"
)
activated = db.Column(db.Boolean, default=False, nullable=False)

View file

@ -0,0 +1,29 @@
"""empty message
Revision ID: a8b996f0be40
Revises: 696e17c13b8b
Create Date: 2019-12-30 00:22:25.114359
"""
import sqlalchemy_utils
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'a8b996f0be40'
down_revision = '696e17c13b8b'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('users', sa.Column('notification', sa.Boolean(), server_default='1', nullable=False))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('users', 'notification')
# ### end Alembic commands ###