aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mediagoblin/auth/lib.py34
-rw-r--r--mediagoblin/auth/views.py62
-rw-r--r--mediagoblin/celery_setup/__init__.py1
-rw-r--r--mediagoblin/db/models.py8
-rw-r--r--mediagoblin/templates/mediagoblin/utils/pagination.html2
5 files changed, 47 insertions, 60 deletions
diff --git a/mediagoblin/auth/lib.py b/mediagoblin/auth/lib.py
index 7cf021bc..dc5f9941 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
+from mediagoblin import globals as mgoblin_globals
+
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_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'])))
diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py
index 4ccd3d86..e4f1a7b1 100644
--- a/mediagoblin/auth/views.py
+++ b/mediagoblin/auth/views.py
@@ -14,13 +14,14 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import bson.objectid
+import uuid
+
from webob import Response, exc
+from mediagoblin.db.util import ObjectId
from mediagoblin.auth import lib as auth_lib
from mediagoblin.auth import forms as auth_forms
-from mediagoblin.util import send_email
-from mediagoblin import globals as mgoblin_globals
+from mediagoblin.auth.lib import send_verification_email
def register(request):
@@ -50,27 +51,8 @@ def register(request):
request.POST['password'])
entry.save(validate=True)
- 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,
- [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'])))
-
+ send_verification_email(entry, request)
+
# Redirect to register_success
return exc.HTTPFound(
location=request.urlgen("mediagoblin.auth.register_success"))
@@ -154,9 +136,7 @@ def verify_email(request):
return exc.HTTPNotFound()
user = request.db.User.find_one(
- {'_id': bson.objectid.ObjectId(unicode(request.GET['userid']))})
-
- verification_successful = bool
+ {'_id': ObjectId(unicode(request.GET['userid']))})
if user and user['verification_key'] == unicode(request.GET['token']):
user['status'] = u'active'
@@ -196,30 +176,10 @@ def resend_activation(request):
Resend the activation email.
"""
- request.user.generate_new_verification_key()
-
- # Copied shamelessly from the register view above.
-
- 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'])))
+ request.user['verification_key'] = unicode(uuid.uuid4())
+ request.user.save()
+
+ send_verification_email(request.user, request)
return exc.HTTPFound(
location=request.urlgen('mediagoblin.auth.resend_verification_success'))
diff --git a/mediagoblin/celery_setup/__init__.py b/mediagoblin/celery_setup/__init__.py
index 1a77cc62..d4f25b07 100644
--- a/mediagoblin/celery_setup/__init__.py
+++ b/mediagoblin/celery_setup/__init__.py
@@ -140,6 +140,7 @@ def setup_celery_from_config(app_config, global_config,
if force_celery_always_eager:
celery_settings['CELERY_ALWAYS_EAGER'] = True
+ celery_settings['CELERY_EAGER_PROPAGATES_EXCEPTIONS'] = True
__import__(settings_module)
this_module = sys.modules[settings_module]
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index 0b85430a..3da97a49 100644
--- a/mediagoblin/db/models.py
+++ b/mediagoblin/db/models.py
@@ -64,14 +64,6 @@ class User(Document):
return auth_lib.bcrypt_check_password(
password, self['pw_hash'])
- def generate_new_verification_key(self):
- """
- Create a new verification key, overwriting the old one.
- """
-
- self['verification_key'] = unicode(uuid.uuid4())
- self.save(validate=False)
-
class MediaEntry(Document):
__collection__ = 'media_entries'
diff --git a/mediagoblin/templates/mediagoblin/utils/pagination.html b/mediagoblin/templates/mediagoblin/utils/pagination.html
index 5ca5e09b..62e8af91 100644
--- a/mediagoblin/templates/mediagoblin/utils/pagination.html
+++ b/mediagoblin/templates/mediagoblin/utils/pagination.html
@@ -32,7 +32,7 @@
<strong>{{ page }}</strong>
{% endif %}
{% else %}
- <span class=ellipsis>…</span>
+ <span class="ellipsis">…</span>
{% endif %}
{%- endfor %}