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('/')
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)
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
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
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'
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
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))
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('/')
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
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
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
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
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')
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!")
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')
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!")
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
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
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
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
def gplus_login(self): oauth = gplus.OAuth(keys=self.gplus_keys) get_session()['gplus_oauth'] = oauth return view.redirect(oauth.get_authorize_url())
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)