Added functionality to support user email verification, email = TBD, verification...
authorJoar Wandborg <git@wandborg.com>
Tue, 3 May 2011 17:49:39 +0000 (19:49 +0200)
committerJoar Wandborg <git@wandborg.com>
Tue, 3 May 2011 17:51:19 +0000 (19:51 +0200)
Signed-off-by: Joar Wandborg <git@wandborg.com>
mediagoblin/auth/routing.py
mediagoblin/auth/views.py
mediagoblin/models.py
mediagoblin/templates/mediagoblin/auth/verify_email.html [new file with mode: 0644]

index 92f19371c90c835a3b06b88dee8f2ee92b9f2665..59762840e44c56e908320f3fa57dc0fa5965c576 100644 (file)
@@ -24,4 +24,6 @@ auth_routes = [
     Route('mediagoblin.auth.login', '/login/',
           controller='mediagoblin.auth.views:login'),
     Route('mediagoblin.auth.logout', '/logout/',
-          controller='mediagoblin.auth.views:logout')]
+          controller='mediagoblin.auth.views:logout'),
+    Route('mediagoblin.auth.verify_email', '/verify_email/',
+          controller='mediagoblin.auth.views:verify_email')]
index 15e33e17ae11a91fc8c86d0eac9af6c13d344ce8..dfb6899f8c7077f3ecd4a5e9c54a7975718e2ce5 100644 (file)
@@ -116,3 +116,26 @@ def logout(request):
     
     return exc.HTTPFound(
         location=request.urlgen("index"))
+
+def verify_email(request):
+    import bson.objectid
+    user = request.db.User.find_one(
+        {'_id': bson.objectid.ObjectId( unicode( request.GET.get('userid') ) )})
+
+    verification_successful = bool
+
+    if user and user['verification_key'] == unicode( request.GET.get('token') ):
+        user['status'] = u'active'
+        user['email_verified'] = True
+        verification_successful = True
+        user.save()
+    else:
+        verification_successful = False
+        
+    template = request.template_env.get_template(
+        'mediagoblin/auth/verify_email.html')
+    return Response(
+        template.render(
+            {'request': request,
+             'user': user,
+             'verification_successful': verification_successful}))
index eef59ed4d553311d49e0e0c49c828e2e308dcbee..62cab4a5d977792a01a06b2aae0a745a42e43efd 100644 (file)
@@ -14,7 +14,7 @@
 # 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 datetime
+import datetime, uuid
 
 from mongokit import Document, Set
 
@@ -41,6 +41,7 @@ class User(Document):
         'pw_hash': unicode,
         'email_verified': bool,
         'status': unicode,
+        'verification_key': unicode
         }
 
     required_fields = ['username', 'created', 'pw_hash', 'email']
@@ -48,8 +49,8 @@ class User(Document):
     default_values = {
         'created': datetime.datetime.utcnow,
         'email_verified': False,
-        # TODO: shouldn't be active by default, must have email registration
-        'status': u'active'}
+        'status': u'needs_email_verification',
+        'verification_key': unicode( uuid.uuid4() ) }
 
     def check_login(self, password):
         """
diff --git a/mediagoblin/templates/mediagoblin/auth/verify_email.html b/mediagoblin/templates/mediagoblin/auth/verify_email.html
new file mode 100644 (file)
index 0000000..fe9094b
--- /dev/null
@@ -0,0 +1,28 @@
+{#
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2011 Free Software Foundation, Inc
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# 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/>.
+#}
+{% extends "mediagoblin/base.html" %}
+
+{% block mediagoblin_content %}
+<p>
+  {% if verification_successful %}
+  Your email address has been verified!
+  {% else %}
+  The verification key or user id is incorrect
+  {% endif %}
+</p>
+{% endblock %}