From 683b855584c2b8e057d68978133a44c99d12d058 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 5 Dec 2020 19:23:43 +0000 Subject: [PATCH] Enable email notifications for new users --- app/blueprints/users/account.py | 20 +++++++++++++------- app/templates/users/change_set_password.html | 4 ++-- app/templates/users/settings_email.html | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/blueprints/users/account.py b/app/blueprints/users/account.py index 0713d4e6..12eb0a7a 100644 --- a/app/blueprints/users/account.py +++ b/app/blueprints/users/account.py @@ -110,6 +110,7 @@ def register(): "We were unable to create the account as the email is already in use by {}. Try a different email address.".format(user.display_name)) else: user = User(form.username.data, False, form.email.data, make_flask_login_password(form.password.data)) + user.notification_preferences = UserNotificationPreferences(user) db.session.add(user) addAuditLog(AuditSeverity.USER, user, "Registered", @@ -267,18 +268,23 @@ def verify_email(): flash("Unknown verification token!", "danger") return redirect(url_for("homepage.home")) - addAuditLog(AuditSeverity.USER, ver.user, "Confirmed their email", - url_for("users.profile", username=ver.user.username)) + user = ver.user + + addAuditLog(AuditSeverity.USER, user, "Confirmed their email", + url_for("users.profile", username=user.username)) + + was_activating = not user.is_active + + user.is_active = True + user.notification_preferences = user.notification_preferences or UserNotificationPreferences(user) + user.email = ver.email - was_activating = not ver.user.is_active - ver.user.is_active = True - ver.user.email = ver.email db.session.delete(ver) db.session.commit() if ver.is_password_reset: - login_user(ver.user) - ver.user.password = None + login_user(user) + user.password = None db.session.commit() return redirect(url_for("users.set_password")) diff --git a/app/templates/users/change_set_password.html b/app/templates/users/change_set_password.html index 42dc97d8..22b032f2 100644 --- a/app/templates/users/change_set_password.html +++ b/app/templates/users/change_set_password.html @@ -26,8 +26,8 @@

Your email is needed to recover your account if you forget your - password, and to optionally send notifications. - Your email will never be shared to a third-party. + password and to send (configurable) notifications. + Your email will never be shared with a third-party.

{% endif %} diff --git a/app/templates/users/settings_email.html b/app/templates/users/settings_email.html index 235fcf49..52039754 100644 --- a/app/templates/users/settings_email.html +++ b/app/templates/users/settings_email.html @@ -17,8 +17,8 @@

Your email is needed to recover your account if you forget your - password, and to optionally send notifications. - Your email will never be shared to a third-party. + password, and to send (configurable) notifications. + Your email will never be shared with a third-party.