-
{% include 'snippets/about.html' with site_settings=site_settings %}
diff --git a/bookwyrm/templates/snippets/register_form.html b/bookwyrm/templates/snippets/register_form.html
index dfde08ab0..d6f5b98f8 100644
--- a/bookwyrm/templates/snippets/register_form.html
+++ b/bookwyrm/templates/snippets/register_form.html
@@ -2,19 +2,28 @@
+ {% for error in register_form.password.errors %}
+
{{ error | escape }}
+ {% endfor %}
diff --git a/bookwyrm/view_actions.py b/bookwyrm/view_actions.py
index 76983f11c..102ec4665 100644
--- a/bookwyrm/view_actions.py
+++ b/bookwyrm/view_actions.py
@@ -23,14 +23,15 @@ def user_login(request):
if request.method == 'GET':
return redirect('/login')
- register_form = forms.RegisterForm()
login_form = forms.LoginForm(request.POST)
+ register_form = forms.RegisterForm()
if not login_form.is_valid():
- return TemplateResponse(
- request,
- 'login.html',
- {'login_form': login_form, 'register_form': register_form}
- )
+ data = {
+ 'site_settings': models.SiteSettings.get(),
+ 'login_form': login_form,
+ 'register_form': register_form
+ }
+ return TemplateResponse(request, 'login.html', data)
username = login_form.data['username']
username = '%s@%s' % (username, DOMAIN)
@@ -39,7 +40,14 @@ def user_login(request):
if user is not None:
login(request, user)
return redirect(request.GET.get('next', '/'))
- return redirect('/login')
+
+ login_form.non_field_errors = 'Username or password are incorrect'
+ data = {
+ 'site_settings': models.SiteSettings.get(),
+ 'login_form': login_form,
+ 'register_form': register_form
+ }
+ return TemplateResponse(request, 'login.html', data)
def register(request):
@@ -61,13 +69,27 @@ def register(request):
invite = None
form = forms.RegisterForm(request.POST)
+ errors = False
if not form.is_valid():
- return redirect('/register/')
+ errors = True
username = form.data['username']
email = form.data['email']
password = form.data['password']
+ # check username and email uniqueness
+ if models.User.objects.filter(localname=username).first():
+ form.add_error('username', 'User with this username already exists')
+ errors = True
+
+ if errors:
+ data = {
+ 'site_settings': models.SiteSettings.get(),
+ 'login_form': forms.LoginForm(),
+ 'register_form': form
+ }
+ return TemplateResponse(request, 'login.html', data)
+
user = models.User.objects.create_user(username, email, password)
if invite:
invite.times_used += 1
diff --git a/celerywyrm/settings.py b/celerywyrm/settings.py
index 12688e060..c27072c2a 100644
--- a/celerywyrm/settings.py
+++ b/celerywyrm/settings.py
@@ -40,7 +40,8 @@ CELERY_RESULT_BACKEND = 'redis'
SECRET_KEY = '0a^0gpwjc1ap+lb$dinin=efc@e&_0%102$o3(>9e7lndiaw'
# SECURITY WARNING: don't run with debug turned on in production!
-DEBUG = True
+DEBUG = env.bool('DEBUG', True)
+
ALLOWED_HOSTS = []