this should fix #354
This commit is contained in:
parent
dfd18edadc
commit
ce72a1bb15
@ -14,6 +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 re
|
||||||
|
|
||||||
from webob import Response, exc
|
from webob import Response, exc
|
||||||
|
|
||||||
@ -31,8 +32,11 @@ def register(request):
|
|||||||
|
|
||||||
if request.method == 'POST' and register_form.validate():
|
if request.method == 'POST' and register_form.validate():
|
||||||
# TODO: Make sure the user doesn't exist already
|
# TODO: Make sure the user doesn't exist already
|
||||||
|
|
||||||
users_with_username = \
|
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:
|
if users_with_username:
|
||||||
register_form.username.errors.append(
|
register_form.username.errors.append(
|
||||||
@ -41,7 +45,8 @@ def register(request):
|
|||||||
else:
|
else:
|
||||||
# Create the user
|
# Create the user
|
||||||
entry = request.db.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['email'] = request.POST['email']
|
||||||
entry['pw_hash'] = auth_lib.bcrypt_gen_password_hash(
|
entry['pw_hash'] = auth_lib.bcrypt_gen_password_hash(
|
||||||
request.POST['password'])
|
request.POST['password'])
|
||||||
@ -61,7 +66,7 @@ def register(request):
|
|||||||
# example "GNU MediaGoblin @ Wandborg - [...]".
|
# example "GNU MediaGoblin @ Wandborg - [...]".
|
||||||
'GNU MediaGoblin - Verify email',
|
'GNU MediaGoblin - Verify email',
|
||||||
email_template.render(
|
email_template.render(
|
||||||
username=entry['username'],
|
username=entry['username_repr'],
|
||||||
verification_url='http://{host}{uri}?userid={userid}&token={verification_key}'.format(
|
verification_url='http://{host}{uri}?userid={userid}&token={verification_key}'.format(
|
||||||
host=request.host,
|
host=request.host,
|
||||||
uri=request.urlgen('mediagoblin.auth.verify_email'),
|
uri=request.urlgen('mediagoblin.auth.verify_email'),
|
||||||
@ -101,7 +106,7 @@ def login(request):
|
|||||||
|
|
||||||
if request.method == 'POST' and login_form.validate():
|
if request.method == 'POST' and login_form.validate():
|
||||||
user = request.db.User.one(
|
user = request.db.User.one(
|
||||||
{'username': request.POST['username']})
|
{'username': request.POST['username'].lower()})
|
||||||
|
|
||||||
if user and user.check_login(request.POST['password']):
|
if user and user.check_login(request.POST['password']):
|
||||||
# set up login in session
|
# set up login in session
|
||||||
|
@ -38,6 +38,7 @@ class User(Document):
|
|||||||
|
|
||||||
structure = {
|
structure = {
|
||||||
'username': unicode,
|
'username': unicode,
|
||||||
|
'username_repr': unicode,
|
||||||
'email': unicode,
|
'email': unicode,
|
||||||
'created': datetime.datetime,
|
'created': datetime.datetime,
|
||||||
'plugin_data': dict, # plugins can dump stuff here.
|
'plugin_data': dict, # plugins can dump stuff here.
|
||||||
@ -48,7 +49,7 @@ class User(Document):
|
|||||||
'is_admin': bool,
|
'is_admin': bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
required_fields = ['username', 'created', 'pw_hash', 'email']
|
required_fields = ['username', 'username_repr', 'created', 'pw_hash', 'email']
|
||||||
|
|
||||||
default_values = {
|
default_values = {
|
||||||
'created': datetime.datetime.utcnow,
|
'created': datetime.datetime.utcnow,
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
{% endblock %}{% block mediagoblin_header_title %}{% endblock %}
|
{% endblock %}{% block mediagoblin_header_title %}{% endblock %}
|
||||||
<div class="mediagoblin_header_right">
|
<div class="mediagoblin_header_right">
|
||||||
{% if request.user %}
|
{% if request.user %}
|
||||||
{{ request.user['username'] }}'s account
|
{{ request.user['username_repr'] }}'s account
|
||||||
(<a href="{{ request.urlgen('mediagoblin.auth.logout') }}">logout</a>)
|
(<a href="{{ request.urlgen('mediagoblin.auth.logout') }}">logout</a>)
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="{{ request.urlgen('mediagoblin.auth.login') }}">
|
<a href="{{ request.urlgen('mediagoblin.auth.login') }}">
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
{% block mediagoblin_content -%}
|
{% block mediagoblin_content -%}
|
||||||
{% if user %}
|
{% if user %}
|
||||||
<h1>User page for '{{ user.username }}'</h1>
|
<h1>User page for '{{ user.username_repr }}'</h1>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user