Skip to content

Commit

Permalink
signals: initial implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Kuncar <jiri.kuncar@cern.ch>
  • Loading branch information
jirikuncar authored and JavierDelgadoFernandez committed Dec 7, 2015
1 parent 357b1f6 commit c15544c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions invenio_oauthclient/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from .forms import EmailSignUpForm
from .models import RemoteAccount, RemoteToken
from .proxies import current_oauthclient
from .signals import account_info_received, account_set
from .utils import oauth_authenticate, oauth_get_user, oauth_register


Expand Down Expand Up @@ -217,6 +218,9 @@ def authorized_signup_handler(resp, remote, *args, **kwargs):
# ---------------
if not current_user.is_authenticated:
account_info = handlers['info'](resp)
account_info_received.send(
remote, response=resp, account_info=account_info
)

user = oauth_get_user(
remote.consumer_key,
Expand Down Expand Up @@ -338,6 +342,7 @@ def signup_handler(remote, *args, **kwargs):

if not token.remote_account.extra_data:
handlers['setup'](token, response)
# TODO add signal for account setup

# Remove account info from session
session.pop(session_prefix + '_account_info', None)
Expand Down
48 changes: 48 additions & 0 deletions invenio_oauthclient/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2015 CERN.
#
# Invenio is free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# Invenio is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Invenio; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307, USA.
#
# In applying this license, CERN does not
# waive the privileges and immunities granted to it by virtue of its status
# as an Intergovernmental Organization or submit itself to any jurisdiction.

"""Signals used together with various handlers."""

from blinker import Namespace

_signals = Namespace()

account_info_received = _signals.signal('oauthclient-account-info-received')
"""Signal is sent after account info handler response.
Example subscriber:
.. code-block:: python
from invenio_oauthclient.signals import account_info_received
# During overlay initialization.
@account_info_received.connect_via(
sender=app.extensions['invenio-oauthclient'].handlers['orcid']
)
def load_extra_information(remote, response=None, account_info=None):
response = remote.get('https://example.org/api/resource')
# process response
"""

0 comments on commit c15544c

Please sign in to comment.