diff options
author | Rodney Ewing <ewing.rj@gmail.com> | 2013-06-25 13:37:21 -0700 |
---|---|---|
committer | Rodney Ewing <ewing.rj@gmail.com> | 2013-06-25 13:37:21 -0700 |
commit | af4414a85f3354a432e29ecf8cf39ffd926371e3 (patch) | |
tree | 34da18957bceb784aff8cd5c413fa8e8273068e9 /mediagoblin/auth/tools.py | |
parent | 5a1be074c0522c2151ab735eeb30a60c07ff7f7c (diff) | |
parent | 7fa4e19fc4e7d04175549ea2f21f8b741fbe69f2 (diff) | |
download | mediagoblin-af4414a85f3354a432e29ecf8cf39ffd926371e3.tar.lz mediagoblin-af4414a85f3354a432e29ecf8cf39ffd926371e3.tar.xz mediagoblin-af4414a85f3354a432e29ecf8cf39ffd926371e3.zip |
Merge remote-tracking branch 'upstream/master' into auth
Conflicts:
mediagoblin/app.py
mediagoblin/auth/forms.py
mediagoblin/auth/tools.py
mediagoblin/db/migrations.py
mediagoblin/db/models.py
mediagoblin/edit/views.py
mediagoblin/plugins/basic_auth/tools.py
mediagoblin/tests/test_edit.py
Diffstat (limited to 'mediagoblin/auth/tools.py')
-rw-r--r-- | mediagoblin/auth/tools.py | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/mediagoblin/auth/tools.py b/mediagoblin/auth/tools.py index 71f824de..877da14f 100644 --- a/mediagoblin/auth/tools.py +++ b/mediagoblin/auth/tools.py @@ -18,6 +18,7 @@ import logging import wtforms from mediagoblin import mg_globals +from mediagoblin.tools.crypto import get_timed_signer_url from mediagoblin.db.models import User from mediagoblin.tools.mail import (normalize_email, send_email, email_debug_message) @@ -60,11 +61,12 @@ def normalize_user_or_email_field(allow_email=True, allow_user=True): EMAIL_VERIFICATION_TEMPLATE = ( - u"http://{host}{uri}?" - u"userid={userid}&token={verification_key}") + u"{uri}?" + u"token={verification_key}") -def send_verification_email(user, request): +def send_verification_email(user, request, email=None, + rendered_email=None): """ Send the verification email to users to activate their accounts. @@ -72,19 +74,24 @@ def send_verification_email(user, request): - user: a user object - request: the request """ - rendered_email = render_template( - request, 'mediagoblin/auth/verification_email.txt', - {'username': user.username, - 'verification_url': EMAIL_VERIFICATION_TEMPLATE.format( - host=request.host, - uri=request.urlgen('mediagoblin.auth.verify_email'), - userid=unicode(user.id), - verification_key=user.verification_key)}) + if not email: + email = user.email + + if not rendered_email: + verification_key = get_timed_signer_url('mail_verification_token') \ + .dumps(user.id) + rendered_email = render_template( + request, 'mediagoblin/auth/verification_email.txt', + {'username': user.username, + 'verification_url': EMAIL_VERIFICATION_TEMPLATE.format( + uri=request.urlgen('mediagoblin.auth.verify_email', + qualified=True), + verification_key=verification_key)}) # TODO: There is no error handling in place send_email( mg_globals.app_config['email_sender_address'], - [user.email], + [email], # TODO # Due to the distributed nature of GNU MediaGoblin, we should # find a way to send some additional information about the |