-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(invite): add an
invite
app, that provides invite tokens
The `invite` app provides the logic to create tokens for user signup. A token can be created in the Django Admin interface and the used in the `/invite/<token>` route to create a user account. Once used, the token is deleted. Closes: #1293
- Loading branch information
Showing
8 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters