当前位置: 首页>>代码示例>>Python>>正文


Python SRegRequest.fromOpenIDRequest方法代码示例

本文整理汇总了Python中openid.extensions.sreg.SRegRequest.fromOpenIDRequest方法的典型用法代码示例。如果您正苦于以下问题:Python SRegRequest.fromOpenIDRequest方法的具体用法?Python SRegRequest.fromOpenIDRequest怎么用?Python SRegRequest.fromOpenIDRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openid.extensions.sreg.SRegRequest的用法示例。


在下文中一共展示了SRegRequest.fromOpenIDRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_approved_data

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
def _get_approved_data(request, orequest):
    """Given an HTTP request and an OpenID request, return a nested dict of
    values requested in the request and approved by the user.
    """
    if not orequest:
        return None

    approved_data = {}
    rpconfig = utils.get_rpconfig(orequest.trust_root)

    sreg_request = SRegRequest.fromOpenIDRequest(orequest)
    ax_request = ax.FetchRequest.fromOpenIDRequest(orequest)

    user_attribs_form = UserAttribsRequestForm(
        request, sreg_request, ax_request, rpconfig)
    if user_attribs_form.has_data:
        approved_data['user_attribs'] = {
            'requested': user_attribs_form.data.keys(),
            'approved': user_attribs_form.data_approved_for_request.keys()}

    args = orequest.message.getArgs(LAUNCHPAD_TEAMS_NS)
    team_names = args.get('query_membership')
    if team_names:
        team_names = team_names.split(',')
        teams_form = TeamsRequestForm(
            request,
            TeamsRequest.fromOpenIDRequest(orequest),
            rpconfig,
        )
        approved_data['teams'] = {
            'requested': team_names,
            'approved': teams_form.teams_approved_by_user}

    return approved_data
开发者ID:miing,项目名称:mci_migo,代码行数:36,代码来源:server.py

示例2: createPositiveResponse

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
    def createPositiveResponse(self):
        """Create a positive assertion OpenIDResponse.

        This method should be called to create the response to
        successful checkid requests.

        If the trust root for the request is in openid_sreg_trustroots,
        then additional user information is included with the
        response.
        """
        assert self.account is not None, (
            'Must be logged in for positive OpenID response')
        assert self.openid_request is not None, (
            'No OpenID request to respond to.')

        if not self.isIdentityOwner():
            return self.createFailedResponse()

        if self.openid_request.idSelect():
            response = self.openid_request.answer(
                True, identity=self.user_identity_url)
        else:
            response = self.openid_request.answer(True)

        person = IPerson(self.account)
        sreg_fields = dict(
            nickname=person.name,
            email=person.preferredemail.email,
            fullname=self.account.displayname)
        sreg_request = SRegRequest.fromOpenIDRequest(self.openid_request)
        sreg_response = SRegResponse.extractResponse(
            sreg_request, sreg_fields)
        response.addExtension(sreg_response)

        return response
开发者ID:vitaminmoo,项目名称:unnaturalcode,代码行数:37,代码来源:server.py

示例3: Respond

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
  def Respond(self, oidresponse):
    logging.warning('Respond: oidresponse.request.mode ' + oidresponse.request.mode)

    if oidresponse.request.mode in ['checkid_immediate', 'checkid_setup']:
      user = users.get_current_user()
      if user:
        from openid.extensions.sreg import SRegRequest, SRegResponse
        sreg_req = SRegRequest.fromOpenIDRequest(oidresponse.request)
        if sreg_req.wereFieldsRequested():
          logging.info("sreg_req:%s", sreg_req.allRequestedFields())
          user_data = {'nickname':user.nickname(),
                       'email':user.email()}
          sreg_resp = SRegResponse.extractResponse(sreg_req, user_data)
          sreg_resp.toMessage(oidresponse.fields)        
    logging.info('Using response: %s' % oidresponse)
    encoded_response = oidserver.encodeResponse(oidresponse)

    for header, value in encoded_response.headers.items():
      self.response.headers[header] = str(value)

    if encoded_response.code in (301, 302):
      self.redirect(self.response.headers['location'])
    else:
      self.response.set_status(encoded_response.code)

    if encoded_response.body:
      logging.debug('Sending response body: %s' % encoded_response.body)
      self.response.out.write(encoded_response.body)
    else:
      self.response.out.write('')
