コード例 #1
0
ファイル: auth.py プロジェクト: shenek/django-mojeid-auth
    def run_handlers(openid_response, user, attribute_set='default'):
        handlers = [x for x in get_attributes(attribute_set) if x.type == 'handler']

        if not handlers:
            return

        fetch_response = ax.FetchResponse.fromSuccessResponse(openid_response)

        for handler in handlers:
            val = handler.attribute.get_value(fetch_response, handler.required, openid_response)
            call_handler(handler.name, user, val)
コード例 #2
0
ファイル: views.py プロジェクト: ciklysta/django-mojeid-auth
def registration(request, attribute_set='default',
                 template_name='openid/registration_form.html',
                 form_class=OpenIDLoginForm):
    """ Try to submit all the registration attributes for mojeID registration"""

    registration_url = getattr(settings, 'MOJEID_REGISTRATION_URL',
                               MOJEID_REGISTRATION_URL)

    # Realm should be always something like 'https://example.org/openid/'
    realm = getattr(settings, 'MOJEID_REALM',
                    request.build_absolute_uri(reverse(top)))

    user = OpenIDBackend.get_user_from_request(request)
    user_id = user.pk if user else None

    # Create Nonce
    nonce = Nonce(server_url=realm, user_id=user_id)
    nonce.save()

    fields = []
    attributes = [x for x in get_attributes(attribute_set) if x.type == 'attribute']
    # Append attributes to creation request if user is valid
    if user:
        for attribute in attributes:
            form_attr = attribute.registration_form_attrs_html(user_id)
            if form_attr:
                fields.append(form_attr)

    # Render the redirection template
    return render_to_response(
        template_name,
        {
            'fields': fields,
            'action': registration_url,
            'realm': realm,
            'nonce': nonce.registration_nonce,
        },
        context_instance=RequestContext(request)
    )
コード例 #3
0
ファイル: auth.py プロジェクト: ciklysta/django-mojeid-auth
    def get_model_changes(openid_response, only_updatable=False,
                          attribute_set='default'):

        attributes = [x for x in get_attributes(attribute_set) if x.type == 'attribute']

        fetch_response = ax.FetchResponse.fromSuccessResponse(openid_response)

        res = {}

        # filter remove non-updatable attributes
        if only_updatable:
            attributes = [x for x in attributes if x.updatable]

        for attribute in attributes:
            if not attribute.model in res:
                res[attribute.model] = {'user_id_field_name': attribute.user_id_field_name}
            val = attribute.get_value(fetch_response, attribute.required)

            if val is not None:
                res[attribute.model][attribute.modelAttribute] = val

        return res
コード例 #4
0
ファイル: views.py プロジェクト: shenek/django-mojeid-auth
def registration(request, attribute_set='default',
                 template_name='openid/registration_form.html'):
    """ Try to submit all the registration attributes for mojeID registration"""

    # Realm should be always something like 'https://example.org/openid/'
    realm = getattr(settings, 'MOJEID_REALM',
                    request.build_absolute_uri(reverse(top)))

    user = OpenIDBackend.get_user_from_request(request)
    user_id = user.pk if user else None

    # Create Nonce
    nonce = Nonce(server_url=realm, user_id=user_id,
                  timestamp=time.time(), salt=randomString(35, NONCE_CHARS))
    nonce.save()

    fields = []
    attributes = [x for x in get_attributes(attribute_set) if x.type == 'attribute']
    # Append attributes to creation request if user is valid
    if user:
        for attribute in attributes:
            form_attr = attribute.registration_form_attrs_html(user_id)
            if form_attr:
                fields.append(form_attr)

    # Render the redirection template
    return render_to_response(
        template_name,
        {
            'fields': fields,
            'action': get_registration_url(),
            'realm': realm,
            'nonce': nonce.registration_nonce,
        },
        context_instance=RequestContext(request)
    )