Exemplo n.º 1
0
 def oauth2callback(self, error=False, **kwargs):
     if error:
         return error
     oauth = get_session()['gplus_oauth']
     oauth.get_credentials(**kwargs)
     get_session()['person'] = oauth.get_person()
     return view.redirect('/')
Exemplo n.º 2
0
 def twitter_login(self):
     redirect_url, tokens = twitter.start_oauth(
         'http://localhost:8000/twitter_oauth')
     get_session()['twitter_request_token'] = tokens
     self.twitter_session = get_session(
     )['twitter_request_token']  #workaround for disappearing session key 2.8.2013 Rod Shapeley
     return view.redirect(redirect_url)
Exemplo n.º 3
0
Arquivo: web.py Projeto: darius/spnet
 def oauth2callback(self, error=False, **kwargs):
     if error:
         return error
     oauth = get_session()['gplus_oauth']
     oauth.get_credentials(**kwargs)
     get_session()['person'] = oauth.get_person()
     return view.redirect('/')
Exemplo n.º 4
0
Arquivo: view.py Projeto: darius/spnet
def get_view_options():
    'get dict of session kwargs passed to view templates'
    try:
        return get_session()['viewArgs']
    except KeyError:
        d = {}
        get_session()['viewArgs'] = d
        return d
Exemplo n.º 5
0
def get_view_options():
    "get dict of session kwargs passed to view templates"
    try:
        return get_session()["viewArgs"]
    except KeyError:
        d = {}
        get_session()["viewArgs"] = d
        return d
Exemplo n.º 6
0
def get_view_options():
    'get dict of session kwargs passed to view templates'
    try:
        return get_session()['viewArgs']
    except KeyError:
        d = {}
        get_session()['viewArgs'] = d
        return d
Exemplo n.º 7
0
 def twitter_oauth(self, oauth_token, oauth_verifier):
     t = get_session()['twitter_request_token']
     auth = twitter.complete_oauth(t[0], t[1], oauth_verifier)
     p, user, api = twitter.get_auth_person(auth)
     get_session()['person'] = p
     get_session()['twitter_user'] = user
     get_session()['twitter_api'] = api
     self.twitter_auth = auth # just for hand testing
     return 'Logged in to twitter'
Exemplo n.º 8
0
 def _POST(self, personID, topic, state, parents, topic2=''):
     'add or remove topic from PaperInterest depending on state'
     topic = topic or topic2 # use whichever is non-empty
     topic = core.SIG.standardize_id(topic) # must follow hashtag rules
     personID = ObjectId(personID)
     state = int(state)
     if state: # make sure topic exists
         sig = core.SIG.find_or_insert(topic)
     interest = self.set_interest(personID, topic, state, parents)
     get_session()['person'].force_reload(True) # refresh user
     return interest
Exemplo n.º 9
0
 def _POST(self, personID, topic, state, parents, topic2=''):
     'add or remove topic from PaperInterest depending on state'
     topic = topic or topic2  # use whichever is non-empty
     topic = core.SIG.standardize_id(topic)  # must follow hashtag rules
     personID = ObjectId(personID)
     state = int(state)
     if state:  # make sure topic exists
         sig = core.SIG.find_or_insert(topic)
     interest = self.set_interest(personID, topic, state, parents)
     get_session()['person'].force_reload(True)  # refresh user
     return interest
Exemplo n.º 10
0
 def login(self, email, password):
     'check password and create session if authenticated'
     try:
         a = core.EmailAddress(email)
     except KeyError:
         return 'no such email address'
     p = a.parent
     if p.authenticate(password):
         get_session()['email'] = email
         get_session()['person'] = p
     else:
         return 'bad password'
     return view.redirect('/view?view=person&person=' + str(p._id))
Exemplo n.º 11
0
 def login(self, email, password):
     'check password and create session if authenticated'
     try:
         a = core.EmailAddress(email)
     except KeyError:
         return 'no such email address'
     p = a.parent
     if p.authenticate(password):
         get_session()['email'] = email
         get_session()['person'] = p
     else:
         return 'bad password'
     return view.redirect('/view?view=person&person=' + str(p._id))
Exemplo n.º 12
0
 def oauth2callback(self, error=False, **kwargs):
     if error:
         return error
     try:
         oauth = get_session()['gplus_oauth']
     except KeyError:
         return view.report_error('session storage failed', 403,
                                  '''Login session info storage (cookie)
     failed.  Please make sure that your browser accepts cookies
     from selectedpapers.net. ''', traceback=False)
     oauth.get_credentials(**kwargs)
     get_session()['person'] = oauth.get_person()
     return view.redirect('/')