开发者ID:DemocracyOS,项目名称:IdentidadEnRed-Prototype,代码行数:32,代码来源:provider.py

示例4: test_login_create_users

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
    def test_login_create_users(self):
        settings.OPENID_CREATE_USERS = True
        # Create a user with the same name as we'll pass back via sreg.
        User.objects.create_user('someuser', '[email protected]')

        # Posting in an identity URL begins the authentication request:
        response = self.client.post('/openid/login/',
            {'openid_identifier': 'http://example.com/identity',
             'next': '/getuser/'})
        self.assertContains(response, 'OpenID transaction in progress')

        # Complete the request, passing back some simple registration
        # data.  The user is redirected to the next URL.
        openid_request = self.provider.parseFormPost(response.content)
        sreg_request = SRegRequest.fromOpenIDRequest(openid_request)
        openid_response = openid_request.answer(True)
        sreg_response = SRegResponse.extractResponse(
            sreg_request, {'nickname': 'someuser', 'fullname': 'Some User',
                           'email': '[email protected]'})
        openid_response.addExtension(sreg_response)
        response = self.complete(openid_response)
        self.assertRedirects(response, 'http://testserver/getuser/')

        # And they are now logged in as a new user (they haven't taken
        # over the existing "someuser" user).
        response = self.client.get('/getuser/')
        self.assertEquals(response.content, 'someuser2')

        # Check the details of the new user.
        user = User.objects.get(username='someuser2')
        self.assertEquals(user.first_name, 'Some')
        self.assertEquals(user.last_name, 'User')
        self.assertEquals(user.email, '[email protected]')
开发者ID:gcr,项目名称:twg,代码行数:35,代码来源:test_views.py

示例5: decide

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
def decide(request, token):
    try:
        orequest = _get_orequest(request, token)
        rpconfig = utils.get_rpconfig(orequest.trust_root)
    except:
        return HttpResponse("Invalid OpenID transaction")

    if not request.user.is_authenticated():
        # XXX: need to remove this circular dep to the webui app
        from webui.views import ui
        return ui.LoginView.as_view()(request, token, rpconfig=rpconfig)

    if not _user_is_verified_for_rp(request.user, rpconfig):
        name = rpconfig.displayname if rpconfig else orequest.trust_root
        messages.warning(
            request,
            SITE_REQUIRES_VERIFIED.format(rp_name=name)
        )
        return HttpResponseRedirect(reverse('account-emails'))

    site_requires_twofactor = twofactor.site_requires_twofactor_auth(
        request, token, rpconfig)
    if (not twofactor.is_authenticated(request) or
            (site_requires_twofactor and not twofactor.is_upgraded(request))):
        if is_twofactor_enabled(request):
            return HttpResponseRedirect(reverse('twofactor', args=[token]))
        else:
            return _process_decide(request, orequest, decision=False)

    if ('ok' in request.POST or
            (rpconfig is not None and rpconfig.auto_authorize)):
        return _process_decide(request, orequest, decision=True)

    sreg_request = SRegRequest.fromOpenIDRequest(orequest)
    ax_request = ax.FetchRequest.fromOpenIDRequest(orequest)
    teams_request = TeamsRequest.fromOpenIDRequest(orequest)
    try:
        summary = OpenIDRPSummary.objects.get(
            account=request.user, trust_root=orequest.trust_root,
            openid_identifier=request.user.openid_identity_url)
        approved_data = summary.get_approved_data()
    except OpenIDRPSummary.DoesNotExist:
        approved_data = {}

    user_attribs_form = UserAttribsRequestForm(
        request, sreg_request, ax_request, rpconfig,
        approved_data=approved_data.get('user_attribs'))
    teams_form = TeamsRequestForm(request, teams_request, rpconfig,
                                  approved_data=approved_data.get('teams'))
    context = RequestContext(request, {
        'account': request.user,
        'trust_root': orequest.trust_root,
        'rpconfig': rpconfig,
        'user_attribs_form': user_attribs_form,
        'teams_form': teams_form,
        'token': token,
        'sane_trust_root': _request_has_sane_trust_root(orequest)
    })
    return render_to_response('server/decide.html', context)
开发者ID:miing,项目名称:mci_migo,代码行数:61,代码来源:server.py

