From e559a93f71c26f972055d0429054dfdbedd726b6 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 4 Oct 2020 14:24:08 -0700 Subject: [PATCH 1/3] Get celery debug settings from env --- celerywyrm/settings.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 = [] From e67feb929699434685840b6f5e6017a5024b600c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 4 Oct 2020 14:30:40 -0700 Subject: [PATCH 2/3] More room for the "about" section on login page --- bookwyrm/templates/login.html | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/bookwyrm/templates/login.html b/bookwyrm/templates/login.html index 00dcd431a..a91544b76 100644 --- a/bookwyrm/templates/login.html +++ b/bookwyrm/templates/login.html @@ -3,21 +3,7 @@
-
- {% if site_settings.allow_registration %} -

Create an Account

-
- {% include 'snippets/register_form.html' %} -
- {% else %} -

This instance is closed

-

Contact an administrator to get an invite

- {% endif %} -
-
- -
-
+

Log in

{% csrf_token %} @@ -43,6 +29,20 @@
+
+ {% if site_settings.allow_registration %} +

Create an Account

+
+ {% include 'snippets/register_form.html' %} +
+ {% else %} +

This instance is closed

+

Contact an administrator to get an invite

+ {% endif %} +
+
+ +
{% include 'snippets/about.html' with site_settings=site_settings %}
From 33f486e7eb39cb1eecf2998b34ca3e46bba9cb26 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 4 Oct 2020 15:10:34 -0700 Subject: [PATCH 3/3] Shows errors for login/register forms --- bookwyrm/templates/login.html | 9 +++++ .../templates/snippets/register_form.html | 13 ++++++- bookwyrm/view_actions.py | 38 +++++++++++++++---- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/bookwyrm/templates/login.html b/bookwyrm/templates/login.html index a91544b76..cbfd2b667 100644 --- a/bookwyrm/templates/login.html +++ b/bookwyrm/templates/login.html @@ -5,6 +5,9 @@

Log in

+ {% if login_form.non_field_errors %} +

{{ login_form.non_field_errors }}

+ {% endif %}
{% csrf_token %}
@@ -12,12 +15,18 @@
{{ login_form.username }}
+ {% for error in login_form.username.errors %} +

{{ error | escape }}

+ {% endfor %}
{{ login_form.password }}
+ {% for error in login_form.password.errors %} +

{{ error | escape }}

+ {% endfor %}
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.username.errors %} +

{{ error | escape }}

+ {% endfor %}
- + + {% for error in register_form.email.errors %} +

{{ error | escape }}

+ {% endfor %}
+ {% 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