Exemple #1
0
def render_login_result(framework_name, result):
    """
    Renders the login handler

    :param result:

        The :class:`.authomatic.core.LoginResult` returned by the
        :meth:`.authomatic.Authomatic.login` method.

    """

    reload_module(sys)
    if six.PY2:
        sys.setdefaultencoding('utf-8')

    response = None
    original_credentials = {}
    refreshed_credentials = {}
    if result:
        if result.user:
            result.user.update()
            if result.user.credentials:
                original_credentials.update(result.user.credentials.__dict__)
                time.sleep(2)
                response = result.user.credentials.refresh(force=True)
                refreshed_credentials.update(result.user.credentials.__dict__)

        user_properties = [
            'birth_date', 'city', 'country', 'email', 'first_name', 'gender',
            'id', 'last_name', 'link', 'locale', 'location', 'name',
            'nickname', 'phone', 'picture', 'postal_code', 'timezone',
            'username'
        ]

        access_token_content = None
        if hasattr(result.provider, 'access_token_response'):
            access_token_content = result.provider.access_token_response.content

        template = env.get_template('login.html')
        return template.render(result=result,
                               providers=list(ASSEMBLED_CONFIG.values()),
                               oauth2_providers=OAUTH2_PROVIDERS,
                               oauth1_providers=OAUTH1_PROVIDERS,
                               openid_providers=OPENID_PROVIDERS,
                               user_properties=user_properties,
                               error=result.error,
                               credentials_response=response,
                               original_credentials=original_credentials,
                               refreshed_credentials=refreshed_credentials,
                               framework_name=framework_name,
                               access_token_content=access_token_content,
                               birth_date_format=BIRTH_DATE_FORMAT)
Exemple #2
0
def render_login_result(framework_name, result):
    """
    Renders the login handler

    :param result:

        The :class:`.authomatic.core.LoginResult` returned by the
        :meth:`.authomatic.Authomatic.login` method.

    """

    reload_module(sys)
    if six.PY2:
        sys.setdefaultencoding('utf-8')

    response = None
    original_credentials = {}
    refreshed_credentials = {}
    if result:
        if result.user:
            result.user.update()
            if result.user.credentials:
                original_credentials.update(result.user.credentials.__dict__)
                time.sleep(2)
                response = result.user.credentials.refresh(force=True)
                refreshed_credentials.update(result.user.credentials.__dict__)

        user_properties = ['birth_date', 'city', 'country', 'email',
                           'first_name', 'gender', 'id', 'last_name', 'link',
                           'locale', 'location', 'name', 'nickname', 'phone',
                           'picture', 'postal_code', 'timezone', 'username']

        access_token_content = None
        if hasattr(result.provider, 'access_token_response'):
            access_token_content = result.provider.access_token_response.content

        template = env.get_template('login.html')
        return template.render(result=result,
                               providers=ASSEMBLED_CONFIG.values(),
                               oauth2_providers=OAUTH2_PROVIDERS,
                               oauth1_providers=OAUTH1_PROVIDERS,
                               openid_providers=OPENID_PROVIDERS,
                               user_properties=user_properties,
                               error=result.error,
                               credentials_response=response,
                               original_credentials=original_credentials,
                               refreshed_credentials=refreshed_credentials,
                               framework_name=framework_name,
                               access_token_content=access_token_content,
                               birth_date_format=BIRTH_DATE_FORMAT)
Exemple #3
0
def render_login_result(framework_name, result):
    """
    Renders the login handler

    :param result:

        The :class:`.authomatic.core.LoginResult` returned by the
        :meth:`.authomatic.Authomatic.login` method.

    """

    reload_module(sys)
    if six.PY2:
        sys.setdefaultencoding('utf-8')

    response = None
    original_credentials = {}
    refreshed_credentials = {}
    if result:
        response_message = ''
        if result.user:
            result.user.update()
            if result.user.credentials:
                original_credentials.update(result.user.credentials.__dict__)
                time.sleep(2)
                response = result.user.credentials.refresh(force=True)
                refreshed_credentials.update(result.user.credentials.__dict__)

        user_properties = list(ASSEMBLED_CONFIG.values())[0]['user'].keys()
        template = env.get_template('login.html')
        return template.render(result=result,
                               providers=ASSEMBLED_CONFIG.values(),
                               oauth2_providers=OAUTH2_PROVIDERS,
                               oauth1_providers=OAUTH1_PROVIDERS,
                               openid_providers=OPENID_PROVIDERS,
                               user_properties=user_properties,
                               error=result.error,
                               credentials_response=response,
                               original_credentials=original_credentials,
                               refreshed_credentials=refreshed_credentials,
                               framework_name=framework_name)
Exemple #4
0
def render_login_result(framework_name, result):
    """
    Renders the login handler

    :param result:

        The :class:`.authomatic.core.LoginResult` returned by the
        :meth:`.authomatic.Authomatic.login` method.

    """

    reload_module(sys)
    if six.PY2:
        sys.setdefaultencoding('utf-8')

    response = None
    original_credentials = {}
    refreshed_credentials = {}
    if result:
        response_message = ''
        if result.user:
            result.user.update()
            if result.user.credentials:
                original_credentials.update(result.user.credentials.__dict__)
                time.sleep(2)
                response = result.user.credentials.refresh(force=True)
                refreshed_credentials.update(result.user.credentials.__dict__)

        user_properties = list(ASSEMBLED_CONFIG.values())[0]['user'].keys()
        template = env.get_template('login.html')
        return template.render(result=result,
                               providers=ASSEMBLED_CONFIG.values(),
                               oauth2_providers=OAUTH2_PROVIDERS,
                               oauth1_providers=OAUTH1_PROVIDERS,
                               openid_providers=OPENID_PROVIDERS,
                               user_properties=user_properties,
                               error=result.error,
                               credentials_response=response,
                               original_credentials=original_credentials,
                               refreshed_credentials=refreshed_credentials,
                               framework_name=framework_name)