def test_serialize_settings_disabled(self): user = UserFactory() settings = serialize_settings(Auth(user)) assert_false(settings['is_enabled']) assert_false(settings['is_confirmed']) assert_equal(settings['secret'], None) assert_equal(settings['drift'], None)
def test_serialize_settings_enabled_and_confirmed(self): self.user_addon.is_confirmed = True self.user_addon.save() settings = serialize_settings(Auth(self.user)) assert_true(settings['is_enabled']) assert_true(settings['is_confirmed']) assert_equal(settings['secret'], self.user_addon.totp_secret_b32) assert_equal(settings['drift'], self.user_addon.totp_drift)
def twofactor_enable(auth, *args, **kwargs): user = auth.user if user.has_addon('twofactor'): return HTTPError( http_status.HTTP_400_BAD_REQUEST, data=dict(message_long='This user already has two-factor enabled')) user.add_addon('twofactor', auth=auth) user_addon = user.get_addon('twofactor') user_addon.save() user.save() return { 'result': serialize_settings(auth), }
def twofactor_settings_get(auth, *args, **kwargs): return { 'result': serialize_settings(auth), }