aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/plugins/basic_auth/tools.py
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2013-09-19 16:04:23 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2013-09-19 16:04:23 -0500
commit74ae6fb0b620c2f899e2c97ba5f6af105103df6f (patch)
tree1fc5a7634299ba221858536a12d3fa8066a1898f /mediagoblin/plugins/basic_auth/tools.py
parent3dc6184167691d390f016c2b73fd6a9887955102 (diff)
parentf9931418d65c7823e13bc45f647a682ddf3b8632 (diff)
downloadmediagoblin-74ae6fb0b620c2f899e2c97ba5f6af105103df6f.tar.lz
mediagoblin-74ae6fb0b620c2f899e2c97ba5f6af105103df6f.tar.xz
mediagoblin-74ae6fb0b620c2f899e2c97ba5f6af105103df6f.zip
Merge remote-tracking branch 'refs/remotes/rodney757/auth_refactor'
Conflicts: mediagoblin/auth/views.py mediagoblin/edit/forms.py mediagoblin/templates/mediagoblin/edit/edit_account.html
Diffstat (limited to 'mediagoblin/plugins/basic_auth/tools.py')
-rw-r--r--mediagoblin/plugins/basic_auth/tools.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/mediagoblin/plugins/basic_auth/tools.py b/mediagoblin/plugins/basic_auth/tools.py
index 1300bb9a..f943bf39 100644
--- a/mediagoblin/plugins/basic_auth/tools.py
+++ b/mediagoblin/plugins/basic_auth/tools.py
@@ -16,6 +16,11 @@
import bcrypt
import random
+from mediagoblin import mg_globals
+from mediagoblin.tools.crypto import get_timed_signer_url
+from mediagoblin.tools.mail import send_email
+from mediagoblin.tools.template import render_template
+
def bcrypt_check_password(raw_pass, stored_hash, extra_salt=None):
"""
@@ -82,3 +87,35 @@ def fake_login_attempt():
randplus_hashed_pass = bcrypt.hashpw(hashed_pass, rand_salt)
randplus_stored_hash == randplus_hashed_pass
+
+
+EMAIL_FP_VERIFICATION_TEMPLATE = (
+ u"{uri}?"
+ u"token={fp_verification_key}")
+
+
+def send_fp_verification_email(user, request):
+ """
+ Send the verification email to users to change their password.
+
+ Args:
+ - user: a user object
+ - request: the request
+ """
+ fp_verification_key = get_timed_signer_url('mail_verification_token') \
+ .dumps(user.id)
+
+ rendered_email = render_template(
+ request, 'mediagoblin/plugins/basic_auth/fp_verification_email.txt',
+ {'username': user.username,
+ 'verification_url': EMAIL_FP_VERIFICATION_TEMPLATE.format(
+ uri=request.urlgen('mediagoblin.plugins.basic_auth.verify_forgot_password',
+ qualified=True),
+ fp_verification_key=fp_verification_key)})
+
+ # TODO: There is no error handling in place
+ send_email(
+ mg_globals.app_config['email_sender_address'],
+ [user.email],
+ 'GNU MediaGoblin - Change forgotten password!',
+ rendered_email)