diff options
-rw-r--r-- | mediagoblin/auth/views.py | 13 | ||||
-rw-r--r-- | mediagoblin/db/models.py | 3 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/base.html | 2 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/user_pages/user.html | 2 |
4 files changed, 13 insertions, 7 deletions
diff --git a/mediagoblin/auth/views.py b/mediagoblin/auth/views.py index c3d24c74..8775d4c4 100644 --- a/mediagoblin/auth/views.py +++ b/mediagoblin/auth/views.py @@ -14,6 +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 re from webob import Response, exc @@ -31,8 +32,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 +45,8 @@ def register(request): else: # Create the user entry = request.db.User() - entry['username'] = request.POST['username'] + entry['username'] = request.POST['username'].lower() + entry['username_repr'] = request.POST['username'] entry['email'] = request.POST['email'] entry['pw_hash'] = auth_lib.bcrypt_gen_password_hash( request.POST['password']) @@ -61,7 +66,7 @@ def register(request): # example "GNU MediaGoblin @ Wandborg - [...]". 'GNU MediaGoblin - Verify email', email_template.render( - username=entry['username'], + username=entry['username_repr'], verification_url='http://{host}{uri}?userid={userid}&token={verification_key}'.format( host=request.host, uri=request.urlgen('mediagoblin.auth.verify_email'), @@ -101,7 +106,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 diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index 37420834..0b4390d7 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -38,6 +38,7 @@ class User(Document): structure = { 'username': unicode, + 'username_repr': unicode, 'email': unicode, 'created': datetime.datetime, 'plugin_data': dict, # plugins can dump stuff here. @@ -48,7 +49,7 @@ class User(Document): 'is_admin': bool, } - required_fields = ['username', 'created', 'pw_hash', 'email'] + required_fields = ['username', 'username_repr', 'created', 'pw_hash', 'email'] default_values = { 'created': datetime.datetime.utcnow, diff --git a/mediagoblin/templates/mediagoblin/base.html b/mediagoblin/templates/mediagoblin/base.html index 704e5aa7..df803196 100644 --- a/mediagoblin/templates/mediagoblin/base.html +++ b/mediagoblin/templates/mediagoblin/base.html @@ -34,7 +34,7 @@ {% endblock %}{% block mediagoblin_header_title %}{% endblock %} <div class="mediagoblin_header_right"> {% if request.user %} - {{ request.user['username'] }}'s account + {{ request.user['username_repr'] }}'s account (<a href="{{ request.urlgen('mediagoblin.auth.logout') }}">logout</a>) {% else %} <a href="{{ request.urlgen('mediagoblin.auth.login') }}"> diff --git a/mediagoblin/templates/mediagoblin/user_pages/user.html b/mediagoblin/templates/mediagoblin/user_pages/user.html index 2d09f685..b9c98568 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/user.html +++ b/mediagoblin/templates/mediagoblin/user_pages/user.html @@ -26,7 +26,7 @@ {% block mediagoblin_content -%} {% if user %} - <h1>User page for '{{ user.username }}'</h1> + <h1>User page for '{{ user.username_repr }}'</h1> <ul> |