summaryrefslogtreecommitdiffstats
path: root/accounts/views
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2016-02-02 03:07:44 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2016-02-02 04:44:07 +0100
commit9a196839970e7d98a2bd9375bbd470846ccb3a27 (patch)
tree1c52403114bb5da11db863da72d67f2b6d75ac98 /accounts/views
parent34b571a7335ba3d2b71409068b93df603b0271b9 (diff)
downloadweb-9a196839970e7d98a2bd9375bbd470846ccb3a27.tar.gz
web-9a196839970e7d98a2bd9375bbd470846ccb3a27.tar.bz2
web-9a196839970e7d98a2bd9375bbd470846ccb3a27.zip
templates/mail: Get all parts from the template
Also render sender and subject with the mail template, so the mails can be created with only a template name, a recipient and the template args. The required confirmation links are also generated in the templates.
Diffstat (limited to 'accounts/views')
-rw-r--r--accounts/views/admin/__init__.py16
-rw-r--r--accounts/views/default/__init__.py34
2 files changed, 16 insertions, 34 deletions
diff --git a/accounts/views/admin/__init__.py b/accounts/views/admin/__init__.py
index f6ac51a..d008d98 100644
--- a/accounts/views/admin/__init__.py
+++ b/accounts/views/admin/__init__.py
@@ -7,7 +7,7 @@ from flask.ext.login import current_user
from uuid import uuid4
from werkzeug.exceptions import Forbidden
-from accounts.utils import templated, send_register_confirmation_mail
+from accounts.utils import templated
from accounts.forms import AdminCreateAccountForm, AdminDisableAccountForm
@@ -33,7 +33,8 @@ def index():
def create_account():
form = AdminCreateAccountForm()
if request.method == 'POST' and form.validate():
- send_register_confirmation_mail(form.username.data, form.mail.data)
+ current_app.mail_backend.send(form.mail.data, 'mail/register.txt',
+ username=form.username.data)
flash(u'Mail versandt.', 'success')
return redirect(url_for('admin.index'))
@@ -78,13 +79,10 @@ def disable_account():
flash(u'Passwort auf ein zufälliges und Mailadresse auf %s '
u'gesetzt.' % mail, 'success')
- if current_app.config.get('MAIL_REGISTER_NOTIFY'):
- current_app.mail_backend.send(
- current_app.config['MAIL_REGISTER_NOTIFY'],
- u'[accounts] Benutzer %s deaktiviert' % form.user.uid,
- 'Benutzername: %s\nE-Mail war: %s\n\ndurch: %s\n' % \
- (form.user.uid, oldmail, session['username'])
- )
+ current_app.mail_backend.send(
+ current_app.config['MAIL_REGISTER_NOTIFY'],
+ 'mail/disable_notify.txt',
+ username=form.user.uid, mail=oldmail, admin=current_user.uid)
return redirect(url_for('admin.index'))
diff --git a/accounts/views/default/__init__.py b/accounts/views/default/__init__.py
index 0a7e65d..eec173e 100644
--- a/accounts/views/default/__init__.py
+++ b/accounts/views/default/__init__.py
@@ -23,7 +23,8 @@ bp = Blueprint('default', __name__)
def register():
form = RegisterForm(request.form)
if form.validate_on_submit():
- send_register_confirmation_mail(form.username.data, form.mail.data)
+ current_app.mail_backend.send(form.mail.data, 'mail/register.txt',
+ username=form.username.data)
flash(u'Es wurde eine E-Mail an die angegebene Adresse geschickt, '
u'um diese zu überprüfen. Bitte folge den Anweisungen in der '
@@ -58,14 +59,10 @@ def register_complete(token):
current_app.user_backend.register(user)
login_user(user)
- if current_app.config.get('MAIL_REGISTER_NOTIFY'):
- current_app.mail_backend.send(
- current_app.config['MAIL_REGISTER_NOTIFY'],
- u'[accounts] Neuer Benutzer %s erstellt' % username,
- u'Benutzername: %s\nE-Mail: %s\n\nSpammer? Deaktivieren: '
- u'%s\n' % (username, mail,
- url_for('admin.disable_account', uid=username, _external=True))
- )
+ current_app.mail_backend.send(
+ current_app.config['MAIL_REGISTER_NOTIFY'],
+ 'mail/register_notify.txt',
+ username=username, mail=mail)
flash(u'Benutzer erfolgreich angelegt.', 'success')
return redirect(url_for('.index'))
@@ -86,15 +83,8 @@ def lost_password():
if form.validate_on_submit():
#TODO: make the link only usable once (e.g include a hash of the old pw)
# atm the only thing we do is make the link valid for only little time
- confirm_token = Confirmation('lost_password').dumps(form.user.uid)
- confirm_link = url_for('.lost_password_complete', token=confirm_token, _external=True)
-
- body = render_template('mail/lost_password.txt', username=form.user.uid,
- link=confirm_link)
-
current_app.mail_backend.send(
- form.user.attributes['mail'], u'Passwort vergessen', body,
- sender=current_app.config.get('MAIL_CONFIRM_SENDER'))
+ form.user.mail, 'mail/lost_password.txt', username=form.user.uid)
flash(u'Wir haben dir eine E-Mail mit einem Link zum Passwort ändern '
u'geschickt. Bitte folge den Anweisungen in der E-Mail.', 'success')
@@ -144,15 +134,9 @@ def index():
elif request.form.get('submit_main'):
if form.mail.data and form.mail.data != current_user.mail:
- confirm_token = Confirmation('change_mail').dumps((current_user.uid, form.mail.data))
- confirm_link = url_for('.change_mail', token=confirm_token, _external=True)
-
- body = render_template('mail/change_mail.txt', username=current_user.uid,
- mail=form.mail.data, link=confirm_link)
-
current_app.mail_backend.send(
- form.mail.data, u'E-Mail-Adresse bestätigen', body,
- sender=current_app.config.get('MAIL_CONFIRM_SENDER'))
+ form.mail.data, 'mail/change_mail.txt',
+ username=current_user.uid)
flash(u'Es wurde eine E-Mail an die angegebene Adresse geschickt, '
u'um diese zu überprüfen. Bitte folge den Anweisungen in der '