示例#1
0
文件: forms.py 项目: NathHense/itou
 def save(self, request, commit=True):
     siae = super().save(commit=commit)
     if commit:
         siae.set_coords(siae.address_on_one_line, post_code=siae.post_code)
         siae.created_by = request.user
         siae.source = Siae.SOURCE_USER_CREATED
         siae.save()
         membership = SiaeMembership()
         membership.user = request.user
         membership.siae = siae
         membership.is_siae_admin = True
         membership.save()
     return siae
示例#2
0
文件: tests.py 项目: NathHense/itou
 def test_any_new_signup_invalidates_past_token(self):
     """
     Tokens are based on siae.members.count() so that
     any new signup invalidates past tokens.
     """
     siae = Siae.objects.create()
     p0 = SiaeSignupTokenGenerator()
     tk1 = p0.make_token(siae)
     self.assertIs(p0.check_token(siae, tk1), True)
     user = User()
     user.save()
     membership = SiaeMembership()
     membership.user = user
     membership.siae = siae
     membership.save()
     self.assertIs(p0.check_token(siae, tk1), False)
示例#3
0
    def save(self, request):

        user = super().save(request)

        user.first_name = self.cleaned_data["first_name"]
        user.last_name = self.cleaned_data["last_name"]
        user.is_siae_staff = True
        user.save()

        siaes = Siae.active_objects.filter(siret=self.cleaned_data["siret"])

        for siae in siaes:
            membership = SiaeMembership()
            membership.user = user
            membership.siae = siae
            # The first member becomes an admin.
            membership.is_siae_admin = siae.members.count() == 0
            membership.save()

        return user
示例#4
0
文件: forms.py 项目: NathHense/itou
    def save(self, request):
        user = super().save(request)

        if self.check_siae_signup_credentials():
            siae = self.get_siae()
        else:
            raise RuntimeError("This should never happen. Attack attempted.")

        if siae.has_members:
            siae.new_signup_warning_email_to_existing_members(user).send()

        user.is_siae_staff = True
        user.save()

        membership = SiaeMembership()
        membership.user = user
        membership.siae = siae
        # Only the first member becomes an admin.
        membership.is_siae_admin = siae.active_members.count() == 0
        membership.save()

        return user
示例#5
0
    def save(self, request):
        # Avoid django-allauth to call its own often failing `generate_unique_username`
        # function by forcing a username.
        self.cleaned_data["username"] = User.generate_unique_username()
        # Create the user.
        user = super().save(request)

        if self.check_siae_signup_credentials():
            siae = self.get_siae()
        else:
            raise RuntimeError("This should never happen.")

        user.is_siae_staff = True
        user.save()

        membership = SiaeMembership()
        membership.user = user
        membership.siae = siae
        # Only the first member becomes an admin.
        membership.is_admin = siae.active_members.count() == 0
        membership.save()

        return user