Exemplo n.º 13
0
 def __call__(self, doc=None, **kwargs):
     f = self.template.render
     kwargs.update(self.kwargs)
     session = get_session()
     try:
         kwargs.update(session["viewArgs"])
     except KeyError:
         pass
     if doc is not None:
         kwargs[self.name] = doc
     try:
         user = session["person"]
     except KeyError:
         user = session["person"] = None
     if user and user.force_reload():
         user = user.__class__(user._id)  # reload from DB
         session["person"] = user  # save on session
     return f(
         kwargs=kwargs,
         hasattr=hasattr,
         enumerate=enumerate,
         urlencode=urllib.urlencode,
         list_people=people_link_list,
         getattr=getattr,
         str=str,
         map=map_helper,
         user=user,
         display_datetime=display_datetime,
         timesort=timesort,
         recentEvents=recentEventsDeque,
         len=len,
         messageOfTheDay=messageOfTheDay,
         Selection=webui.Selection,
         **kwargs
     )  # apply template
Exemplo n.º 14
0
 def _search(self, searchString=None, searchID=None, ipage=0,
             block_size=10, session=None):
     import arxiv
     ipage = int(ipage)
     block_size = int(block_size)
     if session is None:
         session = get_session()
     if searchID: # just get this ID
         return ParentCollection._search(self, searchID)
     if not searchString:
         s = view.report_error('empty searchString', 400,
                               'You did not provide a search string.')
         return rest.Response(s)
     elif arxiv.is_id_string(searchString): # just get this ID
         return ParentCollection._search(self, searchString)
     try: # get from existing query results
         queryResults = session['queryResults']
         if queryResults.get_page(ipage, self.collectionArgs['uri'],
                                  searchString=searchString):
             return queryResults
     except KeyError:
         pass # no stored queryResults, so construct it
     pbl = view.PaperBlockLoader(arxiv.search_arxiv,
                                 uri=self.collectionArgs['uri'])
     queryResults = view.MultiplePages(pbl, block_size, ipage,
                                       self.collectionArgs['uri'],
                                       'arXiv.org Search Results',
                                       searchString=searchString)
     session['queryResults'] = queryResults # keep for this user
     return queryResults
Exemplo n.º 15
0
 def __call__(self, doc=None, **kwargs):
     f = self.template.render
     kwargs.update(self.kwargs)
     session = get_session()
     try:
         kwargs.update(session['viewArgs'])
     except KeyError:
         pass
     if doc is not None:
         kwargs[self.name] = doc
     try:
         user = session['person']
     except KeyError:
         user = session['person'] = None
     if user and user.force_reload():
         user = user.__class__(user._id)  # reload from DB
         session['person'] = user  # save on session
     return f(kwargs=kwargs,
              hasattr=hasattr,
              enumerate=enumerate,
              urlencode=urllib.urlencode,
              list_people=people_link_list,
              getattr=getattr,
              str=str,
              map=map_helper,
              user=user,
              display_datetime=display_datetime,
              timesort=timesort,
              recentEvents=recentEventsDeque,
              len=len,
              Selection=webui.Selection,
              **kwargs)  # apply template
Exemplo n.º 16
0
    def _search(self,
                searchString=None,
                searchID=None,
                ipage=0,
                block_size=20,
                session=None):
        import pubmed
        if not searchString:
            s = view.report_error('empty searchString', 400,
                                  'You did not provide a search string.')
            return rest.Response(s)
        ipage = int(ipage)
        block_size = int(block_size)
        try:  # get from existing query results
            queryResults = get_session()['queryResults']
            if queryResults.get_page(ipage,
                                     self.collectionArgs['uri'],
                                     searchString=searchString):
                return queryResults
        except KeyError:
            pass  # no stored queryResults, so construct it
        try:
            ps = pubmed.PubmedSearch(searchString, block_size)
            pbl = view.PaperBlockLoader(ps, uri=self.collectionArgs['uri'])
            queryResults = view.MultiplePages(pbl,
                                              block_size,
                                              ipage,
                                              self.collectionArgs['uri'],
                                              'Pubmed Search Results',
                                              searchString=searchString)
        except (errors.BackendFailure, KeyError):
            s = view.report_error(
                'eutils error: ' + searchString, 502,
                '''Unfortunately, the NCBI eutils server
failed to perform the requested query.  
To run the <A HREF="/papers?%s">same search</A> on
NCBI Pubmed, please click here.  When you find a paper
of interest, you can copy its PMID (Pubmed ID) and
paste it in the search box on this page.''' % urlencode(
                    dict(searchType='ncbipubmed', searchString=searchString)))
            return rest.Response(s)
        get_session()['queryResults'] = queryResults  # keep for this user
        return queryResults
