diff --git a/bookwyrm/templates/login.html b/bookwyrm/templates/login.html
index 87a97f3b0..683422109 100644
--- a/bookwyrm/templates/login.html
+++ b/bookwyrm/templates/login.html
@@ -38,7 +38,7 @@
{% if site.allow_registration %}
Create an Account
-
{% else %}
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py
index ce0e26b74..209dac019 100644
--- a/bookwyrm/urls.py
+++ b/bookwyrm/urls.py
@@ -42,8 +42,10 @@ urlpatterns = [
# TODO: re_path(r'^.well-known/host-meta/?$', incoming.host_meta),
# TODO: robots.txt
- # ui vviews
+ # authentication
re_path(r'^login/?$', views.LoginView.as_view()),
+ re_path(r'^register/?$', views.RegisterView.as_view()),
+
re_path(r'^about/?$', vviews.about_page),
re_path(r'^password-reset/?$', vviews.password_reset_request),
re_path(r'^password-reset/(?P[A-Za-z0-9]+)/?$', vviews.password_reset),
@@ -91,7 +93,6 @@ urlpatterns = [
# internal action endpoints
re_path(r'^logout/?$', actions.user_logout),
- re_path(r'^user-register/?$', actions.register),
re_path(r'^reset-password-request/?$', actions.password_reset_request),
re_path(r'^reset-password/?$', actions.password_reset),
re_path(r'^change-password/?$', actions.password_change),
diff --git a/bookwyrm/view_actions.py b/bookwyrm/view_actions.py
index 249e62700..d87798f00 100644
--- a/bookwyrm/view_actions.py
+++ b/bookwyrm/view_actions.py
@@ -25,57 +25,6 @@ from bookwyrm.settings import DOMAIN
from bookwyrm.vviews import get_user_from_username, get_edition
-@require_POST
-def register(request):
- ''' join the server '''
- if not models.SiteSettings.get().allow_registration:
- invite_code = request.POST.get('invite_code')
-
- if not invite_code:
- raise PermissionDenied
-
- invite = get_object_or_404(models.SiteInvite, code=invite_code)
- if not invite.valid():
- raise PermissionDenied
- else:
- invite = None
-
- form = forms.RegisterForm(request.POST)
- errors = False
- if not form.is_valid():
- errors = True
-
- localname = form.data['localname'].strip()
- email = form.data['email']
- password = form.data['password']
-
- # check localname and email uniqueness
- if models.User.objects.filter(localname=localname).first():
- form.errors['localname'] = ['User with this username already exists']
- errors = True
-
- if errors:
- data = {
- 'login_form': forms.LoginForm(),
- 'register_form': form,
- 'invite': invite,
- 'valid': invite.valid() if invite else True,
- }
- if invite:
- return TemplateResponse(request, 'invite.html', data)
- return TemplateResponse(request, 'login.html', data)
-
- username = '%s@%s' % (localname, DOMAIN)
- user = models.User.objects.create_user(
- username, email, password, localname=localname, local=True)
- if invite:
- invite.times_used += 1
- invite.save()
-
- login(request, user)
- return redirect('/')
-
-
@login_required
@require_GET
def user_logout(request):
diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py
index 0a5d9900a..7a92fa4c3 100644
--- a/bookwyrm/views/__init__.py
+++ b/bookwyrm/views/__init__.py
@@ -1,2 +1,2 @@
''' make sure all our nice views are available '''
-from .authentication import LoginView
+from .authentication import LoginView, RegisterView
diff --git a/bookwyrm/views/authentication.py b/bookwyrm/views/authentication.py
index b789e9cfb..8c7d21d1c 100644
--- a/bookwyrm/views/authentication.py
+++ b/bookwyrm/views/authentication.py
@@ -1,17 +1,20 @@
''' class views for login/register/password management views '''
from django.contrib.auth import authenticate, login
-from django.shortcuts import redirect
+from django.core.exceptions import PermissionDenied
+from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.utils import timezone
from django.views import View
-from bookwyrm import forms
+from bookwyrm import forms, models
from bookwyrm.settings import DOMAIN
+# pylint: disable= no-self-use
class LoginView(View):
''' authenticate an existing user '''
def get(self, request):
+ ''' login page '''
if request.user.is_authenticated:
return redirect('/')
# send user to the login page
@@ -23,6 +26,7 @@ class LoginView(View):
return TemplateResponse(request, 'login.html', data)
def post(self, request):
+ ''' authentication action '''
login_form = forms.LoginForm(request.POST)
localname = login_form.data['localname']
@@ -43,3 +47,56 @@ class LoginView(View):
'register_form': register_form
}
return TemplateResponse(request, 'login.html', data)
+
+
+class RegisterView(View):
+ ''' register a user '''
+ def post(self, request):
+ ''' join the server '''
+ if not models.SiteSettings.get().allow_registration:
+ invite_code = request.POST.get('invite_code')
+
+ if not invite_code:
+ raise PermissionDenied
+
+ invite = get_object_or_404(models.SiteInvite, code=invite_code)
+ if not invite.valid():
+ raise PermissionDenied
+ else:
+ invite = None
+
+ form = forms.RegisterForm(request.POST)
+ errors = False
+ if not form.is_valid():
+ errors = True
+
+ localname = form.data['localname'].strip()
+ email = form.data['email']
+ password = form.data['password']
+
+ # check localname and email uniqueness
+ if models.User.objects.filter(localname=localname).first():
+ form.errors['localname'] = [
+ 'User with this username already exists']
+ errors = True
+
+ if errors:
+ data = {
+ 'login_form': forms.LoginForm(),
+ 'register_form': form,
+ 'invite': invite,
+ 'valid': invite.valid() if invite else True,
+ }
+ if invite:
+ return TemplateResponse(request, 'invite.html', data)
+ return TemplateResponse(request, 'login.html', data)
+
+ username = '%s@%s' % (localname, DOMAIN)
+ user = models.User.objects.create_user(
+ username, email, password, localname=localname, local=True)
+ if invite:
+ invite.times_used += 1
+ invite.save()
+
+ login(request, user)
+ return redirect('/')