Ticket #12: 0001-Added-functionality-to-support-user-email-verificati.patch

File 0001-Added-functionality-to-support-user-email-verificati.patch, 4.6 KB (added by joar, 13 years ago)

0001-Added-functionality-to-support-user-email-verificati.patch

  • mediagoblin/auth/routing.py

    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 = [  
    2424    Route('mediagoblin.auth.login', '/login/',
    2525          controller='mediagoblin.auth.views:login'),
    2626    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')]
  • mediagoblin/auth/views.py

    diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py
    index 15e33e1..dfb6899 100644
    a b def logout(request):  
    116116   
    117117    return exc.HTTPFound(
    118118        location=request.urlgen("index"))
     119
     120def 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}))
  • mediagoblin/models.py

    diff --git a/mediagoblin/models.py b/mediagoblin/models.py
    index eef59ed..62cab4a 100644
    a b  
    1414# You should have received a copy of the GNU Affero General Public License
    1515# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616
    17 import datetime
     17import datetime, uuid
    1818
    1919from mongokit import Document, Set
    2020
    class User(Document):  
    4141        'pw_hash': unicode,
    4242        'email_verified': bool,
    4343        'status': unicode,
     44        'verification_key': unicode
    4445        }
    4546
    4647    required_fields = ['username', 'created', 'pw_hash', 'email']
    class User(Document):  
    4849    default_values = {
    4950        'created': datetime.datetime.utcnow,
    5051        '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() ) }
    5354
    5455    def check_login(self, password):
    5556        """
  • new file mediagoblin/templates/mediagoblin/auth/verify_email.html

    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 %}