diff --git a/app/static/css/site.scss b/app/static/css/site.scss index dd1d666..9714140 100644 --- a/app/static/css/site.scss +++ b/app/static/css/site.scss @@ -142,3 +142,31 @@ nav.overlay { opacity: 0.8; } + +.login, .register { + margin-top: 16px; + margin-left: 24px; + textarea, + input { + padding: 4px; + margin-left: 0; + margin-top: 4px; + margin-bottom: 4px; + margin-right: 4px; + background: none; + color: white; + border: 1px solid green; + } + button { + margin-top: 4px; + background: black; + color: white; + border: solid 1px green; + padding: 8px; + } + button:hover, + button:active { + border: solid 1px lightgreen; + cursor: pointer; + } +} diff --git a/app/templates/base.html b/app/templates/base.html index 771aa3b..5147345 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -53,6 +53,8 @@ logout {% else %} login +
+ register {% endif %} diff --git a/app/templates/login.html b/app/templates/login.html index 9380368..7a8f8fe 100644 --- a/app/templates/login.html +++ b/app/templates/login.html @@ -7,8 +7,9 @@
{% csrf_token %} +
-
+
{{ error }}
diff --git a/app/user/views.py b/app/user/views.py index 2949f51..2da80d8 100644 --- a/app/user/views.py +++ b/app/user/views.py @@ -16,9 +16,15 @@ User = get_user_model() @ratelimit(method="POST", block=True, rate="5/m") def register(request): + context = default_context(request) response = {} + request_type = 'json' if request.method == "POST": - data = json.loads(request.body) + if "username" in request.POST and "password" in request.POST: + data = request.POST + request_type = 'html' + else: + data = json.loads(request.body) if User.objects.filter(username__iexact=data['username']).exists(): response['error'] = 'username not allowed' elif User.objects.filter(email__iexact=data['email']).exists(): @@ -33,8 +39,16 @@ def register(request): user = django.contrib.auth.authenticate(username=data['username'], password=data['password']) django.contrib.auth.login(request, user) response['user'] = user.username + if request_type == 'html': + if 'error' in response: + context['error'] = response['error'] + return render(request, 'register.html', context) + else: + return redirect('/') return render_to_json(response) else: + if request.user.is_authenticated: + return redirect('/') context = default_context(request) return render(request, 'register.html', context)