コード例 #1
0
ファイル: facebook.py プロジェクト: gamunax/pyhtongamunax
def index(_resp, token, ret_path='/'):
    cmd = facade.login_facebook(token, _resp)
    cmd()
    if cmd.pending_link:
        pending_path = router.to_path(pending.index, cmd.pending_link.key.id())
        user_email = cmd.main_user_from_email.email
        facade.send_passwordless_login_link(user_email,
                                            settings.APP_URL + pending_path).execute()
        return TemplateResponse({'provider': 'Facebook', 'email': user_email}, 'login/pending.html')
    return RedirectResponse(ret_path)
コード例 #2
0
ファイル: facebook.py プロジェクト: renzon/livrogae
def index(_handler, _resp, _write_tmpl, token, ret_path='/'):
    cmd = facade.login_facebook(token, _resp)
    cmd.execute()
    if cmd.pending_link:
        pendente_path = router.to_path(pendente.index, cmd.pending_link.key.id())
        user_email = cmd.main_user_from_email.email
        facade.send_passwordless_login_link(user_email,
                                            'https://livrogae.appspot.com' + pendente_path,
                                            'pt_BR').execute()
        _write_tmpl('login/pendente.html', {'provider': 'Facebook', 'email': user_email})
        return
    _handler.redirect(ret_path)
コード例 #3
0
def index(_resp, token, ret_path='/'):
    cmd = facade.login_facebook(token, _resp)
    cmd()
    if cmd.pending_link:
        pending_path = router.to_path(pending.index, cmd.pending_link.key.id())
        user_email = cmd.main_user_from_email.email
        facade.send_passwordless_login_link(user_email, settings.APP_URL +
                                            pending_path).execute()
        return TemplateResponse({
            'provider': 'Facebook',
            'email': user_email
        }, 'login/pending.html')
    return RedirectResponse(ret_path)
コード例 #4
0
    def test_facebook_user_logged_for_the_first_time_with_no_conflict(self, log_main_user_in):
        response = Mock()
        fetch_mock = self.setup_fetch_mock()
        cmd = facade.login_facebook('', response)

        cmd._fetch_facebook = fetch_mock
        cmd.execute()

        self.assertTrue(cmd.result)
        user = cmd.main_user_from_external
        self.assertEqual('*****@*****.**', user.email)
        self.assertEqual('foo', user.name)
        self.assertEqual(MainUser.query().get(), user)
        facebook_user = ExternalUserSearch(user).execute().result[0]
        self.assertEqual('123', facebook_user.external_id)
        log_main_user_in.assert_called_once_with(user, response, 'userck')
        self.assertIsNone(cmd.pending_link)
コード例 #5
0
    def test_facebook_user_logged_for_the_first_time_with_conflict(self, log_main_user_in):
        main_user = mommy.save_one(MainUser, email='*****@*****.**')

        response = Mock()
        fetch_mock = self.setup_fetch_mock()
        cmd = facade.login_facebook('', response)

        cmd._fetch_facebook = fetch_mock
        cmd.execute()
        self.assertFalse(cmd.result)
        self.assertIsNone(cmd.main_user_from_external)

        self.assertEqual(1, len(FacebookUser.query().fetch()))
        self.assertEqual(1, len(MainUser.query().fetch()))
        self.assertIsNotNone(cmd.pending_link)
        self.assertEqual(PendingExternalToMainUser.query().get(), cmd.pending_link)
        self.assertEqual(cmd.external_user.key, cmd.pending_link.external_user)
        self.assertEqual(main_user.key, cmd.pending_link.main_user)
        self.assertEqual('123', cmd.external_user.external_id)
        self.assertFalse(log_main_user_in.called)
コード例 #6
0
    def test_facebook_user_logged_for_the_second_time(self, log_main_user_in):
        f_key = FacebookUser(external_id='123').put()
        main_user = MainUser(name='foo', email='*****@*****.**')
        main_user.put()
        ExternalToMainUser(origin=f_key, destination=main_user.key.id()).put()

        response = Mock()
        fetch_mock = self.setup_fetch_mock()
        cmd = facade.login_facebook('', response)

        cmd._fetch_facebook = fetch_mock
        cmd.execute()

        self.assertTrue(cmd.result)

        user = cmd.main_user_from_external
        self.assertEqual('*****@*****.**', user.email)
        self.assertEqual('foo', user.name)
        self.assertEqual(main_user, user)
        self.assertEqual(1, len(FacebookUser.query().fetch()))
        self.assertEqual(1, len(MainUser.query().fetch()))
        self.assertIsNone(cmd.pending_link)
        log_main_user_in.assert_called_once_with(user, response, 'userck')