mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-20 17:41:55 +02:00
Invalidate registrations, fix profile creation
This commit is contained in:
@ -10,7 +10,7 @@ def save_user_profile(instance, created, raw, **_kwargs):
|
||||
# When provisionning data, do not try to autocreate
|
||||
return
|
||||
|
||||
if created:
|
||||
if created and instance.is_active:
|
||||
from .models import Profile
|
||||
Profile.objects.get_or_create(user=instance)
|
||||
instance.profile.save()
|
||||
instance.profile.save()
|
||||
|
@ -102,11 +102,8 @@ class UserUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView):
|
||||
return super().form_valid(form)
|
||||
|
||||
def get_success_url(self, **kwargs):
|
||||
if kwargs:
|
||||
return reverse_lazy('member:user_detail',
|
||||
kwargs={'pk': kwargs['id']})
|
||||
else:
|
||||
return reverse_lazy('member:user_detail', args=(self.object.id,))
|
||||
url = 'member:user_detail' if self.object.profile.registration_valid else 'registration:future_user_detail'
|
||||
return reverse_lazy(url, args=(self.object.id,))
|
||||
|
||||
|
||||
class UserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
||||
@ -117,6 +114,12 @@ class UserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
||||
context_object_name = "user_object"
|
||||
template_name = "member/profile_detail.html"
|
||||
|
||||
def get_queryset(self, **kwargs):
|
||||
"""
|
||||
We can't display information of a not registered user.
|
||||
"""
|
||||
return super().get_queryset().filter(profile__registration_valid=True)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
user = context['user_object']
|
||||
|
@ -8,7 +8,9 @@ from . import views
|
||||
app_name = 'registration'
|
||||
urlpatterns = [
|
||||
path('signup/', views.UserCreateView.as_view(), name="signup"),
|
||||
path('validate_email/sent', views.UserActivationEmailSentView.as_view(), name='account_activation_sent'),
|
||||
path('validate_email/<uidb64>/<token>', views.UserActivateView.as_view(), name='account_activation'),
|
||||
path('validate_email/sent/', views.UserActivationEmailSentView.as_view(), name='account_activation_sent'),
|
||||
path('validate_email/<uidb64>/<token>/', views.UserActivateView.as_view(), name='account_activation'),
|
||||
path('validate_user/', views.FutureUserListView.as_view(), name="future_user_list"),
|
||||
path('validate_user/<int:pk>/', views.FutureUserDetailView.as_view(), name="future_user_detail"),
|
||||
path('validate_user/<int:pk>/invalidate/', views.FutureUserInvalidateView.as_view(), name="future_user_invalidate"),
|
||||
]
|
||||
|
@ -5,15 +5,18 @@ from django.conf import settings
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.shortcuts import resolve_url
|
||||
from django.shortcuts import resolve_url, redirect
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.http import urlsafe_base64_decode
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views import View
|
||||
from django.views.decorators.csrf import csrf_protect
|
||||
from django.views.generic import CreateView, TemplateView
|
||||
from django.views.generic import CreateView, TemplateView, DetailView
|
||||
from django_tables2 import SingleTableView
|
||||
from member.forms import ProfileForm
|
||||
from member.models import Profile
|
||||
from permission.backends import PermissionBackend
|
||||
from permission.views import ProtectQuerysetMixin
|
||||
|
||||
from .forms import SignUpForm
|
||||
@ -42,15 +45,19 @@ class UserCreateView(CreateView):
|
||||
If the form is valid, then the user is created with is_active set to False
|
||||
so that the user cannot log in until the email has been validated.
|
||||
"""
|
||||
profile_form = ProfileForm(self.request.POST)
|
||||
profile_form = ProfileForm(data=self.request.POST)
|
||||
if not profile_form.is_valid():
|
||||
return self.form_invalid(form)
|
||||
|
||||
user = form.save(commit=False)
|
||||
user.is_active = False
|
||||
user.profile = profile_form.save(commit=False)
|
||||
profile_form.instance.user = user
|
||||
profile = profile_form.save(commit=False)
|
||||
user.profile = profile
|
||||
user.save()
|
||||
user.profile.save()
|
||||
user.refresh_from_db()
|
||||
profile.user = user
|
||||
profile.save()
|
||||
|
||||
user.profile.send_email_validation_link()
|
||||
|
||||
@ -86,7 +93,6 @@ class UserActivateView(TemplateView):
|
||||
return self.render_to_response(self.get_context_data())
|
||||
|
||||
def get_user(self, uidb64):
|
||||
print(uidb64)
|
||||
try:
|
||||
# urlsafe_base64_decode() decodes to bytestring
|
||||
uid = urlsafe_base64_decode(uidb64).decode()
|
||||
@ -131,3 +137,32 @@ class FutureUserListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableVi
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class FutureUserDetailView(ProtectQuerysetMixin, LoginRequiredMixin, DetailView):
|
||||
"""
|
||||
Affiche les informations sur un utilisateur, sa note, ses clubs...
|
||||
"""
|
||||
model = User
|
||||
context_object_name = "user_object"
|
||||
template_name = "registration/future_profile_detail.html"
|
||||
|
||||
def get_queryset(self, **kwargs):
|
||||
"""
|
||||
We only display information of a not registered user.
|
||||
"""
|
||||
return super().get_queryset().filter(profile__registration_valid=False)
|
||||
|
||||
|
||||
class FutureUserInvalidateView(ProtectQuerysetMixin, LoginRequiredMixin, View):
|
||||
"""
|
||||
Affiche les informations sur un utilisateur, sa note, ses clubs...
|
||||
"""
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
user = User.objects.filter(profile__registration_valid=False)\
|
||||
.filter(PermissionBackend.filter_queryset(request.user, User, "change", "is_valid"))\
|
||||
.get(pk=self.kwargs["pk"])
|
||||
|
||||
user.delete()
|
||||
|
||||
return redirect('registration:future_user_list')
|
||||
|
@ -53,7 +53,7 @@ ProductFormSet = forms.inlineformset_factory(
|
||||
|
||||
class ProductFormSetHelper(FormHelper):
|
||||
"""
|
||||
Specify some template informations for the product form.
|
||||
Specify some template information for the product form.
|
||||
"""
|
||||
|
||||
def __init__(self, form=None):
|
||||
|
Reference in New Issue
Block a user