diff options
Diffstat (limited to 'mediagoblin/auth/lib.py')
-rw-r--r-- | mediagoblin/auth/lib.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/mediagoblin/auth/lib.py b/mediagoblin/auth/lib.py index 7cf021bc..f40e560f 100644 --- a/mediagoblin/auth/lib.py +++ b/mediagoblin/auth/lib.py @@ -19,6 +19,9 @@ import random import bcrypt +from mediagoblin.util import send_email, render_template +from mediagoblin import globals as mgoblin_globals + def bcrypt_check_password(raw_pass, stored_hash, extra_salt=None): """ @@ -84,3 +87,37 @@ def fake_login_attempt(): randplus_hashed_pass = bcrypt.hashpw(hashed_pass, rand_salt) randplus_stored_hash == randplus_hashed_pass + + +EMAIL_VERIFICATION_TEMPLATE = ( + u"http://{host}{uri}?" + u"userid={userid}&token={verification_key}") + +def send_verification_email(user, request): + """ + Send the verification email to users to activate their accounts. + + Args: + - 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'])}) + + # TODO: There is no error handling in place + send_email( + mgoblin_globals.email_sender_address, + [user['email']], + # TODO + # Due to the distributed nature of GNU MediaGoblin, we should + # find a way to send some additional information about the + # specific GNU MediaGoblin instance in the subject line. For + # example "GNU MediaGoblin @ Wandborg - [...]". + 'GNU MediaGoblin - Verify your email!', + rendered_email) |