Skip to content

Commit

Permalink
feat(dev): gc notify support;
Browse files Browse the repository at this point in the history
- Support for GC Notify mailer.
  • Loading branch information
JVickery-TBS committed Jul 16, 2024
1 parent 0c82604 commit ca11994
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions ckanext/security/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ckan.common import config, is_flask_request
from ckan.lib.base import render_jinja2, render
from ckan.lib.mailer import get_reset_link_body, mail_user
import ckan.lib.mailer as mailer # (canada fork only): GC Notify support
from ckan.plugins import toolkit as tk
from ckan import model

Expand Down Expand Up @@ -66,29 +67,34 @@ def _build_footer_content(extra_vars):


def notify_lockout(user, lockout_timeout):
extra_vars = {
'site_title': config.get('ckan.site_title'),
'site_url': config.get('ckan.site_url'),
'user_name': user.name,
'password_reset_url':
config.get('ckan.site_url').rstrip('/') + '/user/login',
'lockout_mins': lockout_timeout // 60,
}
# (canada fork only): GC Notify support
try:
# see: ckanext.gcnotify.mailer.notify_lockout
mailer.notify_lockout(user, lockout_timeout)
except mailer.MailerException:
extra_vars = {
'site_title': config.get('ckan.site_title'),
'site_url': config.get('ckan.site_url'),
'user_name': user.name,
'password_reset_url':
config.get('ckan.site_url').rstrip('/') + '/user/login',
'lockout_mins': lockout_timeout // 60,
}

if is_flask_request():
subject = render(
'security/emails/lockout_subject.txt', extra_vars)
else:
subject = render_jinja2(
'security/emails/lockout_subject.txt', extra_vars)
if is_flask_request():
subject = render(
'security/emails/lockout_subject.txt', extra_vars)
else:
subject = render_jinja2(
'security/emails/lockout_subject.txt', extra_vars)

subject = subject.split('\n')[0] # Make sure we only use the first line
subject = subject.split('\n')[0] # Make sure we only use the first line

if is_flask_request():
body = render('security/emails/lockout_mail.txt', extra_vars)\
+ _build_footer_content(extra_vars)
else:
body = render_jinja2('security/emails/lockout_mail.txt', extra_vars)\
+ _build_footer_content(extra_vars)
if is_flask_request():
body = render('security/emails/lockout_mail.txt', extra_vars)\
+ _build_footer_content(extra_vars)
else:
body = render_jinja2('security/emails/lockout_mail.txt', extra_vars)\
+ _build_footer_content(extra_vars)

mail_user(user, subject, body)
mail_user(user, subject, body)

0 comments on commit ca11994

Please sign in to comment.