mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-22 22:48:03 +01:00
Cleanup activation views
This commit is contained in:
parent
71faf4dbe1
commit
e6d2568686
2 changed files with 1 additions and 32 deletions
|
@ -18,11 +18,10 @@ from django.conf.urls.static import static
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth import logout
|
from django.contrib.auth import logout
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from django.views.generic import TemplateView
|
|
||||||
from django_registration.backends.activation.views import RegistrationView
|
from django_registration.backends.activation.views import RegistrationView
|
||||||
|
|
||||||
from common.forms import RegistrationForm
|
from common.forms import RegistrationForm
|
||||||
from common.views import ActivationView, hello_world
|
from common.views import hello_world
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("logout/", logout, {"next_page": settings.LOGOUT_REDIRECT_URL}, name="logout"),
|
path("logout/", logout, {"next_page": settings.LOGOUT_REDIRECT_URL}, name="logout"),
|
||||||
|
@ -31,18 +30,6 @@ urlpatterns = [
|
||||||
RegistrationView.as_view(form_class=RegistrationForm),
|
RegistrationView.as_view(form_class=RegistrationForm),
|
||||||
name="django_registration_register",
|
name="django_registration_register",
|
||||||
),
|
),
|
||||||
path(
|
|
||||||
"accounts/activate/complete/",
|
|
||||||
TemplateView.as_view(
|
|
||||||
template_name="django_registration/activation_complete.html"
|
|
||||||
),
|
|
||||||
name="django_registration_activation_complete",
|
|
||||||
),
|
|
||||||
path(
|
|
||||||
"accounts/activate/<str:activation_key>/",
|
|
||||||
ActivationView.as_view(),
|
|
||||||
name="django_registration_activate",
|
|
||||||
),
|
|
||||||
path("accounts/", include("django_registration.backends.activation.urls")),
|
path("accounts/", include("django_registration.backends.activation.urls")),
|
||||||
path("accounts/", include("django.contrib.auth.urls")),
|
path("accounts/", include("django.contrib.auth.urls")),
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
|
|
|
@ -1,27 +1,9 @@
|
||||||
from django.contrib.auth.models import Permission
|
|
||||||
from django.core.handlers.wsgi import WSGIRequest
|
from django.core.handlers.wsgi import WSGIRequest
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
from django_registration.backends.activation.views import (
|
|
||||||
ActivationView as BaseActivationView,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def hello_world(request: WSGIRequest) -> HttpResponse:
|
def hello_world(request: WSGIRequest) -> HttpResponse:
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
return redirect("character:list")
|
return redirect("character:list")
|
||||||
return render(request, "common/hello.html")
|
return render(request, "common/hello.html")
|
||||||
|
|
||||||
|
|
||||||
class ActivationView(BaseActivationView):
|
|
||||||
def activate(self, *args, **kwargs):
|
|
||||||
user = super().activate(*args, **kwargs)
|
|
||||||
perm = Permission.objects.get(
|
|
||||||
content_type__app_label="character",
|
|
||||||
content_type__model="character",
|
|
||||||
codename="add_character",
|
|
||||||
)
|
|
||||||
user.user_permissions.add(perm)
|
|
||||||
user.is_staff = True
|
|
||||||
user.save()
|
|
||||||
return user
|
|
||||||
|
|
Loading…
Reference in a new issue