def test_matching_passwords(self): form = ActivateAccountForm(user=self.pending_user, data={ 'full_name': 'First Last', 'password': '******', 'confirm_password': '******', }) self.assertTrue(form.is_valid())
def test_matching_passwords(self): form = ActivateAccountForm( user=self.pending_user, data={ 'full_name': 'First Last', 'password': '******', 'confirm_password': '******', } ) self.assertTrue(form.is_valid())
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)
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)