Refactored the sending of verification emails.
This commit is contained in:
parent
04cb99b223
commit
02d80437d1
@ -19,6 +19,9 @@ import random
|
|||||||
|
|
||||||
import bcrypt
|
import bcrypt
|
||||||
|
|
||||||
|
from mediagoblin.util import send_email
|
||||||
|
from mediagoblin import globals as mgoblin_globals
|
||||||
|
|
||||||
|
|
||||||
def bcrypt_check_password(raw_pass, stored_hash, extra_salt=None):
|
def bcrypt_check_password(raw_pass, stored_hash, extra_salt=None):
|
||||||
"""
|
"""
|
||||||
@ -84,3 +87,34 @@ def fake_login_attempt():
|
|||||||
randplus_hashed_pass = bcrypt.hashpw(hashed_pass, rand_salt)
|
randplus_hashed_pass = bcrypt.hashpw(hashed_pass, rand_salt)
|
||||||
|
|
||||||
randplus_stored_hash == randplus_hashed_pass
|
randplus_stored_hash == randplus_hashed_pass
|
||||||
|
|
||||||
|
|
||||||
|
def send_verification_email(user, request):
|
||||||
|
"""
|
||||||
|
Send the verification email to users to activate their accounts.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
- user: a user object
|
||||||
|
- request: the request
|
||||||
|
"""
|
||||||
|
|
||||||
|
email_template = request.template_env.get_template(
|
||||||
|
'mediagoblin/auth/verification_email.txt')
|
||||||
|
|
||||||
|
# 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!',
|
||||||
|
email_template.render(
|
||||||
|
username=user['username'],
|
||||||
|
verification_url='http://{host}{uri}?userid={userid}&token={verification_key}'.format(
|
||||||
|
host=request.host,
|
||||||
|
uri=request.urlgen('mediagoblin.auth.verify_email'),
|
||||||
|
userid=unicode(user['_id']),
|
||||||
|
verification_key=user['verification_key'])))
|
||||||
|
@ -21,8 +21,7 @@ from webob import Response, exc
|
|||||||
from mediagoblin.db.util import ObjectId
|
from mediagoblin.db.util import ObjectId
|
||||||
from mediagoblin.auth import lib as auth_lib
|
from mediagoblin.auth import lib as auth_lib
|
||||||
from mediagoblin.auth import forms as auth_forms
|
from mediagoblin.auth import forms as auth_forms
|
||||||
from mediagoblin.util import send_email
|
from mediagoblin.auth.lib import send_verification_email
|
||||||
from mediagoblin import globals as mgoblin_globals
|
|
||||||
|
|
||||||
|
|
||||||
def register(request):
|
def register(request):
|
||||||
@ -52,27 +51,8 @@ def register(request):
|
|||||||
request.POST['password'])
|
request.POST['password'])
|
||||||
entry.save(validate=True)
|
entry.save(validate=True)
|
||||||
|
|
||||||
email_template = request.template_env.get_template(
|
send_verification_email(entry, request)
|
||||||
'mediagoblin/auth/verification_email.txt')
|
|
||||||
|
|
||||||
# TODO: There is no error handling in place
|
|
||||||
send_email(
|
|
||||||
mgoblin_globals.email_sender_address,
|
|
||||||
[entry['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 email',
|
|
||||||
email_template.render(
|
|
||||||
username=entry['username'],
|
|
||||||
verification_url='http://{host}{uri}?userid={userid}&token={verification_key}'.format(
|
|
||||||
host=request.host,
|
|
||||||
uri=request.urlgen('mediagoblin.auth.verify_email'),
|
|
||||||
userid=unicode(entry['_id']),
|
|
||||||
verification_key=entry['verification_key'])))
|
|
||||||
|
|
||||||
# Redirect to register_success
|
# Redirect to register_success
|
||||||
return exc.HTTPFound(
|
return exc.HTTPFound(
|
||||||
location=request.urlgen("mediagoblin.auth.register_success"))
|
location=request.urlgen("mediagoblin.auth.register_success"))
|
||||||
@ -195,31 +175,11 @@ def resend_activation(request):
|
|||||||
|
|
||||||
Resend the activation email.
|
Resend the activation email.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request.user['verification_key'] = unicode(uuid.uuid4())
|
request.user['verification_key'] = unicode(uuid.uuid4())
|
||||||
request.user.save()
|
request.user.save()
|
||||||
|
|
||||||
# Copied shamelessly from the register view above.
|
send_verification_email(request.user, request)
|
||||||
|
|
||||||
email_template = request.template_env.get_template(
|
|
||||||
'mediagoblin/auth/verification_email.txt')
|
|
||||||
|
|
||||||
# TODO: There is no error handling in place
|
|
||||||
send_email(
|
|
||||||
mgoblin_globals.email_sender_address,
|
|
||||||
[request.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 email',
|
|
||||||
email_template.render(
|
|
||||||
username=request.user['username'],
|
|
||||||
verification_url='http://{host}{uri}?userid={userid}&token={verification_key}'.format(
|
|
||||||
host=request.host,
|
|
||||||
uri=request.urlgen('mediagoblin.auth.verify_email'),
|
|
||||||
userid=unicode(request.user['_id']),
|
|
||||||
verification_key=request.user['verification_key'])))
|
|
||||||
|
|
||||||
return exc.HTTPFound(
|
return exc.HTTPFound(
|
||||||
location=request.urlgen('mediagoblin.auth.resend_verification_success'))
|
location=request.urlgen('mediagoblin.auth.resend_verification_success'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user