diff options
18 files changed, 339 insertions, 133 deletions
diff --git a/mediagoblin/auth/routing.py b/mediagoblin/auth/routing.py index 59762840..a8909fbb 100644 --- a/mediagoblin/auth/routing.py +++ b/mediagoblin/auth/routing.py @@ -26,4 +26,11 @@ auth_routes = [ Route('mediagoblin.auth.logout', '/logout/', controller='mediagoblin.auth.views:logout'), Route('mediagoblin.auth.verify_email', '/verify_email/', - controller='mediagoblin.auth.views:verify_email')] + controller='mediagoblin.auth.views:verify_email'), + Route('mediagoblin.auth.verify_email_notice', '/verification_required/', + controller='mediagoblin.auth.views:verify_email_notice'), + Route('mediagoblin.auth.resend_verification', '/resend_verification/', + controller='mediagoblin.auth.views:resend_activation'), + Route('mediagoblin.auth.resend_verification_success', + '/resend_verification_success/', + controller='mediagoblin.auth.views:resend_activation_success')] diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index c3d24c74..4ccd3d86 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -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 bson.objectid from webob import Response, exc from mediagoblin.auth import lib as auth_lib @@ -31,8 +31,11 @@ def register(request): if request.method == 'POST' and register_form.validate(): # TODO: Make sure the user doesn't exist already + users_with_username = \ - request.db.User.find({'username': request.POST['username']}).count() + request.db.User.find({ + 'username': request.POST['username'].lower() + }).count() if users_with_username: register_form.username.errors.append( @@ -41,7 +44,7 @@ def register(request): else: # Create the user entry = request.db.User() - entry['username'] = request.POST['username'] + entry['username'] = request.POST['username'].lower() entry['email'] = request.POST['email'] entry['pw_hash'] = auth_lib.bcrypt_gen_password_hash( request.POST['password']) @@ -101,7 +104,7 @@ def login(request): if request.method == 'POST' and login_form.validate(): user = request.db.User.one( - {'username': request.POST['username']}) + {'username': request.POST['username'].lower()}) if user and user.check_login(request.POST['password']): # set up login in session @@ -138,6 +141,7 @@ def logout(request): return exc.HTTPFound( location=request.urlgen("index")) + def verify_email(request): """ Email verification view @@ -145,13 +149,16 @@ def verify_email(request): validates GET parameters against database and unlocks the user account, if you are lucky :) """ - import bson.objectid + # If we don't have userid and token parameters, we can't do anything; 404 + if not request.GET.has_key('userid') or not request.GET.has_key('token'): + return exc.HTTPNotFound() + user = request.db.User.find_one( - {'_id': bson.objectid.ObjectId(unicode(request.GET.get('userid')))}) + {'_id': bson.objectid.ObjectId(unicode(request.GET['userid']))}) verification_successful = bool - if user and user['verification_key'] == unicode(request.GET.get('token')): + if user and user['verification_key'] == unicode(request.GET['token']): user['status'] = u'active' user['email_verified'] = True verification_successful = True @@ -166,3 +173,61 @@ def verify_email(request): {'request': request, 'user': user, 'verification_successful': verification_successful})) + +def verify_email_notice(request): + """ + Verify warning view. + + When the user tries to do some action that requires their account + to be verified beforehand, this view is called upon! + """ + + template = request.template_env.get_template( + 'mediagoblin/auth/verification_needed.html') + return Response( + 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']))) + + return exc.HTTPFound( + location=request.urlgen('mediagoblin.auth.resend_verification_success')) + + +def resend_activation_success(request): + template = request.template_env.get_template( + 'mediagoblin/auth/resent_verification_email.html') + return Response( + template.render( + {'request': request})) diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 37420834..0b85430a 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -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' @@ -95,7 +103,7 @@ class MediaEntry(Document): 'thumbnail_file': [unicode]} required_fields = [ - 'uploader', 'created', 'media_type'] + 'uploader', 'created', 'media_type', 'slug'] default_values = { 'created': datetime.datetime.utcnow, @@ -103,11 +111,10 @@ class MediaEntry(Document): migration_handler = migrations.MediaEntryMigration - # Actually we should referene uniqueness by uploader, but we - # should fix http://bugs.foocorp.net/issues/340 first. - # indexes = [ - # {'fields': ['uploader', 'slug'], - # 'unique': True}] + indexes = [ + # Referene uniqueness of slugs by uploader + {'fields': ['uploader', 'slug'], + 'unique': True}] def main_mediafile(self): pass diff --git a/mediagoblin/decorators.py b/mediagoblin/decorators.py index fe631112..34575320 100644 --- a/mediagoblin/decorators.py +++ b/mediagoblin/decorators.py @@ -36,9 +36,12 @@ def require_active_login(controller): Require an active login from the user. """ def new_controller_func(request, *args, **kwargs): - if not request.user or not request.user.get('status') == u'active': - # TODO: Indicate to the user that they were redirected - # here because an *active* user is required. + if request.user and \ + request.user.get('status') == u'needs_email_verification': + return exc.HTTPFound( + location = request.urlgen( + 'mediagoblin.auth.verify_email_notice')) + elif not request.user or request.user.get('status') != u'active': return exc.HTTPFound( location="%s?next=%s" % ( request.urlgen("mediagoblin.auth.login"), diff --git a/mediagoblin/static/css/base.css b/mediagoblin/static/css/base.css index c7d3d4ad..5d928b9a 100644 --- a/mediagoblin/static/css/base.css +++ b/mediagoblin/static/css/base.css @@ -1,9 +1,9 @@ body { - background-color: #272727; - color: #f7f7f7; - font-family: sans; - padding:none; - margin:0px; + background-color: #272727; + color: #f7f7f7; + font-family: sans-serif; + padding:none; + margin:0px; } /* Carter One font */ @@ -18,13 +18,18 @@ body { /* text styles */ h1 { - font-family: 'Carter One', arial, serif; - margin-bottom: 20px; - margin-top:40px; + font-family: 'Carter One', arial, serif; + margin-bottom: 20px; + margin-top:40px; +} + +p { + font-family: sans-serif; + font-size:16px; } a { - color: #86D4B1; + color: #86D4B1; } label { @@ -34,53 +39,122 @@ label { /* website structure */ .mediagoblin_header { - width:100%; - height:36px; - background-color:#393939; - padding-top:14px; - margin-bottom:40px; + width:100%; + height:36px; + background-color:#393939; + padding-top:14px; + margin-bottom:40px; +} + +a.mediagoblin_logo { + width:34px; + height:25px; + margin-right:10px; + background-image:url('../images/icon.png'); + background-position:0px 0px; + display:inline-block; } -.icon { - vertical-align:middle; - margin-right:10px; +a.mediagoblin_logo:hover { + background-position:0px -28px; } .mediagoblin_container { - width: 960px; - margin-left: auto; - margin-right: auto; + width: 960px; + margin-left: auto; + margin-right: auto; } .mediagoblin_header_right { - float:right; + float:right; } .button { - font-family:'Carter One', arial, serif; - height:32px; - min-width:99px; - background-color:#86d4b1; - box-shadow:0px 0px 4px #000; - border-radius:5px; - border:none; - color:#272727; - margin:10px; - font-size:1em; - float:left; - display:block; - text-align:center; - padding-left:11px; - padding-right:11px; + font-family:'Carter One', arial, serif; + height:32px; + min-width:99px; + background-color:#86d4b1; + box-shadow:0px 0px 4px #000; + border-radius:5px; + border:none; + color:#272727; + margin:10px; + font-size:1em; + display:block; + text-align:center; + padding-left:11px; + padding-right:11px; } /* common website elements */ .dotted_line { - width:100%; - height:0px; - border-bottom: dotted 1px #5f5f5f; - position:absolute; - left:0px; - margin-top:-20px; + width:100%; + height:0px; + border-bottom: dotted 1px #5f5f5f; + position:absolute; + left:0px; + margin-top:-20px; +} + +/* forms */ + +.form_box { + width:300px; + margin-left:auto; + margin-right:auto; + background-color:#393939; + padding:0px 83px 30px 83px; + border-top:5px solid #d49086; + font-size:18px; +} + +.submit_box { + width:600px; +} + +.form_box h1 { + font-size:28px; +} + +.form_field_input input { + width:300px; + font-size:18px; +} + +.form_field_box { + margin-bottom:24px; +} + +.form_field_label,.form_field_input { + margin-bottom:4px; +} + +.form_field_error { + background-color:#87453b; + border:none; + font-size:16px; + padding:9px; + margin-top:8px; + margin-bottom:8px; +} + +/* media pages */ + +img.media_image { + display:block; + margin-left:auto; + margin-right:auto; +} + +li.media_thumbnail { + width: 200px; + min-height: 250px; + display: -moz-inline-stack; + display: inline-block; + vertical-align: top; + margin: 5px; + zoom: 1; + *display: inline; + _height: 250px; } diff --git a/mediagoblin/static/images/icon.png b/mediagoblin/static/images/icon.png Binary files differindex 47f07b9a..4f4f3e9c 100644 --- a/mediagoblin/static/images/icon.png +++ b/mediagoblin/static/images/icon.png diff --git a/mediagoblin/templates/mediagoblin/auth/login.html b/mediagoblin/templates/mediagoblin/auth/login.html index 02bfb91f..22a57b70 100644 --- a/mediagoblin/templates/mediagoblin/auth/login.html +++ b/mediagoblin/templates/mediagoblin/auth/login.html @@ -20,25 +20,22 @@ {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} {% block mediagoblin_content %} - <h1>Login:</h1> <form action="{{ request.urlgen('mediagoblin.auth.login') }}" method="POST" enctype="multipart/form-data"> - - {% if login_failed %} - <p><i>Login failed!</i></p> - {% endif %} - - <table> - {{ wtforms_util.render_table(login_form) }} - <tr> - <td></td> - <td><input type="submit" value="submit" class="button"/></td> - </tr> - </table> - - {% if next %} - <input type="hidden" name="next" value="{{ next }}" class="button" /> - {% endif %} + <div class="login_box form_box"> + <h1>Log in</h1> + {% if login_failed %} + <div class="form_field_error">Login failed!</div> + {% endif %} + {{ wtforms_util.render_divs(login_form) }} + <div class="form_submit_buttons"> + <input type="submit" value="submit" class="button"/> + </div> + {% if next %} + <input type="hidden" name="next" value="{{ next }}" class="button" /> + {% endif %} + <p>Don't have an account yet? <a href="{{ request.urlgen('mediagoblin.auth.register') }}">Create one here!</a></p> + </div> </form> {% endblock %} diff --git a/mediagoblin/templates/mediagoblin/auth/register.html b/mediagoblin/templates/mediagoblin/auth/register.html index 610c7cc4..730d684d 100644 --- a/mediagoblin/templates/mediagoblin/auth/register.html +++ b/mediagoblin/templates/mediagoblin/auth/register.html @@ -20,14 +20,15 @@ {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} {% block mediagoblin_content %} + <form action="{{ request.urlgen('mediagoblin.auth.register') }}" method="POST" enctype="multipart/form-data"> - <table> - {{ wtforms_util.render_table(register_form) }} - <tr> - <td></td> - <td><input type="submit" value="submit" class="button" /></td> - </tr> - </table> + <div class="register_box form_box"> + <h1>Create an account!</h1> + {{ wtforms_util.render_divs(register_form) }} + <div class="form_submit_buttons"> + <input type="submit" value="submit" class="button" /> + </div> + </div> </form> {% endblock %} diff --git a/mediagoblin/templates/mediagoblin/auth/resent_verification_email.html b/mediagoblin/templates/mediagoblin/auth/resent_verification_email.html new file mode 100644 index 00000000..da3a9e99 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/auth/resent_verification_email.html @@ -0,0 +1,24 @@ +{# +# 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> + Resent your verification email. + </p> +{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/auth/verification_needed.html b/mediagoblin/templates/mediagoblin/auth/verification_needed.html new file mode 100644 index 00000000..4104da19 --- /dev/null +++ b/mediagoblin/templates/mediagoblin/auth/verification_needed.html @@ -0,0 +1,29 @@ +{# +# 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> + Verfication needed!<br /> + Please check your email to verify your account. + </p> + + <p> + Still haven't received an email? <a href="{{ request.urlgen('mediagoblin.auth.resend_verification') }}">Click here to resend it.</a> + </p> +{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/base.html b/mediagoblin/templates/mediagoblin/base.html index b0c88a13..704e5aa7 100644 --- a/mediagoblin/templates/mediagoblin/base.html +++ b/mediagoblin/templates/mediagoblin/base.html @@ -17,7 +17,7 @@ #} <html> <head> - <title>{% block title %}MediaGoblin{% endblock title %}</title> + <title>{% block title %}GNU MediaGoblin{% endblock title %}</title> <link rel="stylesheet" type="text/css" href="{{ request.staticdirect('/css/base.css') }}"/> {% block mediagoblin_head %} @@ -30,13 +30,12 @@ <div class="mediagoblin_header"> <div class="mediagoblin_container"> {% block mediagoblin_logo %} - <a href="{{ request.urlgen('index') }}"><img src="{{ request.staticdirect('/images/icon.png') }}" class="icon" /></a> - {% endblock %}{% block mediagoblin_header_title %}GNU MediaGoblin Home{% endblock %} + <a class="mediagoblin_logo" href="{{ request.urlgen('index') }}"></a> + {% endblock %}{% block mediagoblin_header_title %}{% endblock %} <div class="mediagoblin_header_right"> {% if request.user %} - Welcome {{ request.user['username'] }}! -- - <a href="{{ request.urlgen('mediagoblin.auth.logout') }}"> - Logout</a> + {{ request.user['username'] }}'s account + (<a href="{{ request.urlgen('mediagoblin.auth.logout') }}">logout</a>) {% else %} <a href="{{ request.urlgen('mediagoblin.auth.login') }}"> Login</a> diff --git a/mediagoblin/templates/mediagoblin/root.html b/mediagoblin/templates/mediagoblin/root.html index 05926687..e5344e08 100644 --- a/mediagoblin/templates/mediagoblin/root.html +++ b/mediagoblin/templates/mediagoblin/root.html @@ -41,15 +41,7 @@ {# temporarily, an "image gallery" that isn't one really ;) #} <div> - <ul> - {% for entry in media_entries %} - <li> - <a href="{{ entry.url_for_self(request.urlgen) }}"> - <img src="{{ request.app.public_store.file_url( - entry['media_files']['thumb']) }}" /></a> - </li> - {% endfor %} - </ul> + {% include "mediagoblin/utils/object_gallery.html" %} </div> {% endblock %} diff --git a/mediagoblin/templates/mediagoblin/submit/start.html b/mediagoblin/templates/mediagoblin/submit/start.html index 8fdbe4ed..75c31df4 100644 --- a/mediagoblin/templates/mediagoblin/submit/start.html +++ b/mediagoblin/templates/mediagoblin/submit/start.html @@ -20,16 +20,15 @@ {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} {% block mediagoblin_content %} - <h1>Submit yer media</h1> <form action="{{ request.urlgen('mediagoblin.submit.start') }}" method="POST" enctype="multipart/form-data"> - <table> - {{ wtforms_util.render_table(submit_form) }} - <tr> - <td></td> - <td><input type="submit" value="submit" class="button" /></td> - </tr> - </table> + <div class="submit_box form_box"> + <h1>Submit yer media</h1> + {{ wtforms_util.render_divs(submit_form) }} + <div class="form_submit_buttons"> + <input type="submit" value="submit" class="button" /> + </div> + </div> </form> {% endblock %} diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index f13c32e3..b26e2514 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -20,32 +20,22 @@ {# temporarily, an "image gallery" that isn't one really ;) #} {% if media %} - <h1> - Media details for - <a href="{{ request.urlgen( - 'mediagoblin.user_pages.user_home', - user=media.uploader().username) }}"> - {{- media.uploader().username }}</a> - / {{media.title}} - </h1> - <div> - <img src="{{ request.app.public_store.file_url( + <img class="media_image" src="{{ request.app.public_store.file_url( media.media_files.main) }}" /> - <br /> - Uploaded on + <h1> + {{media.title}} + </h1> + <p>{{ media.description }}</p> + <p>Uploaded on {{ "%4d-%02d-%02d"|format(media.created.year, media.created.month, media.created.day) }} by <a href="{{ request.urlgen('mediagoblin.user_pages.user_home', user= media.uploader().username) }}"> - {{- media.uploader().username }}</a> - <br /> - Description: {{ media.description }} - <br /> - <a href="{{ request.urlgen('mediagoblin.edit.edit_media', - media= media._id) }}">Edit</a> - </div> + {{- media.uploader().username }}</a></p> + <p><a href="{{ request.urlgen('mediagoblin.edit.edit_media', + media= media._id) }}">Edit</a></p> {% else %} <p>Sorry, no such media found.<p/> {% endif %} -{% endblock %} +{% endblock %} diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html index 2d09f685..b3708c85 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/user.html +++ b/mediagoblin/templates/mediagoblin/user_pages/user.html @@ -28,11 +28,8 @@ {% if user %} <h1>User page for '{{ user.username }}'</h1> - <ul> - - {% include "mediagoblin/utils/object_gallery.html" %} + {% include "mediagoblin/utils/object_gallery.html" %} - </ul> <a href={{ request.urlgen( 'mediagoblin.user_pages.atom_feed', user=user.username) }}> atom feed</a> diff --git a/mediagoblin/templates/mediagoblin/utils/object_gallery.html b/mediagoblin/templates/mediagoblin/utils/object_gallery.html index 30497f47..c9c3e0db 100644 --- a/mediagoblin/templates/mediagoblin/utils/object_gallery.html +++ b/mediagoblin/templates/mediagoblin/utils/object_gallery.html @@ -21,7 +21,7 @@ {% if media_entries %} <ul> {% for entry in media_entries %} - <li> + <li class="media_thumbnail"> <a href="{{ entry.url_for_self(request.urlgen) }}"> <img src="{{ request.app.public_store.file_url( entry['media_files']['thumb']) }}" /></a> diff --git a/mediagoblin/templates/mediagoblin/utils/wtforms.html b/mediagoblin/templates/mediagoblin/utils/wtforms.html index 15556936..9adf8e53 100644 --- a/mediagoblin/templates/mediagoblin/utils/wtforms.html +++ b/mediagoblin/templates/mediagoblin/utils/wtforms.html @@ -15,6 +15,28 @@ # 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/>. #} + +{# Auto-render a form as a series of divs #} +{% macro render_divs(form) -%} + {% for field in form %} + <div class="form_field_box"> + <div class="form_field_label">{{ field.label }}</div> + {% if field.description -%} + <div class="form_field_description">{{ field.description }}</div> + {%- endif %} + <div class="form_field_input">{{ field }}</div> + {%- if field.errors -%} + {% for error in field.errors %} + <div class="form_field_error"> + {{ error }} + </div> + {% endfor %} + {%- endif %} + </div> + {% endfor %} +{%- endmacro %} + +{# Auto-render a form as a table #} {% macro render_table(form) -%} {% for field in form %} <tr> @@ -18,7 +18,7 @@ from setuptools import setup, find_packages setup( name = "mediagoblin", - version = "0.0.1", + version = "0.0.2", packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), zip_safe=False, # scripts and dependencies @@ -45,7 +45,7 @@ setup( test_suite='nose.collector', license = 'AGPLv3', - author = 'Christopher Webber', + author = 'Free Software Foundation and contributors', author_email = 'cwebber@gnu.org', entry_points = """\ [console_scripts] |