예제 #1
0
파일: test_forms.py 프로젝트: xxfyx/connect
    def test_matching_passwords(self):
        form = ActivateAccountForm(user=self.pending_user,
                                   data={
                                       'full_name': 'First Last',
                                       'password': '******',
                                       'confirm_password': '******',
                                   })

        self.assertTrue(form.is_valid())
예제 #2
0
    def test_matching_passwords(self):
        form = ActivateAccountForm(
            user=self.pending_user,
            data={
                'full_name': 'First Last',
                'password': '******',
                'confirm_password': '******',
            }
        )

        self.assertTrue(form.is_valid())
예제 #3
0
파일: views.py 프로젝트: foobacca/connect
def activate_account(request, token):
    """
    Allow a user to activate their account with the token sent to them
    by email.
    """
    user = get_object_or_404(User, auth_token=token)

    if not user.auth_token_is_used:
        if request.POST:
            form = ActivateAccountForm(request.POST, user=user)

            if form.is_valid():

                # Activate the user's account
                user.first_name = form.cleaned_data['first_name']
                user.last_name = form.cleaned_data['last_name']
                user.password = make_password(form.cleaned_data['password'])
                user.is_active = True

                user.activated_datetime = now()
                user.auth_token_is_used = True
                user.save()

                email = user.email
                password = request.POST['password']
                user = authenticate(username=email, password=password)
                login(request, user)

                # Redirect to dashboard with welcome message
                request.session['show_welcome'] = True
                return redirect(reverse('dashboard'))

        else:
            form = ActivateAccountForm(user=user)

        context = {
            'user': user,
            'form': form,
        }

    else:
        token_is_used = True

        context = {
            'token_is_used': token_is_used,
        }

    return render(request, 'accounts/activate_account.html', context)
예제 #4
0
def activate_account(request, token):
    """
    Allow a user to activate their account with the token sent to them
    by email.
    """
    user = get_object_or_404(User, auth_token=token)

    if not user.auth_token_is_used:
        if request.POST:
            form = ActivateAccountForm(request.POST, user=user)

            if form.is_valid():

                # Activate the user's account
                user.full_name = form.cleaned_data['full_name']
                user.password = make_password(form.cleaned_data['password'])
                user.is_active = True

                user.activated_datetime = now()
                user.auth_token_is_used = True
                user.save()

                email = user.email
                password = request.POST['password']
                user = authenticate(username=email, password=password)
                login(request, user)

                # Redirect to dashboard with welcome message
                request.session['show_welcome'] = True
                return redirect(reverse('dashboard'))

        else:
            form = ActivateAccountForm(user=user)

        context = {
            'user': user,
            'form': form,
        }

    else:
        token_is_used = True

        context = {
            'token_is_used': token_is_used,
        }

    return render(request, 'accounts/activate_account.html', context)