From db1a438f3e6f8c5c8cec20b9326a21baf4579306 Mon Sep 17 00:00:00 2001
From: Joar Wandborg <git@wandborg.com>
Date: Tue, 3 May 2011 19:49:39 +0200
Subject: [PATCH] Added functionality to support user email verification, email = TBD, verification = done.
Signed-off-by: Joar Wandborg <git@wandborg.com>
---
mediagoblin/auth/routing.py | 4 ++-
mediagoblin/auth/views.py | 23 ++++++++++++++++
mediagoblin/models.py | 7 +++--
.../templates/mediagoblin/auth/verify_email.html | 28 ++++++++++++++++++++
4 files changed, 58 insertions(+), 4 deletions(-)
create mode 100644 mediagoblin/templates/mediagoblin/auth/verify_email.html
diff --git a/mediagoblin/auth/routing.py b/mediagoblin/auth/routing.py
index 92f1937..5976284 100644
a
|
b
|
auth_routes = [
|
24 | 24 | Route('mediagoblin.auth.login', '/login/', |
25 | 25 | controller='mediagoblin.auth.views:login'), |
26 | 26 | Route('mediagoblin.auth.logout', '/logout/', |
27 | | controller='mediagoblin.auth.views:logout')] |
| 27 | controller='mediagoblin.auth.views:logout'), |
| 28 | Route('mediagoblin.auth.verify_email', '/verify_email/', |
| 29 | controller='mediagoblin.auth.views:verify_email')] |
diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py
index 15e33e1..dfb6899 100644
a
|
b
|
def logout(request):
|
116 | 116 | |
117 | 117 | return exc.HTTPFound( |
118 | 118 | location=request.urlgen("index")) |
| 119 | |
| 120 | def verify_email(request): |
| 121 | import bson.objectid |
| 122 | user = request.db.User.find_one( |
| 123 | {'_id': bson.objectid.ObjectId( unicode( request.GET.get('userid') ) )}) |
| 124 | |
| 125 | verification_successful = bool |
| 126 | |
| 127 | if user and user['verification_key'] == unicode( request.GET.get('token') ): |
| 128 | user['status'] = u'active' |
| 129 | user['email_verified'] = True |
| 130 | verification_successful = True |
| 131 | user.save() |
| 132 | else: |
| 133 | verification_successful = False |
| 134 | |
| 135 | template = request.template_env.get_template( |
| 136 | 'mediagoblin/auth/verify_email.html') |
| 137 | return Response( |
| 138 | template.render( |
| 139 | {'request': request, |
| 140 | 'user': user, |
| 141 | 'verification_successful': verification_successful})) |
diff --git a/mediagoblin/models.py b/mediagoblin/models.py
index eef59ed..62cab4a 100644
a
|
b
|
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 | | import datetime |
| 17 | import datetime, uuid |
18 | 18 | |
19 | 19 | from mongokit import Document, Set |
20 | 20 | |
… |
… |
class User(Document):
|
41 | 41 | 'pw_hash': unicode, |
42 | 42 | 'email_verified': bool, |
43 | 43 | 'status': unicode, |
| 44 | 'verification_key': unicode |
44 | 45 | } |
45 | 46 | |
46 | 47 | required_fields = ['username', 'created', 'pw_hash', 'email'] |
… |
… |
class User(Document):
|
48 | 49 | default_values = { |
49 | 50 | 'created': datetime.datetime.utcnow, |
50 | 51 | 'email_verified': False, |
51 | | # TODO: shouldn't be active by default, must have email registration |
52 | | 'status': u'active'} |
| 52 | 'status': u'needs_email_verification', |
| 53 | 'verification_key': unicode( uuid.uuid4() ) } |
53 | 54 | |
54 | 55 | def check_login(self, password): |
55 | 56 | """ |
diff --git a/mediagoblin/templates/mediagoblin/auth/verify_email.html b/mediagoblin/templates/mediagoblin/auth/verify_email.html
new file mode 100644
index 0000000..fe9094b
-
|
+
|
|
| 1 | {# |
| 2 | # GNU MediaGoblin -- federated, autonomous media hosting |
| 3 | # Copyright (C) 2011 Free Software Foundation, Inc |
| 4 | # |
| 5 | # This program is free software: you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU Affero General Public License as published by |
| 7 | # the Free Software Foundation, either version 3 of the License, or |
| 8 | # (at your option) any later version. |
| 9 | # |
| 10 | # This program is distributed in the hope that it will be useful, |
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU Affero General Public License for more details. |
| 14 | # |
| 15 | # You should have received a copy of the GNU Affero General Public License |
| 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | #} |
| 18 | {% extends "mediagoblin/base.html" %} |
| 19 | |
| 20 | {% block mediagoblin_content %} |
| 21 | <p> |
| 22 | {% if verification_successful %} |
| 23 | Your email address has been verified! |
| 24 | {% else %} |
| 25 | The verification key or user id is incorrect |
| 26 | {% endif %} |
| 27 | </p> |
| 28 | {% endblock %} |