Added the ability to regenerate a verification key.
authorAleksandar Micovic <aleks.micovic@gmail.com>
Tue, 31 May 2011 21:14:23 +0000 (17:14 -0400)
committerAleksandar Micovic <aleks.micovic@gmail.com>
Tue, 31 May 2011 21:14:23 +0000 (17:14 -0400)
mediagoblin/auth/routing.py
mediagoblin/auth/views.py
mediagoblin/db/models.py
mediagoblin/templates/mediagoblin/auth/verification_needed.html

index 9544b1652501264a0946b0ffd4f62d0d6c9dbf71..069e301949ebce4065c9a7186e77efb0d481d955 100644 (file)
@@ -28,4 +28,6 @@ auth_routes = [
     Route('mediagoblin.auth.verify_email', '/verify_email/',
           controller='mediagoblin.auth.views:verify_email'),
     Route('mediagoblin.auth.verify_email_notice', '/verification_required/',
-          controller='mediagoblin.auth.views:verify_email_notice')]
+          controller='mediagoblin.auth.views:verify_email_notice'),
+    Route('mediagoblin.auth.resend_verification', '/resend_verification/',
+          controller='mediagoblin.auth.views:resend_activation')]
index edac74a8d88e85dc816296139c499085758c51dd..22fdd46bbcbaf5b5f69142197051d90db281760b 100644 (file)
@@ -183,3 +183,44 @@ def verify_email_notice(request):
         template.render(
             {'request': request}))
 
+def resend_activation(request):
+    """
+    The reactivation view
+
+    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'])))
+
+
+    # TODO: For now, we use the successful registration page until we get a 
+    # proper messaging system.
+
+    template = request.template_env.get_template(
+        'mediagoblin/auth/register_success.html')
+    return exc.HTTPFound(
+        location=request.urlgen('mediagoblin.auth.register_success'))
+
index 37420834669ea380e48fa113b4537a28328edd70..0e933fb777c4cc631943f5f259bbeb66ea10787e 100644 (file)
@@ -64,6 +64,14 @@ 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'
index 26ea84dc67da39b7484ae2344f170f354064ef84..4104da192517d2f989b1238dddb930bdd482c15c 100644 (file)
@@ -24,6 +24,6 @@
   </p>
 
   <p>
-    Still haven't received an email? <a href="#">Click here to resend it.</a>
+    Still haven't received an email? <a href="{{ request.urlgen('mediagoblin.auth.resend_verification') }}">Click here to resend it.</a>
   </p>
 {% endblock %}