Exemplo n.º 1
0
    def test_backup_phones(self):
        self.assertQuerysetEqual(list(backup_phones(None)), list(PhoneDevice.objects.none()))
        user = self.create_user()
        user.phonedevice_set.create(name="default", number="+1")
        backup = user.phonedevice_set.create(name="backup", number="+1")
        phones = backup_phones(user)

        self.assertEqual(len(phones), 1)
        self.assertEqual(phones[0].pk, backup.pk)
Exemplo n.º 2
0
    def test_backup_phones(self):
        self.assertQuerysetEqual(list(backup_phones(None)),
                                 list(PhoneDevice.objects.none()))
        user = self.create_user()
        PhoneDevice.objects.create(user=user, name='default')
        backup = PhoneDevice.objects.create(user=user, name='backup')
        phones = backup_phones(user)

        self.assertEqual(len(phones), 1)
        self.assertEqual(phones[0].pk, backup.pk)
    def test_backup_phones(self):
        self.assertQuerysetEqual(list(backup_phones(None)),
                                 list(PhoneDevice.objects.none()))
        user = self.create_user()
        user.phonedevice_set.create(name='default', number='+1')
        backup = user.phonedevice_set.create(name='backup', number='+1')
        phones = backup_phones(user)

        self.assertEqual(len(phones), 1)
        self.assertEqual(phones[0].pk, backup.pk)
Exemplo n.º 4
0
    def test_backup_phones(self):
        self.assertQuerysetEqual(list(backup_phones(None)),
                                 list(PhoneDevice.objects.none()))

        user = User.objects.create_user('bouke')
        user.phonedevice_set.create(name='default')
        backup = user.phonedevice_set.create(name='backup')
        phones = backup_phones(user)

        self.assertEqual(len(phones), 1)
        self.assertEqual(phones[0].pk, backup.pk)
Exemplo n.º 5
0
    def dispatch(self, request, *args, **kwargs):
        has_backup_phones = bool(backup_phones(self.request.user))
        if not (has_backup_phones or _user_can_use_phone(request.couch_user)):
            # NOTE: this behavior could be seen as un-intuitive. If a domain is not authorized to use phone/sms,
            # we are still allowing full functionality if they have an existing backup phone. The primary reason
            # is so that a user can delete a backup number if needed. The ability to add in a new number is still
            # enabled just to prevent confusion -- it is expected to be an edge case.
            raise Http404

        return super(TwoFactorPhoneSetupView,
                     self).dispatch(request, *args, **kwargs)
Exemplo n.º 6
0
def account(request):
	try:
		backup_tokens = request.user.staticdevice_set.all()[0].token_set.count()
	except Exception:
		backup_tokens = 0

	status = {
		'default_device': default_device(request.user),
		'default_device_type': default_device(request.user).__class__.__name__,
		'backup_phones': backup_phones(request.user),
		'backup_tokens': backup_tokens,
		'site_user': request.user
	}

	return render_to_response('account.html', status, context_instance=RequestContext(request))
Exemplo n.º 7
0
    def get_context_data(self, **kwargs):
        try:
            backup_tokens = self.request.user.staticdevice_set.all(
            )[0].token_set.count()
        except Exception:
            backup_tokens = 0

        return {
            'default_device': default_device(self.request.user),
            'default_device_type':
            default_device(self.request.user).__class__.__name__,
            'backup_phones': backup_phones(self.request.user),
            'backup_tokens': backup_tokens,
            'available_phone_methods': get_available_phone_methods()
        }
Exemplo n.º 8
0
    def list(self, request):
        try:
            token_set = request.user.staticdevice_set.first().token_set.all()
        except AttributeError:
            token_set = []

        return Response({
            'default': get_info_text_for_device(default_device(request.user)),
            'backup_phone_numbers': [
                {
                    'id': phone.pk,
                    'number': mask_phone_number(format_phone_number(phone.number)),
                } for phone in backup_phones(request.user)
            ],
            'backup_tokens': [token.token for token in token_set],
        })
Exemplo n.º 9
0
    def list(self, request):
        try:
            token_set = request.user.staticdevice_set.first().token_set.all()
        except AttributeError:
            token_set = []

        return Response({
            'default': get_info_text_for_device(default_device(request.user)),
            'backup_phone_numbers': [
                {
                    'id': phone.pk,
                    'number': mask_phone_number(format_phone_number(phone.number)),
                } for phone in backup_phones(request.user)
            ],
            'backup_tokens': [token.token for token in token_set],
        })
Exemplo n.º 10
0
def account(request):
    try:
        backup_tokens = request.user.staticdevice_set.all()[0].token_set.count(
        )
    except Exception:
        backup_tokens = 0

    status = {
        'default_device': default_device(request.user),
        'default_device_type': default_device(request.user).__class__.__name__,
        'backup_phones': backup_phones(request.user),
        'backup_tokens': backup_tokens,
        'site_user': request.user
    }

    return render_to_response('account.html',
                              status,
                              context_instance=RequestContext(request))
Exemplo n.º 11
0
 def test_delete(self):
     response = self.client.post(
         reverse('two_factor:phone_delete', args=[self.backup.pk]))
     self.assertRedirects(response,
                          resolve_url(settings.LOGIN_REDIRECT_URL))
     self.assertEqual(list(backup_phones(self.user)), [])
Exemplo n.º 12
0
 def test_delete(self):
     response = self.client.post(reverse('two_factor:phone_delete',
                                         args=[self.backup.pk]))
     self.assertRedirects(response, str(settings.LOGIN_REDIRECT_URL))
     self.assertEqual(list(backup_phones(self.user)), [])