Exemplo n.º 17
0
 def check_permission(self, method, personID, *args, **kwargs):
     if method == 'GET': # permitted
         return False
     try:
         if personID != get_session()['person']._id:
             return view.report_error('TRAP set_interest by different user!', 403,
                                   "You cannot change someone else's settings!")
     except (KeyError,AttributeError):
         return view.report_error('TRAP set_interest, not logged in!', 401,
                                  'You must log in to access this interface')
Exemplo n.º 18
0
 def check_permission(self, method, *args, **kwargs):
     if method == 'GET': # permitted
         return False
     user = get_session().get('person', None)
     if not user:
         return view.report_error('TRAP set_interest, not logged in!', 401,
                                  'You must log in to access this interface')
     person = kwargs['parents'].values()[0]
     if person != user:
         return view.report_error('TRAP set_interest by different user!', 403,
                                  "You cannot change someone else's settings!")
Exemplo n.º 19
0
 def check_permission(self, method, personID, *args, **kwargs):
     if method == 'GET':  # permitted
         return False
     try:
         if personID != get_session()['person']._id:
             return view.report_error(
                 'TRAP set_interest by different user!', 403,
                 "You cannot change someone else's settings!")
     except (KeyError, AttributeError):
         return view.report_error(
             'TRAP set_interest, not logged in!', 401,
             'You must log in to access this interface')
Exemplo n.º 20
0
 def check_permission(self, method, *args, **kwargs):
     if method == 'GET':  # permitted
         return False
     user = get_session().get('person', None)
     if not user:
         return view.report_error(
             'TRAP set_interest, not logged in!', 401,
             'You must log in to access this interface')
     person = kwargs['parents'].values()[0]
     if person != user:
         return view.report_error(
             'TRAP set_interest by different user!', 403,
             "You cannot change someone else's settings!")
Exemplo n.º 21
0
 def _GET(self, docID, parents=None):
     try:  # use cached query results if present
         queryResults = get_session()['queryResults']
     except (AttributeError, KeyError):
         pass
     else:
         try:  # use cached docData if found for this docID
             docData = queryResults.get_doc_data(docID,
                                                 self.collectionArgs['uri'])
         except KeyError:  # not in query results
             pass
         else:
             return self.klass(docData=docData,
                               insertNew='findOrInsert').parent
     return self.klass(docID, insertNew='findOrInsert').parent
Exemplo n.º 22
0
    def _search(self, searchString=None, searchID=None, ipage=0,
                block_size=20):
        import pubmed
        if not searchString:
            s = view.report_error('empty searchString', 400,
                                  'You did not provide a search string.')
            return rest.Response(s)
        ipage = int(ipage)
        block_size = int(block_size)
        try: # get from existing query results
            queryResults = get_session()['queryResults']
            if queryResults.get_page(ipage, self.collectionArgs['uri'],
                                     searchString=searchString):
                return queryResults
        except KeyError:
            pass # no stored queryResults, so construct it
        try:
            ps = pubmed.PubmedSearch(searchString, block_size)
            pbl = view.PaperBlockLoader(ps, uri=self.collectionArgs['uri'])
            queryResults = view.MultiplePages(pbl, block_size, ipage,
                                              self.collectionArgs['uri'],
                                              'Pubmed Search Results',
                                              searchString=searchString)
        except (errors.BackendFailure,KeyError):
            s = view.report_error('eutils error: ' + searchString, 502,
                                  '''Unfortunately, the NCBI eutils server
failed to perform the requested query.  
To run the <A HREF="/papers?%s">same search</A> on
NCBI Pubmed, please click here.  When you find a paper
of interest, you can copy its PMID (Pubmed ID) and
paste it in the search box on this page.''' 
                                  % urlencode(dict(searchType='ncbipubmed',
                                                   searchString=searchString)))
            return rest.Response(s)
        get_session()['queryResults'] = queryResults # keep for this user
        return queryResults
Exemplo n.º 23
0
 def _GET(self, docID, parents=None):
     try: # use cached query results if present
         queryResults = get_session()['queryResults']
     except (AttributeError, KeyError):
         pass
     else:
         try: # use cached docData if found for this docID
             docData = queryResults.get_doc_data(docID,
                                        self.collectionArgs['uri'])
         except KeyError: # not in query results
             pass
         else:
             return self.klass(docData=docData,
                               insertNew='findOrInsert').parent
     return self.klass(docID, insertNew='findOrInsert').parent