示例6: post

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
  def post(self):

    parsed = urlparse.urlparse(self.request.uri)
    request_url_without_path = parsed[0] + '://' + parsed[1]
    request_url_without_params = request_url_without_path + parsed[2]

    token = self.request.get('token') or urlparse.urlparse(self.request.uri)[2].rsplit('/',2)[2]
    oid_args = False
    query = datastore.Query('Verification')
    query['token ='] = token
    v = query.Get(1)
    if v:
      v = v[0]
      if v['expires'] > time.time():
        self.user = v['email']
        self.oid_args = pickle.loads(str(v['oidrequest']))
      else:
        error = 'That token has expired.  Please try again.'
      datastore.Delete(v)
    else:
      error = 'No such token found.'

    if not self.CheckUser():
      self.ShowFrontPage(error)
      return

    args = self.ArgsToDict()

    try:
      oidrequest = OpenIDServer.CheckIDRequest.fromMessage(OpenIDMessage.fromPostArgs(args), '')
    except:
      trace = ''.join(traceback.format_exception(*sys.exc_info()))
      self.ReportError('Error decoding login request:\n%s' % trace)
      return

    if True: #args.has_key('yes'):
      logging.debug('Confirming identity to %s' % oidrequest.trust_root)
      if args.get('remember', '') == 'yes':
        logging.info('Setting cookie to remember openid login for two weeks')

        expires = datetime.datetime.now() + datetime.timedelta(weeks=2)
        expires_rfc822 = expires.strftime('%a, %d %b %Y %H:%M:%S +0000')
        self.response.headers.add_header(
          'Set-Cookie', 'openid_remembered=yes; expires=%s' % expires_rfc822)

      self.store_login(oidrequest, 'confirmed')
      sreg_req = SRegRequest.fromOpenIDRequest(oidrequest)
      self.Respond(oidrequest.answer(True, request_url_without_path + '/id/' + urllib.quote(self.user)), sreg_req)

    elif args.has_key('no'):
      logging.debug('Login denied, sending cancel to %s' %
                    oidrequest.trust_root)
      self.store_login(oidrequest, 'declined')
      return self.Respond(oidrequest.answer(False))

    else:
      self.ReportError('Bad login request.')
开发者ID:singpolyma,项目名称:Email-Verify,代码行数:59,代码来源:provider.py

示例7: openid_decide

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
def openid_decide(request):
    """
    The page that asks the user if they really want to sign in to the site, and
    lets them add the consumer to their trusted whitelist.
    # If user is logged in, ask if they want to trust this trust_root
    # If they are NOT logged in, show the landing page
    """
    orequest = request.session.get('OPENID_REQUEST')
    # No request ? Failure..
    if not orequest:
        logger.warning('OpenID decide view failed, \
because no OpenID request is saved')
        return HttpResponseRedirect('/')
    sreg_request = SRegRequest.fromOpenIDRequest(orequest)
    logger.debug('SREG request: %s' % sreg_request.__dict__)
    if not request.user.is_authenticated():
        # Not authenticated ? Authenticate and go back to the server endpoint
        return redirect_to_login(request, next=reverse(openid_server),
                nonce='1')

    if request.method == 'POST':
        if 'cancel' in request.POST:
            # User refused
            logger.info('OpenID decide canceled')
            return HttpResponseRedirect('%s?cancel' % reverse(openid_server))
        else:
            form = DecideForm(sreg_request=sreg_request, data=request.POST)
            if form.is_valid():
                data = form.cleaned_data
                # Remember the choice
                t, created = models.TrustedRoot.objects.get_or_create(
                        user=request.user.id, trust_root=orequest.trust_root)
		t.choices = sreg_request.required \
                    + [ field for field in data if data[field] ]
                t.save()
                logger.debug('OpenID decide, user choice:%s' % data)
                return HttpResponseRedirect(reverse('openid-provider-root'))
    else:
        form = DecideForm(sreg_request=sreg_request)
    logger.info('OpenID device view, orequest:%s' % orequest)

    # verify return_to of trust_root
    try:
        trust_root_valid = verifyReturnTo(orequest.trust_root,
                orequest.return_to) and "Valid" or "Invalid"
    except HTTPFetchingError:
        trust_root_valid = "Unreachable"
    except DiscoveryFailure:
        trust_root_valid = "DISCOVERY_FAILED"

    return render_to_response('idp/openid/decide.html', {
        'title': _('Trust this site?'),
        'required': sreg_request.required,
        'optional': sreg_request.optional,
        'trust_root_valid': trust_root_valid,
        'form': form,
    }, context_instance=RequestContext(request))
