Example #1
0
def handle_openid_login_response():
    conn = db.session.connection()
    consumer = openid.Consumer(session, None)
    info = consumer.complete(request.args, request.url)
    if info.status == openid.SUCCESS:
        openid_url = info.identity_url
        values = {}
        ax_resp = ax.FetchResponse.fromSuccessResponse(info)
        if ax_resp:
            attrs = {
                'email': 'http://schema.openid.net/contact/email',
                'name': 'http://schema.openid.net/namePerson/friendly',
            }
            for name, uri in attrs.iteritems():
                try:
                    value = ax_resp.getSingle(uri)
                    if value:
                        values[name] = value
                except KeyError:
                    pass
        account_id = lookup_account_id_by_openid(conn, openid_url)
        if not account_id:
            account_id, account_api_key = insert_account(conn, {
                'name': 'OpenID User',
                'openid': openid_url,
            })
        logger.info("Successfuly identified OpenID user %s (%d) with email '%s' and nickname '%s'",
            openid_url, account_id, values.get('email', ''), values.get('name', ''))
        return login_user_and_redirect(account_id)
    elif info.status == openid.CANCEL:
        raise Exception('OpenID login has been canceled')
    else:
        raise Exception('OpenID login failed')
Example #2
0
 def _handle_openid_login_response(self, req, errors):
     consumer = openid.Consumer(self.session, None)
     info = consumer.complete(req.args, self.login_url)
     if info.status == openid.SUCCESS:
         openid_url = info.identity_url
         values = {}
         ax_resp = ax.FetchResponse.fromSuccessResponse(info)
         if ax_resp:
             attrs = {
                 'email': 'http://schema.openid.net/contact/email',
                 'name': 'http://schema.openid.net/namePerson/friendly',
             }
             for name, uri in attrs.iteritems():
                 try:
                     value = ax_resp.getSingle(uri)
                     if value:
                         values[name] = value
                 except KeyError:
                     pass
         account_id = lookup_account_id_by_openid(self.conn, openid_url)
         if not account_id:
             account_id = insert_account(self.conn, {
                 'name': 'OpenID User',
                 'openid': openid_url,
             })
         logger.info("Successfuly identified OpenID user %s (%d) with email '%s' and nickname '%s'",
             openid_url, account_id, values.get('email', ''), values.get('name', ''))
         self.session['id'] = account_id
     elif info.status == openid.CANCEL:
         errors.append('OpenID verification has been canceled')
     else:
         errors.append('OpenID verification failed')
Example #3
0
 def _handle_openid_login_response(self, req, errors):
     consumer = openid.Consumer(self.session, None)
     info = consumer.complete(req.args, self.login_url)
     if info.status == openid.SUCCESS:
         openid_url = info.identity_url
         values = {}
         ax_resp = ax.FetchResponse.fromSuccessResponse(info)
         if ax_resp:
             attrs = {
                 'email': 'http://schema.openid.net/contact/email',
                 'name': 'http://schema.openid.net/namePerson/friendly',
             }
             for name, uri in attrs.iteritems():
                 try:
                     value = ax_resp.getSingle(uri)
                     if value:
                         values[name] = value
                 except KeyError:
                     pass
         account_id = lookup_account_id_by_openid(self.conn, openid_url)
         if not account_id:
             account_id = insert_account(self.conn, {
                 'name': 'OpenID User',
                 'openid': openid_url,
             })
         else:
             update_account_lastlogin(self.conn, account_id)
         logger.info("Successfuly identified OpenID user %s (%d) with email '%s' and nickname '%s'",
             openid_url, account_id, values.get('email', ''), values.get('name', ''))
         self.session['id'] = account_id
     elif info.status == openid.CANCEL:
         errors.append('OpenID verification has been canceled')
     else:
         errors.append('OpenID verification failed')
Example #4
0
def handle_openid_login_response():
    conn = db.session.connection()
    consumer = openid.Consumer(session, None)
    info = consumer.complete(request.args, request.url)
    if info.status == openid.SUCCESS:
        openid_url = info.identity_url
        values = {}
        ax_resp = ax.FetchResponse.fromSuccessResponse(info)
        if ax_resp:
            attrs = {
                'email': 'http://schema.openid.net/contact/email',
                'name': 'http://schema.openid.net/namePerson/friendly',
            }
            for name, uri in attrs.items():
                try:
                    value = ax_resp.getSingle(uri)
                    if value:
                        values[name] = value
                except KeyError:
                    pass
        account_id = lookup_account_id_by_openid(conn, openid_url)
        if not account_id:
            account_id, account_api_key = insert_account(conn, {
                'name': 'OpenID User',
                'openid': openid_url,
            })
        logger.info("Successfuly identified OpenID user %s (%d) with email '%s' and nickname '%s'",
            openid_url, account_id, values.get('email', ''), values.get('name', ''))
        return login_user_and_redirect(account_id)
    elif info.status == openid.CANCEL:
        raise Exception('OpenID login has been canceled')
    else:
        raise Exception('OpenID login failed')