def get(self): code = self.request.GET.get('code') if code: user_info = TheCitySDK.post_for_user_token(code) sdk = TheCitySDK(user_info.get('access_token')) user_permissions = sdk.get_user_permissions() if 'error_code' not in user_permissions: if sdk.user_is_in_worship_arts(user_permissions): logging.info('This user can join our site') user_info_dict = sdk.get_basic_user_info() user_info_dict['jwt'] = create_jwt_from_user_data(user_permissions, user_info_dict) User.put_from_city_dict(user_info_dict) self.redirect('/login?success=true&userId={}'.format(user_info_dict['id'])) else: logging.info('This user needs to be added to a Worship Arts group on The City') # TODO: Redirect to a different landing page explaining the purpose of this site and who to contact. self.redirect('/') else: self.redirect('/login')
def test_get_info_dict_returns_sane_info_about_a_user(self): user = User.put_from_city_dict(self.user_dict).get() user_dict = user.info_dict self.assertEqual(self.user_dict['first_name'], user_dict['first_name']) self.assertEqual(self.user_dict['last_name'], user_dict['last_name'])
def test_get_info_dict_returns_a_dict(self): user = User.put_from_city_dict(self.user_dict).get() user_dict = user.info_dict self.assertTrue(type(user_dict) == dict)
def test_get_key_hash_returns_appropriate_hash_value(self): user = User.put_from_city_dict(self.user_dict).get() user_jwt_decoded = decode_jwt(user.get_key_hash()) self.assertEqual(user.id, user_jwt_decoded['usr']['id'])
def test_get_by_user_id_returns_correct_user(self): user = User.put_from_city_dict(self.user_dict).get() self.assertEqual('cdac', user.subdomain)
def test_put_from_city_dict_instantiates_user_with_properties_from_dict(self): user = User.put_from_city_dict(self.user_dict).get() self.assertEqual('cdac', user.subdomain)