开发者ID:pu239ppy,项目名称:authentic2,代码行数:59,代码来源:views.py

示例8: handle_sreg

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
def handle_sreg(request, response):
    """Handle any sreg data requests"""
    sreg_req = SRegRequest.fromOpenIDRequest(request)
    # Extract information if required
    if sreg_req.wereFieldsRequested():
        fields = config.sreg_fields()
        if not fields:
            return
        sreg_resp = SRegResponse.extractResponse(sreg_req, config.sreg_fields())
        sreg_resp.toMessage(response.fields)
开发者ID:kgaughan,项目名称:poit-wsgi,代码行数:12,代码来源:poit.py

示例9: Respond

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
  def Respond(self, oidresponse):
    """Send an OpenID response.

    Args:
      oidresponse: OpenIDResponse
      The response to send, usually created by OpenIDRequest.answer().
    """
    logging.warning('Respond: oidresponse.request.mode ' + oidresponse.request.mode)

    if oidresponse.request.mode in ['checkid_immediate', 'checkid_setup']:
      # user = users.get_current_user()
      user = self.get_current_user()
      if user:
        from openid.extensions.sreg import SRegRequest,SRegResponse
        sreg_req = SRegRequest.fromOpenIDRequest(oidresponse.request)
        logging.info("sreg_req:%s",sreg_req.allRequestedFields())
        if sreg_req.wereFieldsRequested():
          user_data = {'nickname':user.nickname,
                       'email':user.email}
          sreg_resp = SRegResponse.extractResponse(sreg_req, user_data)
          sreg_resp.toMessage(oidresponse.fields)
        # add nickname, using the Simple Registration Extension:
        # http://www.openidenabled.com/openid/simple-registration-extension/
        #oidresponse.fields.setArg('http://openid.net/sreg/1.0', 'nickname', user.nickname)
        #oidresponse.fields.setArg('http://openid.net/sreg/1.0', 'email', user.email)
        #oidresponse.fields.setArg('http://openid.net/srv/ax/1.0', 'nickname', user.nickname)
        #oidresponse.fields.setArg('http://openid.net/srv/ax/1.0', 'email', user.email)
        from openid.extensions.ax import FetchRequest, FetchResponse	
        res ={'nickname':user.nickname,'email':user.email,'attr0':user.email,'attr1':user.nickname}
        ax_req = FetchRequest.fromOpenIDRequest(oidresponse.request)
        logging.info("ax_req:%s",ax_req.getRequiredAttrs())
        ax_res = FetchResponse()
        for x in ax_req.iterAttrs():
          ax_res.addValue(x.type_uri,res[x.alias] )
        ax_res.toMessage(oidresponse.fields)       
        pass
    logging.info('Using response: %s' % oidresponse)
    encoded_response = oidserver.encodeResponse(oidresponse)

    # update() would be nice, but wsgiref.headers.Headers doesn't implement it
    for header, value in encoded_response.headers.items():
      self.response.headers[header] = str(value)

    if encoded_response.code in (301, 302):
      self.redirect(self.response.headers['location'])
    else:
      self.response.set_status(encoded_response.code)

    if encoded_response.body:
      logging.debug('Sending response body: %s' % encoded_response.body)
      self.response.out.write(encoded_response.body)
    else:
      self.response.out.write('')
开发者ID:patou,项目名称:facebook-openid,代码行数:55,代码来源:provider.py

示例10: add_sreg_fields

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
 def add_sreg_fields(self, oidresponse, user):
     """
     Add requested Simple Registration Extension fields to oidresponse
     and return it.
     """
     sreg_req = SRegRequest.fromOpenIDRequest(oidresponse.request)
     if sreg_req.wereFieldsRequested():
         logging.debug("respond: sreg_req:%s",
                       sreg_req.allRequestedFields())
         sreg_map = dict(
             ((key, val) for (key, val) in 
              {'nickname':user.nickname(), 'email':user.email()}.items()
              if key in sreg_req.allRequestedFields()))
         oidresponse.addExtension(
             SRegResponse.extractResponse(sreg_req, sreg_map))
     return oidresponse
开发者ID:jpellerin,项目名称:duo_web,代码行数:18,代码来源:provider.py

