Beispiel #1
0
    def form_valid(self, form):
        request = self.request
        user = form.save(commit=False)

        if settings.DISABLE_USERNAME:
            # Set a temporary username
            user.username = get_random_string()
        else:
            user.username = form.cleaned_data['username']

        if settings.ENABLE_USER_ACTIVATION:
            user.is_active = False

        # Create a user record
        user.owner = request.user
        user.save()

        # Change the username to the "user_ID" form
        if settings.DISABLE_USERNAME:
            user.username = f'user_{user.id}'
            user.save()

        if settings.ENABLE_USER_ACTIVATION:
            code = get_random_string(20)

            act = Activation()
            act.code = code
            act.user = user
            act.save()

            send_activation_email(request, user.email, code)

            messages.success(
                request,
                f'You are signed up. To activate the account, follow the link sent to the mail.'
            )
        else:
            raw_password = form.cleaned_data['password1']

            user = authenticate(username=user.username, password=raw_password)
            login(request, user)
            messages.success(request, f'You are successfully signed up!')

        return redirect('student_list')
Beispiel #2
0
def organization_detail(request):
    organization = request.organization

    invite_form = InviteForm(data=request.POST or None,
                             organization=organization)
    if invite_form.is_valid():
        user = invite_form.save()
        activation = user.make_activation()
        send_activation_email(request, activation)

    members = organization.members.all()
    active_members_count = members.filter(is_active=True).count()
    logo_edit_form = OrganisationLogoForm()

    return render(request, 'organizations/organization_detail.html', {
        'object_list': members,
        'active_members_count': active_members_count,
        'organization': organization,
        'invite_form': invite_form,
        'logo_edit_form': logo_edit_form
    })
Beispiel #3
0
def registration_view(request):

    user_form = OwnerRegistrationForm(data=request.POST or None,
                                      prefix='owner')
    organization_form = OrganizationRegistrationForm(data=request.POST or None,
                                                     prefix='organization')
    if user_form.is_valid() and organization_form.is_valid():
        organization = organization_form.save()
        user = user_form.save(commit=False)
        user.organization = organization
        user.is_owner = True
        user.save()

        activation = user.make_activation()
        send_activation_email(request, activation)

        return redirect('organizations_registration_success')
    return render(request, 'organizations/registration.html', {
        'organization_form': organization_form,
        'user_form': user_form
    })
Beispiel #4
0
def registration_view(request):
    if request.method == 'GET':
        form = RegistrationForm()

        return render(request, 'accounts/registration.html', {'form': form})

    elif request.method == 'POST':

        form = RegistrationForm(request.POST)

        if form.is_valid():
            email = form.cleaned_data['email']
            heslo = form.cleaned_data['heslo']
            jmeno = form.cleaned_data['jmeno']
            prijmeni = form.cleaned_data['prijmeni']
            rodne_cislo = form.cleaned_data['rodne_cislo']
            telefon = form.cleaned_data['telefon']

            #TODO: Add more user info

            # check if user already exists
            try:
                User.objects.get(email=email)
                messages.error(request, u'Uživatel již existuje')
                return render(request, 'accounts/registration.html', {'form': form})
            except User.DoesNotExist:
                user, password = User.objects.create_user(email, heslo)
                send_activation_email(user)
                user.jmeno = jmeno
                user.prijmeni = prijmeni
                user.rodne_cislo = rodne_cislo
                user.telefon = telefon
                user.save()

                return render(request, 'accounts/registration.html',
                              {
                                  'success': True
                              })
        else:
            return render(request, 'accounts/registration.html', {'form': form})
Beispiel #5
0
def registration_view(request):

    user_form = OwnerRegistrationForm(data=request.POST or None,
                                      prefix='owner')
    organization_form = OrganizationRegistrationForm(
        data=request.POST or None, prefix='organization'
    )
    if user_form.is_valid() and organization_form.is_valid():
        organization = organization_form.save()
        user = user_form.save(commit=False)
        user.organization = organization
        user.is_owner = True
        user.save()

        activation = user.make_activation()
        send_activation_email(request, activation)

        return redirect('organizations_registration_success')
    return render(request, 'organizations/registration.html', {
        'organization_form': organization_form,
        'user_form': user_form
    })
Beispiel #6
0
def organization_detail(request):
    organization = request.organization

    invite_form = InviteForm(data=request.POST or None,
                             organization=organization)
    if invite_form.is_valid():
        user = invite_form.save()
        activation = user.make_activation()
        send_activation_email(request, activation)

    members = organization.members.all()
    active_members_count = members.filter(is_active=True).count()
    logo_edit_form = OrganisationLogoForm()

    return render(
        request, 'organizations/organization_detail.html', {
            'object_list': members,
            'active_members_count': active_members_count,
            'organization': organization,
            'invite_form': invite_form,
            'logo_edit_form': logo_edit_form
        })
Beispiel #7
0
    def clean(self):
        username = self.cleaned_data.get('username')
        password = self.cleaned_data.get('password')

        if username and password:
            self.user_cache = authenticate(username=username,
                password=password)
            if self.user_cache is None:
                raise forms.ValidationError(
                    self.error_messages['invalid_login'])
            elif not self.user_cache.is_active:
                activation_cache=ActivationCode.objects.get(user=self.user_cache).activation_code
                if send_activation_email(email=self.user_cache.email,username=self.user_cache.username,code=activation_cache):
                    raise forms.ValidationError(self.error_messages['inactive'])
                else:
                    raise forms.ValidationError(self.error_messages['send_mail_fail'])
        self.check_for_test_cookie()
        return self.cleaned_data
Beispiel #8
0
    def clean(self):
        username = self.cleaned_data.get('username')
        email = self.cleaned_data.get('email')
        password1 = self.cleaned_data.get('password1')
        password2 = self.cleaned_data.get('password2')

        if password1 != password2:
            raise forms.ValidationError(self.error_messages['password_mismatch'])

        new_user=User.objects.create_user(username,email,password1)
        new_user.is_active=False
        new_user.save()

        activation_code=new_activation_code()
        activation_cache=ActivationCode.objects.create(user=new_user,activation_code=activation_code)

        if send_activation_email(email=email,username=username,code=activation_code):
            activation_cache.mail_sent_or_not=True
            activation_cache.save()
        else:
            raise forms.ValidationError(self.error_messages['send_mail_fail'])

        return self.cleaned_data