Пример #1
0
    def test_user_delete_using_form(self):
        # This should set user's attribute active to false and anonymize it
        user = self.create_user_and_content(is_index_dirty=False)
        a = self.client.login(username=user.username, password='******')
        form = DeleteUserForm(user_id=user.id)
        encr_link = form.initial['encrypted_link']
        resp = self.client.post(reverse('accounts-delete'),
                                {'encrypted_link': encr_link, 'password': '******', 'delete_sounds': 'delete_sounds'})

        self.assertEqual(User.objects.get(id=user.id).profile.is_deleted_user, True)
Пример #2
0
    def test_fail_user_delete_using_form(self):
        # This should try to delete the account but with a wrong password
        user = self.create_user_and_content(is_index_dirty=False)
        a = self.client.login(username=user.username, password='******')
        form = DeleteUserForm(user_id=user.id)
        encr_link = form.initial['encrypted_link']
        resp = self.client.post(reverse('accounts-delete'),
                                {'encrypted_link': encr_link, 'password': '******',
                                 'delete_sounds': 'delete_sounds'})

        self.assertEqual(User.objects.get(id=user.id).profile.is_deleted_user, False)
Пример #3
0
def delete(request):
    num_sounds = request.user.sounds.all().count()
    error_message = None
    if request.method == 'POST':
        form = DeleteUserForm(request.POST, user_id=request.user.id)
        if not form.is_valid():
            error_message = "Sorry, you waited too long, ... try again?"
            form = DeleteUserForm(user_id=request.user.id)
        else:
            delete_sounds =\
                form.cleaned_data['delete_sounds'] == 'delete_sounds'
            request.user.profile.delete_user(remove_sounds=delete_sounds)
            logout(request)
            return HttpResponseRedirect(reverse("front-page"))
    else:
        form = DeleteUserForm(user_id=request.user.id)

    tvars = {
            'error_message': error_message,
            'delete_form': form,
            'num_sounds': num_sounds,
    }
    return render(request, 'accounts/delete.html', tvars)
Пример #4
0
def delete(request):
    num_sounds = request.user.sounds.all().count()
    error_message = None
    if request.method == 'POST':
        form = DeleteUserForm(request.POST, user_id=request.user.id)
        if not form.is_valid():
            error_message = "Sorry, you waited too long, ... try again?"
            form = DeleteUserForm(user_id=request.user.id)
        else:
            delete_sounds =\
                form.cleaned_data['delete_sounds'] == 'delete_sounds'
            request.user.profile.delete_user(remove_sounds=delete_sounds)
            logout(request)
            return HttpResponseRedirect(reverse("front-page"))
    else:
        form = DeleteUserForm(user_id=request.user.id)

    tvars = {
        'error_message': error_message,
        'delete_form': form,
        'num_sounds': num_sounds,
    }
    return render(request, 'accounts/delete.html', tvars)