예제 #1
0
def main(argv):

    # If the Credentials don't exist or are invalid run through the native client
    # flow. The Storage object will ensure that if successful the good
    # Credentials will get written back to a file.
    storage = Storage('umbrowser_credentials.dat')
    credentials = storage.get()
    p = httplib2.ProxyInfo(proxy_type=httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL, proxy_host='www-cache.it.usyd.edu.au', proxy_port=8000)
    h = httplib2.Http(proxy_info=p)
    if credentials is None or credentials.invalid:
        credentials = run(FLOW, storage, h)
    cjson = json.loads(credentials.to_json())
    # Create an httplib2.Http object to handle our HTTP requests and authorize it
    # with our good Credentials.
    http = httplib2.Http(proxy_info=p)
    #http = credentials.authorize(http)
    c = connection.Connection(uri = 'http://ec2-54-251-12-234.ap-southeast-1.compute.amazonaws.com:2005/', credentials = credentials, http = http)

    b = browse()
    b.um = Personis_server.Access(connection=c, debug=True)
    reslist = b.um.ask(context=["Personal"],view=['firstname'])
    Personis_util.printcomplist(reslist)
    b.username = reslist[0].value
    print b.username

    b.cmdloop()
예제 #2
0
    def logged_in(self, code):
        flow = cherrypy.session.get('flow')
        if not flow:
            raise IOError()
        credentials = flow.step2_exchange(cherrypy.request.params)
        http = httplib2.Http()
        http = credentials.authorize(http)
        cjson = credentials.to_json()
        cjson = json.loads(cjson)
        content = http.request('https://www.googleapis.com/oauth2/v1/userinfo?access_token='+cjson['access_token'])
        #print 'content', content
        usr = json.loads(content[1])
        cherrypy.session['user'] = usr
        self.users[usr['id']] = [usr, credentials]
        self.users.sync()
        
        if not 'client_id' in cherrypy.session:
            raise cherrypy.HTTPRedirect(cherrypy.session['target_url'])

        cli = self.oauth_clients[cherrypy.session['client_id']]
        print 'loggedin session id',cherrypy.session.id

        # if no model for user, create one.
        if not os.path.exists(os.path.join(self.modeldir,usr['id'])):
            fn = os.path.join('tmp',usr['id'])
            #f1 = open('Modeldefs/user.template','r').read()
            #f = open(fn, 'w')
            #f.write(f1%(usr['given_name'],usr['family_name'], usr['gender'], usr['email']))
            #f.close()
            mkmodel(model=usr['id'], mfile='Modeldefs/user.prod', modeldir=self.modeldir, user=usr['id'], password='')
            um = Personis_a.Access(model=usr['id'], modeldir=self.modeldir, user=usr['id'], password='')
            ev = Personis_base.Evidence(source="Create_Model", evidence_type="explicit", value=usr['given_name'])
            um.tell(context=["Personal"], componentid='firstname', evidence=ev)
            ev = Personis_base.Evidence(source="Create_Model", evidence_type="explicit", value=usr['family_name'])
            um.tell(context=["Personal"], componentid='lastname', evidence=ev)
            ev = Personis_base.Evidence(source="Create_Model", evidence_type="explicit", value=usr['gender'])
            um.tell(context=["Personal"], componentid='gender', evidence=ev)
            ev = Personis_base.Evidence(source="Create_Model", evidence_type="explicit", value=usr['email'])
            um.tell(context=["Personal"], componentid='email', evidence=ev)
            reslist = um.ask(context=["Personal"], view=['firstname','email'])
            Personis_util.printcomplist(reslist)


        # if it's mneme, then don't ask whether it's all ok. just do it.
        #if cli.secret == 'personis_client_secret_mneme':
            #raise cherrypy.HTTPRedirect('/allow')
        
        #otherwise, ask yes/no                
        base_path = os.path.dirname(os.path.abspath(__file__))
        loader = TemplateLoader([base_path])
        tmpl = loader.load('appQuery.html')
        stream = tmpl.generate(name=usr['given_name'], app=cli.friendly_name, icon=cli.icon)
        return stream.render('xhtml')
예제 #3
0
파일: main_new.py 프로젝트: jbu/Mneme
    def authorized(self, code, state=None):
        flow = cherrypy.session.get('flow')
        if not flow:
            raise IOError()
        print cherrypy.request.params
        p = httplib2.ProxyInfo(proxy_type=httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL, proxy_host='www-cache.it.usyd.edu.au', proxy_port=8000)
        h = httplib2.Http(proxy_info=p)
        credentials = flow.step2_exchange(cherrypy.request.params, h)
        ht = httplib2.Http(proxy_info=p)
        c = connection.Connection(uri = self.oauthconf['personis_uri'], credentials = credentials, http = ht)
        #credentials.authorize(ht)
        cherrypy.session['connection'] = c

        cherrypy.session['cur_session'] = "Session 1"

        um = Personis_Access(connection=c, debug=True)
        app_manager = Personis_App_Manager(ACCESS_TYPE, um)
        personis_vis = Personis_Visualisation_Manager(ACCESS_TYPE, um)

        cherrypy.session['um'] = um
        cherrypy.session['appmgr'] = app_manager
        cherrypy.session['vismgr'] = personis_vis

        #ev = Personis_base.Evidence(source="build_model.py", evidence_type="explicit", value='testname')
        #um.um.tell(context=["Personal"], componentid='firstname', evidence=ev)

        reslist = um.um.ask(context=["Personal"],view=['firstname'])
        Personis_util.printcomplist(reslist)
        cherrypy.session['username'] = reslist[0].value
        print "user name: "+str(cherrypy.session['username'])
        #um.tell_login_time('log-in')
        redir = cherrypy.session.get('redirect')
        
        if redir == None:
            print "No redirect found"+str(redir)
            redir = '/browse/'
        raise cherrypy.HTTPRedirect(redir)
예제 #4
0
파일: watch.py 프로젝트: dbarua/personis
if __name__ == '__main__':

    httplib2.debuglevel=0
    storage = Storage('credentials.dat')
    credentials = storage.get()
    p = httplib2.ProxyInfo(proxy_type=httplib2.socks.PROXY_TYPE_HTTP_NO_TUNNEL, proxy_host='www-cache.it.usyd.edu.au', proxy_port=8000)
    h = httplib2.Http(proxy_info=p)
    if credentials is None or credentials.invalid:
        credentials = run(FLOW, storage, h)
    cjson = json.loads(credentials.to_json())
    http = httplib2.Http(proxy_info=p)
    c = connection.Connection(uri = personis_uri, credentials = credentials, http = http)

    um = Personis_server.Access(connection=c, debug=True)
    reslist = um.ask(context=["Personal"],view=['firstname'])
    Personis_util.printcomplist(reslist)
    username = reslist[0].value
    print username

    install_inactivity(um)

    idle = idler();
    while True:
        i = idle.getIdleTime()
        if i < idletimeout:
            start = time.time()
            while i < idletimeout:
                time.sleep(idletimeout)
                i = idle.getIdleTime()
            end = time.time()
            print 'ended activity of ',int(end-start)