示例11: _add_user_attribs

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
def _add_user_attribs(request, openid_request, openid_response):
    # Add ax and sreg result data
    sreg_request = SRegRequest.fromOpenIDRequest(openid_request)
    ax_request = ax.FetchRequest.fromOpenIDRequest(openid_request)
    rpconfig = utils.get_rpconfig(openid_request.trust_root)
    form = UserAttribsRequestForm(
        request, sreg_request, ax_request, rpconfig)
    if form.data_approved_for_request:
        sreg_response = SRegResponse.extractResponse(
            sreg_request, form.data_approved_for_request)
        openid_response.addExtension(sreg_response)
        if ax_request is not None:
            ax_response = ax.FetchResponse(ax_request)
            for k, v in form.data_approved_for_request.iteritems():
                if AX_DATA_FIELDS.getNamespaceURI(k) in ax_request:
                    ax_response.addValue(AX_DATA_FIELDS.getNamespaceURI(k), v)
            openid_response.addExtension(ax_response)
开发者ID:miing,项目名称:mci_migo,代码行数:19,代码来源:server.py

示例12: Respond

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
  def Respond(self, oidresponse):
    """Send an OpenID response.

    Args:
      oidresponse: OpenIDResponse
      The response to send, usually created by OpenIDRequest.answer().
    """
    logging.info('Respond: oidresponse.request.mode ' + oidresponse.request.mode)

    if oidresponse.request.mode in ['checkid_immediate', 'checkid_setup']:
      user = Auth.AuthenticatedUser(self.request)
      if user:
        from openid.extensions.sreg import SRegRequest,SRegResponse
        sreg_req = SRegRequest.fromOpenIDRequest(oidresponse.request)
        if sreg_req.wereFieldsRequested():
          logging.info("sreg_req:%s",sreg_req.allRequestedFields())
          user_data = {'nickname':user.nickname(),
                       'email':user.email}
          sreg_resp = SRegResponse.extractResponse(sreg_req, user_data)
          sreg_resp.toMessage(oidresponse.fields)        
        # add nickname, using the Simple Registration Extension:
        # http://www.openidenabled.com/openid/simple-registration-extension/
#mrk
#        oidresponse.fields.setArg('http://openid.net/sreg/1.0', 'nickname', user.nickname())
#        oidresponse.fields.setArg('http://openid.net/sreg/1.0', 'email', user.email())
        pass
    logging.info('Using response: %s' % oidresponse)
    encoded_response = oidserver.encodeResponse(oidresponse)

    # update() would be nice, but wsgiref.headers.Headers doesn't implement it
    for header, value in encoded_response.headers.items():
      self.response.headers[header] = str(value)

    if encoded_response.code in (301, 302):
      self.redirect(self.response.headers['location'])
    else:
      self.response.set_status(encoded_response.code)

    if encoded_response.body:
      logging.debug('Sending response body: %s' % encoded_response.body)
      self.response.out.write(encoded_response.body)
    else:
      self.response.out.write('')
开发者ID:wibge,项目名称:EncSubServer,代码行数:45,代码来源:OpenIdProvider.py

示例13: test_login_update_details

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
    def test_login_update_details(self):
        settings.OPENID_UPDATE_DETAILS_FROM_SREG = True
        user = User.objects.create_user('testuser', '[email protected]')
        useropenid = UserOpenID(
            user=user,
            claimed_id='http://example.com/identity',
            display_id='http://example.com/identity')
        useropenid.save()

        # Posting in an identity URL begins the authentication request:
        response = self.client.post('/openid/login/',
            {'openid_identifier': 'http://example.com/identity',
             'next': '/getuser/'})
        self.assertContains(response, 'OpenID transaction in progress')

        # Complete the request, passing back some simple registration
        # data.  The user is redirected to the next URL.
        openid_request = self.provider.parseFormPost(response.content)
        sreg_request = SRegRequest.fromOpenIDRequest(openid_request)
        openid_response = openid_request.answer(True)
        sreg_response = SRegResponse.extractResponse(
            sreg_request, {'nickname': 'someuser', 'fullname': 'Some User',
                           'email': '[email protected]'})
        openid_response.addExtension(sreg_response)
        response = self.complete(openid_response)
        self.assertRedirects(response, 'http://testserver/getuser/')

        # And they are now logged in as testuser (the passed in
        # nickname has not caused the username to change).
        response = self.client.get('/getuser/')
        self.assertEquals(response.content, 'testuser')

        # The user's full name and email have been updated.
        user = User.objects.get(username='testuser')
        self.assertEquals(user.first_name, 'Some')
        self.assertEquals(user.last_name, 'User')
        self.assertEquals(user.email, 'foo[email protected]')
