mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +00:00
Adds registration
This commit is contained in:
parent
4007ed8827
commit
3d09d355eb
8 changed files with 59 additions and 15 deletions
|
@ -23,7 +23,7 @@ a good idea for the long term but it's what I'm doing right now).
|
|||
``` bash
|
||||
./rebuilddb.sh
|
||||
```
|
||||
This creates two users, `mouse@your-domain.com` with password `password123` and `rat@your-domain.com` with password `ratword`.
|
||||
This creates two users, `mouse` with password `password123` and `rat` with password `ratword`.
|
||||
|
||||
And go to the app at `localhost:8000`
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ def webfinger(request):
|
|||
@csrf_exempt
|
||||
def shared_inbox(request):
|
||||
''' incoming activitypub events '''
|
||||
# TODO: this is just a dupe of inbox but there's gotta be a reason??
|
||||
if request.method == 'GET':
|
||||
return HttpResponseNotFound()
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.0.2 on 2020-01-29 01:16
|
||||
# Generated by Django 3.0.2 on 2020-01-29 02:56
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.auth.models
|
||||
|
@ -32,13 +32,13 @@ class Migration(migrations.Migration):
|
|||
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
|
||||
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
|
||||
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
|
||||
('private_key', models.TextField(blank=True, null=True)),
|
||||
('public_key', models.TextField(blank=True, null=True)),
|
||||
('private_key', models.TextField(blank=True, null=True, unique=True)),
|
||||
('public_key', models.TextField(blank=True, null=True, unique=True)),
|
||||
('api_key', models.CharField(blank=True, max_length=255, null=True)),
|
||||
('actor', models.CharField(max_length=255)),
|
||||
('inbox', models.CharField(max_length=255)),
|
||||
('actor', models.CharField(max_length=255, unique=True)),
|
||||
('inbox', models.CharField(max_length=255, unique=True)),
|
||||
('shared_inbox', models.CharField(max_length=255)),
|
||||
('outbox', models.CharField(max_length=255)),
|
||||
('outbox', models.CharField(max_length=255, unique=True)),
|
||||
('summary', models.TextField(blank=True, null=True)),
|
||||
('local', models.BooleanField(default=True)),
|
||||
('localname', models.CharField(blank=True, max_length=255, null=True, unique=True)),
|
||||
|
@ -99,7 +99,7 @@ class Migration(migrations.Migration):
|
|||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('activitypub_id', models.CharField(max_length=255)),
|
||||
('identifier', models.CharField(max_length=255)),
|
||||
('identifier', models.CharField(max_length=255, unique=True)),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('editable', models.BooleanField(default=True)),
|
||||
('shelf_type', models.CharField(default='custom', max_length=100)),
|
||||
|
|
|
@ -13,13 +13,13 @@ from fedireads.settings import DOMAIN, OL_URL
|
|||
|
||||
class User(AbstractUser):
|
||||
''' a user who wants to read books '''
|
||||
private_key = models.TextField(blank=True, null=True)
|
||||
public_key = models.TextField(blank=True, null=True)
|
||||
private_key = models.TextField(blank=True, null=True, unique=True)
|
||||
public_key = models.TextField(blank=True, null=True, unique=True)
|
||||
api_key = models.CharField(max_length=255, blank=True, null=True)
|
||||
actor = models.CharField(max_length=255)
|
||||
inbox = models.CharField(max_length=255)
|
||||
actor = models.CharField(max_length=255, unique=True)
|
||||
inbox = models.CharField(max_length=255, unique=True)
|
||||
shared_inbox = models.CharField(max_length=255)
|
||||
outbox = models.CharField(max_length=255)
|
||||
outbox = models.CharField(max_length=255, unique=True)
|
||||
summary = models.TextField(blank=True, null=True)
|
||||
local = models.BooleanField(default=True)
|
||||
localname = models.CharField(
|
||||
|
@ -151,7 +151,7 @@ class Note(Activity):
|
|||
|
||||
class Shelf(models.Model):
|
||||
activitypub_id = models.CharField(max_length=255)
|
||||
identifier = models.CharField(max_length=255)
|
||||
identifier = models.CharField(max_length=255, unique=True)
|
||||
name = models.CharField(max_length=100)
|
||||
user = models.ForeignKey('User', on_delete=models.PROTECT)
|
||||
editable = models.BooleanField(default=True)
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
</label>
|
||||
<button type="submit">Log in</button>
|
||||
</form>
|
||||
<a href="/register/">Create a new account</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
23
fedireads/templates/register.html
Normal file
23
fedireads/templates/register.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% block content %}
|
||||
<div id="content">
|
||||
<div>
|
||||
<form name="register" method="post">
|
||||
<label for="username">Username:
|
||||
<input type="text" name="username"></input>
|
||||
</label>
|
||||
|
||||
<label for="email">Email address:
|
||||
<input type="text" name="email"></input>
|
||||
</label>
|
||||
|
||||
<label for="password">Password:
|
||||
<input type="password" name="password"></input>
|
||||
</label>
|
||||
<button type="submit">Create account</button>
|
||||
</form>
|
||||
|
||||
<a href="/login/">Log in with existing account</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -18,6 +18,7 @@ urlpatterns = [
|
|||
|
||||
# ui views
|
||||
path('', views.home),
|
||||
path('register/', views.register),
|
||||
path('login/', views.user_login),
|
||||
path('logout/', views.user_logout),
|
||||
path('user/<str:username>', views.user_profile),
|
||||
|
|
|
@ -9,6 +9,7 @@ from django.views.decorators.csrf import csrf_exempt
|
|||
import re
|
||||
|
||||
from fedireads import models, openlibrary, outgoing as api
|
||||
from fedireads.settings import DOMAIN
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -45,12 +46,12 @@ def home(request):
|
|||
def user_login(request):
|
||||
''' authentication '''
|
||||
# send user to the login page
|
||||
# TODO: login with localname or email
|
||||
if request.method == 'GET':
|
||||
return TemplateResponse(request, 'login.html')
|
||||
|
||||
# authenticate user
|
||||
username = request.POST['username']
|
||||
username = '%s@%s' % (username, DOMAIN)
|
||||
password = request.POST['password']
|
||||
user = authenticate(request, username=username, password=password)
|
||||
if user is not None:
|
||||
|
@ -67,6 +68,22 @@ def user_logout(request):
|
|||
return redirect('/')
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def register(request):
|
||||
''' join the server '''
|
||||
if request.method == 'GET':
|
||||
return TemplateResponse(request, 'register.html')
|
||||
|
||||
username = request.POST['username']
|
||||
password = request.POST['password']
|
||||
email = request.POST['email']
|
||||
password = request.POST['password']
|
||||
|
||||
user = models.User.objects.create_user(username, email, password)
|
||||
login(request, user)
|
||||
return redirect('/')
|
||||
|
||||
|
||||
@login_required
|
||||
def user_profile(request, username):
|
||||
''' profile page for a user '''
|
||||
|
|
Loading…
Reference in a new issue