Added functionality to support user email verification, email = TBD, verification = done.
Signed-off-by: Joar Wandborg <git@wandborg.com>
This commit is contained in:
parent
3dca2776a6
commit
db1a438f3e
@ -24,4 +24,6 @@ auth_routes = [
|
|||||||
Route('mediagoblin.auth.login', '/login/',
|
Route('mediagoblin.auth.login', '/login/',
|
||||||
controller='mediagoblin.auth.views:login'),
|
controller='mediagoblin.auth.views:login'),
|
||||||
Route('mediagoblin.auth.logout', '/logout/',
|
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')]
|
||||||
|
@ -116,3 +116,26 @@ def logout(request):
|
|||||||
|
|
||||||
return exc.HTTPFound(
|
return exc.HTTPFound(
|
||||||
location=request.urlgen("index"))
|
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}))
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import datetime
|
import datetime, uuid
|
||||||
|
|
||||||
from mongokit import Document, Set
|
from mongokit import Document, Set
|
||||||
|
|
||||||
@ -41,6 +41,7 @@ class User(Document):
|
|||||||
'pw_hash': unicode,
|
'pw_hash': unicode,
|
||||||
'email_verified': bool,
|
'email_verified': bool,
|
||||||
'status': unicode,
|
'status': unicode,
|
||||||
|
'verification_key': unicode
|
||||||
}
|
}
|
||||||
|
|
||||||
required_fields = ['username', 'created', 'pw_hash', 'email']
|
required_fields = ['username', 'created', 'pw_hash', 'email']
|
||||||
@ -48,8 +49,8 @@ class User(Document):
|
|||||||
default_values = {
|
default_values = {
|
||||||
'created': datetime.datetime.utcnow,
|
'created': datetime.datetime.utcnow,
|
||||||
'email_verified': False,
|
'email_verified': False,
|
||||||
# TODO: shouldn't be active by default, must have email registration
|
'status': u'needs_email_verification',
|
||||||
'status': u'active'}
|
'verification_key': unicode( uuid.uuid4() ) }
|
||||||
|
|
||||||
def check_login(self, password):
|
def check_login(self, password):
|
||||||
"""
|
"""
|
||||||
|
28
mediagoblin/templates/mediagoblin/auth/verify_email.html
Normal file
28
mediagoblin/templates/mediagoblin/auth/verify_email.html
Normal file
@ -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 %}
|
Loading…
x
Reference in New Issue
Block a user