def __init__(self, auth, api_key="", embed=False, auth_url="https://rpxnow.com/api/v2/auth_info", realm="", token_url="", prompt="Choose a provider", language="en", allow_local=False, on_login_failure=None, on_mapped=None): self.auth = auth self.db = auth.db self.environment = auth.environment self.api_key = api_key self.embed = embed self.auth_url = auth_url self.realm = realm self.token_url = token_url self.prompt = prompt self.language = language self.profile = None self.allow_local = allow_local self.on_login_failure = on_login_failure self.on_mapped = on_mapped self.mappings = Storage() self.mappings.Facebook = dict(registration_id="identifier", username="******", email="email", first_name="givenName", last_name="familyName") self.mappings.Google = dict(registration_id="identifier", username="******", email="email", first_name="givenName", last_name="familyName") self.mappings.Yahoo = dict(registration_id="identifier", username="******", email="email", first_name="formatted", last_name="formatted") self.rpx_disabled = [ 'register', 'retrieve_password', 'reset_password', 'change_password', 'profile' ]
def get_user(self): import string request = self.environment.request if request.vars.token: user = Storage() data = urllib.urlencode( dict(apiKey=self.api_key, token=request.vars.token)) auth_info_json = fetch("?".join([self.auth_url, data])) auth_info = json.loads(auth_info_json) if auth_info['stat'] == 'ok': self.profile = auth_info['profile'] provider = self.profile['providerName'] provider = ''.join(c for c in provider if c in string.ascii_letters) for field in self.auth.settings.table_user.fields: user[field] = self.get_mapping(provider, field) if self.on_mapped and user: user = self.on_mapped(user, provider) if self.allow_local: db = self.db user_table = self.auth.settings.table_user if 'username' in user_table.fields: username = '******' else: username = '******' existing = db( user_table[username] == user[username]).select() if len(existing): dbuser = existing.first() if dbuser[self.auth.settings.password_field] != None: self.environment.session.flash = '%s already in use' % username.capitalize( ) return None if 'registration_key' in user_table.fields: if dbuser['registration_key']: self.environment.session.flash = '%s already in use' % username.capitalize( ) return None return user else: return None #auth_info['err']['msg'] return None
def __init__(self, a=request.application, c="plugin_clientapi", f="api", protocol="json", url=None): # append base script to the response apiurl = URL(c="static", f="plugin_clientapi/clientapi.js") if not apiurl in response.files: response.files.append(apiurl) self.settings = Storage() self.settings.application = self.settings.a = a self.settings.controller = self.settings.c = c self.settings.function = self.settings.f = f self.settings.protocol = protocol self.settings.url = url or \ URL(c=self.settings.c, f=self.settings.f, extension=self.settings.protocol) self.settings.setup = True self.settings.onsetup = None self.settings.logged = False self.settings.requires = self.settings.rbac = \ self.settings.log = True gd = globals() self.databases = dict([(name, gd[name]) for name in gd if isinstance(gd[name], DAL)]) self.dbnames = self.databases.keys() self.dbname = request.args(1) if self.dbname in self.dbnames: self.database = gd[dbname] else: try: self.database = db self.dbname = "db" except NameError: raise HTTP(500, T("Database not found"))