开发者ID:gcr,项目名称:twg,代码行数:39,代码来源:test_views.py

示例14: openid_decide

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
def openid_decide(request):
    """
    The page that asks the user if they really want to sign in to the site, and
    lets them add the consumer to their trusted whitelist.
    # If user is logged in, ask if they want to trust this trust_root
    # If they are NOT logged in, show the landing page
    """
    orequest = request.session.get("OPENID_REQUEST")
    # No request ? Failure..
    if not orequest:
        logger.warning(
            "OpenID decide view failed, \
because no OpenID request is saved"
        )
        return redirect("auth_homepage")
    sreg_request = SRegRequest.fromOpenIDRequest(orequest)
    logger.debug("SREG request: %s" % sreg_request.__dict__)
    if not request.user.is_authenticated():
        # Not authenticated ? Authenticate and go back to the server endpoint
        return login_require(request, params={NONCE_FIELD_NAME: "1"})

    if request.method == "POST":
        if "cancel" in request.POST:
            # User refused
            logger.info("OpenID decide canceled")
            return redirect(openid_server, params={"cancel": ""})
        else:
            form = DecideForm(sreg_request=sreg_request, data=request.POST)
            if form.is_valid():
                data = form.cleaned_data
                # Remember the choice
                t, created = models.TrustedRoot.objects.get_or_create(
                    user=request.user.id, trust_root=orequest.trust_root
                )
                t.choices = sreg_request.required + [field for field in data if data[field]]
                t.save()
                logger.debug("OpenID decide, user choice:%s" % data)
                return redirect("openid-provider-root")
    else:
        form = DecideForm(sreg_request=sreg_request)
    logger.info("OpenID device view, orequest:%s" % orequest)

    # verify return_to of trust_root
    try:
        trust_root_valid = verifyReturnTo(orequest.trust_root, orequest.return_to) and "Valid" or "Invalid"
    except HTTPFetchingError:
        trust_root_valid = "Unreachable"
    except DiscoveryFailure:
        trust_root_valid = "DISCOVERY_FAILED"

    return render_to_response(
        "idp/openid/decide.html",
        {
            "title": _("Trust this site?"),
            "required": sreg_request.required,
            "optional": sreg_request.optional,
            "trust_root_valid": trust_root_valid,
            "form": form,
        },
        context_instance=RequestContext(request),
    )
开发者ID:josuebrunel,项目名称:authentic2,代码行数:63,代码来源:views.py

示例15: oresponse_to_response

# 需要导入模块: from openid.extensions.sreg import SRegRequest [as 别名]
# 或者: from openid.extensions.sreg.SRegRequest import fromOpenIDRequest [as 别名]
    except ProtocolError, why:
        logger.error('Invalid OpenID message %s' % querydict)
        return oresponse_to_response(server, why)
    if not orequest:
        orequest = request.session.get('OPENID_REQUEST', None)
        if orequest:
            logger.info('Restarting saved request by %s' % orequest.trust_root)
            # remove session stored data:
            pass
            # del request.session['OPENID_REQUEST']
        else:
            logger.info('No OpenID request redirecting to homepage')
            return HttpResponseRedirect('/')
    else:
        logger.info('Received OpenID request: %s' % querydict)
    sreg_request = SRegRequest.fromOpenIDRequest(orequest)
    logger.debug('SREG request: %s' % sreg_request.__dict__)

    if orequest.mode in ("checkid_immediate", "checkid_setup"):
        # User is not logged
        if not request.user.is_authenticated():
            # Site does not want interaction
            if orequest.immediate:
                logger.debug('User not logged and checkid immediate request, \
returning OpenID failure')
                return oresponse_to_response(server, orequest.answer(False))
            else:
            # Try to login
                request.session['OPENID_REQUEST'] = orequest
                logger.debug('User not logged and checkid request, \
redirecting to login page')
开发者ID:pu239ppy,项目名称:authentic2,代码行数:33,代码来源:views.py


注:本文中的openid.extensions.sreg.SRegRequest.fromOpenIDRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。