Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

birger/feat invite #1436

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apis_core/invite/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin

from .models import InviteToken

admin.site.register(InviteToken)
28 changes: 28 additions & 0 deletions apis_core/invite/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.1.2 on 2024-11-27 12:21

import uuid

from django.db import migrations, models


class Migration(migrations.Migration):
initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="InviteToken",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
],
),
]
Empty file.
10 changes: 10 additions & 0 deletions apis_core/invite/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import uuid

from django.db import models


class InviteToken(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

def __str__(self):
return str(self.id)
15 changes: 15 additions & 0 deletions apis_core/invite/templates/invite.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends basetemplate|default:"base.html" %}
{% load crispy_forms_tags %}

{% block content %}
<div class="container">
<div class="mt-4">
<form method="post">
{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="login">
<input type="hidden" name="next" value="{{ next }}">
</form>
</div>
</div>
{% endblock content %}
7 changes: 7 additions & 0 deletions apis_core/invite/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path

from apis_core.invite.views import Invite

urlpatterns = [
path("invite/<uuid:invite>", Invite.as_view()),
]
25 changes: 25 additions & 0 deletions apis_core/invite/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.contrib import messages
from django.contrib.auth.forms import UserCreationForm
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.views.generic.edit import CreateView

from apis_core.invite.models import InviteToken


class Invite(CreateView):
form_class = UserCreationForm
template_name = "invite.html"

def setup(self, *args, **kwargs):
super().setup(*args, **kwargs)
self.invite = get_object_or_404(InviteToken, id=kwargs.get("invite"))

def form_valid(self, form):
ret = super().form_valid(form)
self.invite.delete()
messages.success(self.request, f"Created user {self.object}")
return ret

def get_success_url(self):
return reverse("apis_core:login")
4 changes: 4 additions & 0 deletions apis_core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
urlpatterns.append(path("", include("apis_core.documentation.urls")))


if "apis_core.invite" in settings.INSTALLED_APPS:
urlpatterns.append(path("", include("apis_core.invite.urls")))


urlpatterns.append(path("api/", include(router.urls)))
urlpatterns.append(path("api-auth/", include("rest_framework.urls")))

Expand Down