Exemplo n.º 24
0
 def _GET(self, docID, getUpdates=False, timeframe=None, **kwargs):
     user = get_session().get('person', None)
     if user and docID == user._id:
         person = user # use cached Person object so we can mark it for refresh
     else:
         person = rest.Collection._GET(self, docID, **kwargs)
     if getUpdates:
         try:
             gpd = person.gplus
         except AttributeError:
             pass
         else: # get list of new posts
             if timeframe == 'all': # get last 10 years
                 l = gpd.update_posts(3650, recentEvents=view.recentEventsDeque)
             else:
                 l = gpd.update_posts(recentEvents=view.recentEventsDeque)
             if l: # need to update our object representation to see them
                 person = rest.Collection._GET(self, docID, **kwargs)
     return person
Exemplo n.º 25
0
 def _GET(self, docID, getUpdates=False, timeframe=None, **kwargs):
     user = get_session().get('person', None)
     if user and docID == user._id:
         person = user  # use cached Person object so we can mark it for refresh
     else:
         person = rest.Collection._GET(self, docID, **kwargs)
     if getUpdates:
         try:
             gpd = person.gplus
         except AttributeError:
             pass
         else:  # get list of new posts
             if timeframe == 'all':  # get last 10 years
                 l = gpd.update_posts(3650,
                                      recentEvents=view.recentEventsDeque)
             else:
                 l = gpd.update_posts(recentEvents=view.recentEventsDeque)
             if l:  # need to update our object representation to see them
                 person = rest.Collection._GET(self, docID, **kwargs)
     return person
Exemplo n.º 26
0
 def twitter_oauth(self, oauth_token, oauth_verifier):
     t = self.twitter_session
     auth = twitter.complete_oauth(
         t[0], t[1],
         oauth_verifier)  #now up to here 7:54pm 2.8.2013 Rod Shapeley
     #print "no problems so far"
     p, user, api = twitter.get_auth_person(
         auth)  #now up to here 7:58pm 2.8.2013 Rod Shapeley
     get_session(
     )['twitter_oauth'] = auth  # workaround - extract p, user, api from auth. 7.8.2013 Rod Shapeley
     self.twitter_auth = auth  # just for hand testing
     # pickling error http://docs.python.org/2/library/pickle.html#what-can-be-pickled-and-unpickled
     # therefore will need to rewrite previous functions (oauth_twitter) as a class twitter.Oauth
     # in order that it can be pickled.  at least, that's a good start. 8:26pm 2.8.2013 Rod Shapeley
     #the problem is not with twitter.complete_oauth, twitter.start_oauth.  No, the problem is with
     #twitter.get_auth_person(auth) .... this is where the problem lies.
     #no, not even there.  looks like it is in assignation of get_session()['person'] = p.
     #return 'Logged in to twitter'
     print 'Logged in to twitter'
     return view.redirect(
         'http://localhost:8000')  #might need to be changed in production
Exemplo n.º 27
0
 def _search(self,
             searchString=None,
             searchID=None,
             ipage=0,
             block_size=10,
             session=None):
     import arxiv
     ipage = int(ipage)
     block_size = int(block_size)
     if session is None:
         session = get_session()
     if searchID:  # just get this ID
         return ParentCollection._search(self, searchID)
     if not searchString:
         s = view.report_error('empty searchString', 400,
                               'You did not provide a search string.')
         return rest.Response(s)
     elif arxiv.is_id_string(searchString):  # just get this ID
         return ParentCollection._search(self, searchString)
     try:  # get from existing query results
         queryResults = session['queryResults']
         if queryResults.get_page(ipage,
                                  self.collectionArgs['uri'],
                                  searchString=searchString):
             return queryResults
     except KeyError:
         pass  # no stored queryResults, so construct it
     pbl = view.PaperBlockLoader(arxiv.search_arxiv,
                                 uri=self.collectionArgs['uri'])
     queryResults = view.MultiplePages(pbl,
                                       block_size,
                                       ipage,
                                       self.collectionArgs['uri'],
                                       'arXiv.org Search Results',
                                       searchString=searchString)
     session['queryResults'] = queryResults  # keep for this user
     return queryResults
Exemplo n.º 28
0
 def gplus_login(self):
     oauth = gplus.OAuth(keys=self.gplus_keys)
     get_session()['gplus_oauth'] = oauth
     return view.redirect(oauth.get_authorize_url())
Exemplo n.º 29
0
 def gplus_login(self):
     oauth = gplus.OAuth(keys=self.gplus_keys)
     get_session()['gplus_oauth'] = oauth
     return view.redirect(oauth.get_authorize_url())
Exemplo n.º 30
0
 def twitter_login(self):
     redirect_url, tokens = twitter.start_oauth('http://localhost:8000/twitter_oauth')
     get_session()['twitter_request_token'] = tokens
     return view.redirect(redirect_url)