My app has two methods for creating user accounts (for two different
user groups)

The first is conventional and takes email/password and sets
auth.settings.register_onaccept to a function that adds the new user
to various 'permission' groups.

The second authenticates via LinkedIn but on return I'm having trouble
doing one-off set-up (e.g., adding 'permission' groups). I've set
auth.settings.register_onaccept but no registration function is
called. is this correct?

So my question is: when authenticating using LinkedIn how can I do one-
off user set-up?
I've put the relevant code from default.py below...

# LinkedIn
loa = local_import('linkedin_oauth_data')
CLIENT_ID=loa.CLIENT_ID
CLIENT_SECRET=loa.CLIENT_SECRET
AUTH_URL=loa.AUTH_URL
TOKEN_URL=loa.TOKEN_URL
ACCESS_TOKEN_URL=loa.ACCESS_TOKEN_URL
from gluon.contrib.login_methods.oauth10a_account import OAuthAccount
import oauth2 as oauth
import gluon.contrib.simplejson as json

class LinkedInAccount(OAuthAccount):
    def get_user(self):
        if self.accessToken() is None:
            return None
        else:
            client = oauth.Client(self.consumer, self.accessToken())
            resp, content = client.request('https://api.linkedin.com/
v1/people/~:(id,first-name,last-name)')
            if resp['status'] != '200':
                return None
            from gluon.contrib.login_methods.linkedin import Profile
            p = Profile()
            profile = p.create(content)
            return dict(first_name=profile.first_name,
                        last_name=profile.last_name,
                        email=profile.id)


def user():
    auth.settings.login_onaccept = lambda form: registerAgent(form)
    auth.settings.login_next = URL(r=request,f='account')
 
auth.settings.login_form=LinkedInAccount(globals(),CLIENT_ID,CLIENT_SECRET,
AUTH_URL, TOKEN_URL, ACCESS_TOKEN_URL)
    return dict(form=auth())

Reply via email to