def form_valid(self, form): for device in devices_for_user(self.request.user): device.delete() resp = HttpResponseRedirect(reverse('edit_profile')) resp.delete_cookie('S2FA', domain=settings.SESSION_COOKIE_DOMAIN) return resp
def test_can_disable_two_factor_auth(self): totp = TOTPDevice(user=self.admin, name="", confirmed=1) totp.save() devices = devices_for_user(self.admin) i = 0 for device in devices_for_user(self.admin): if device: i+=1 assert i > 0 resp = self.client.delete(reverse('two-factor-auth-view', args=[str(self.admin.username)])) assert resp.status_code == 200 i = 0 for device in devices_for_user(self.admin): if device: i+=1 assert i == 0
def handle(self, *args, **options): for username in args: try: user = User.objects.get_by_natural_key(username) except User.DoesNotExist: raise CommandError('User "%s" does not exist' % username) for device in devices_for_user(user): device.delete()
def delete(self, request, email): if not email: error_msg = "email can not be empty" return api_error(status.HTTP_400_BAD_REQUEST, error_msg) try: user = User.objects.get(email=email) except User.DoesNotExist: error_msg = "User %s not found" % email return api_error(status.HTTP_400_BAD_REQUEST, error_msg) devices = devices_for_user(user) if devices: for device in devices: device.delete() return Response({'success': True}, status=status.HTTP_200_OK)
def device_choices(user): return list((d.persistent_id, d.name) for d in devices_for_user(user))
def tearDown(self): try: for device in devices_for_user(self.admin): device.delete() except: pass