def login(nickname=None, password=None, login_method=None, action='', remember_me=False, referer=None): if CFG_ACCESS_CONTROL_LEVEL_SITE > 0: return abort(401) # page is not authorized if action: try: action, arguments = mail_cookie_check_authorize_action(action) except InvenioWebAccessMailCookieError: pass form = LoginForm(CombinedMultiDict([ ImmutableMultiDict({'referer': referer} if referer else {}), request.values ]), csrf_enabled=False) try: user = None if not CFG_EXTERNAL_AUTH_USING_SSO: if login_method is 'Local': if form.validate_on_submit(): user = update_login(nickname, password, remember_me) elif login_method in ['openid', 'oauth1', 'oauth2']: pass req = request.get_legacy_request() (iden, nickname, password, msgcode) = webuser.loginUser(req, nickname, password, login_method) if iden: user = update_login(nickname) else: flash(_('Invalid login method.'), 'error') else: req = request.get_legacy_request() # Fake parameters for p_un & p_pw because SSO takes them from the environment (iden, nickname, password, msgcode) = webuser.loginUser(req, '', '', CFG_EXTERNAL_AUTH_USING_SSO) if iden: user = update_login(nickname) if user: flash(_("You are logged in as %s.") % user.nickname, "info") if referer is not None: # Change HTTP method to https if needed. referer = referer.replace(CFG_SITE_URL, CFG_SITE_SECURE_URL) return redirect(referer) except: flash(_("Problem with login."), "error") current_app.config.update( dict((k, v) for k, v in vars(websession_config).iteritems() if "CFG_" == k[:4])) return render_template('webaccount_login.html', form=form)
def search(collection, p, of, ot, so, rm): """Render search page.""" from invenio.legacy.search_engine import perform_request_search if 'action_browse' in request.args \ or request.args.get('action', '') == 'browse': return browse() if 'c' in request.args and len(request.args) == 1 \ and len(request.args.getlist('c')) == 1: return redirect(url_for('.collection', name=request.args.get('c'))) argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' # fix for queries like `/search?p=+ellis` if 'p' in argd: argd['p'] = argd['p'].strip() # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = int(current_user.get('rg')) rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) # back-to-search related code if request and not isinstance(request.get_legacy_request(), cStringIO.OutputType): # store the last search results page session['websearch-last-query'] = request.get_legacy_request() \ .unparsed_uri hit_limit = current_app.config['CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT'] if len(recids) > hit_limit: last_query_hits = None else: last_query_hits = recids # store list of results if user wants to display hits # in a single list, or store list of collections of records # if user displays hits split by collections: session["websearch-last-query-hits"] = last_query_hits ctx = dict( facets=facets.get_facets_config(collection, qid), records=len(get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False), ot=ot) return response_formated_records(recids, collection, of, **ctx)
def search(collection, p, of, so, rm): """ Renders search pages. """ if 'action_browse' in request.args \ or request.args.get('action', '') == 'browse': return browse() if 'c' in request.args and len(request.args) == 1 \ and len(request.args.getlist('c')) == 1: return redirect(url_for('.collection', name=request.args.get('c'))) from invenio.websearch_webinterface import wash_search_urlargd argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = current_user.get('rg') rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) #if so or rm: if len(of) > 0 and of[0] == 'h': recids.reverse() # back-to-search related code if request and not isinstance(request.get_legacy_request(), cStringIO.OutputType): # store the last search results page session['websearch-last-query'] = request.get_legacy_request( ).unparsed_uri if len(recids) > CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT: last_query_hits = None else: last_query_hits = recids # store list of results if user wants to display hits # in a single list, or store list of collections of records # if user displays hits split by collections: session["websearch-last-query-hits"] = last_query_hits ctx = dict( facets=FACETS.config(collection=collection, qid=qid), records=len(get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False)) return response_formated_records(recids, collection, of, **ctx)
def browse(collection, p, f, of, so, rm, rg, jrec): """Render browse page.""" from invenio.legacy.search_engine import browse_pattern_phrases argd = argd_orig = wash_search_urlargd(request.args) colls = [collection.name] + request.args.getlist('c') if f is None and ':' in p[1:]: f, p = string.split(p, ":", 1) argd['f'] = f argd['p'] = p websearch_before_browse.send(collection, **argd) records = map( lambda (r, h): (r.decode('utf-8'), h), browse_pattern_phrases(req=request.get_legacy_request(), colls=colls, p=p, f=f, rg=rg, ln=g.ln)) @register_template_context_processor def index_context(): box = lambda: _create_neareset_term_box(argd_orig) pagination = Pagination(int(ceil(jrec / float(rg))), rg, len(records)) breadcrumbs = current_breadcrumbs + collection_breadcrumbs(collection) return dict( collection=collection, create_nearest_terms_box=box, pagination=pagination, rg=rg, p=p, f=f, easy_search_form=EasySearchForm(csrf_enabled=False), breadcrumbs=breadcrumbs ) return dict(records=records)
def search(collection, p, of, so, rm): """ Renders search pages. """ if 'action_browse' in request.args: return browse() from invenio.websearch_webinterface import wash_search_urlargd argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = current_user.get('rg') rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) if so or rm: recids.reverse() ctx = dict( facets=FACETS.config(collection=collection, qid=qid), records=len(get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False)) return response_formated_records(recids, collection, of, **ctx)
def browse(collection, p, f, of, so, rm, rg, jrec): from invenio.websearch_webinterface import wash_search_urlargd argd_orig = wash_search_urlargd(request.args) collection_breadcrumbs(collection) colls = [collection.name] + request.args.getlist('c') if f is None and ':' in p[1:]: f, p = string.split(p, ":", 1) records = map( lambda (r, h): (r.decode('utf-8'), h), browse_pattern_phrases(req=request.get_legacy_request(), colls=colls, p=p, f=f, rg=rg, ln=g.ln)) @register_template_context_processor def index_context(): return dict( collection=collection, create_nearest_terms_box=lambda: _create_neareset_term_box( argd_orig), pagination=Pagination(int(ceil(jrec / float(rg))), rg, len(records)), rg=rg, p=p, f=f, easy_search_form=EasySearchForm(csrf_enabled=False), ) return dict(records=records)
def register(): req = request.get_legacy_request() # FIXME if cfg.get('CFG_ACCESS_CONTROL_LEVEL_SITE') > 0: return webuser.page_not_authorized(req, "../youraccount/register?ln=%s" % g.ln, navmenuid='youraccount') form = RegisterForm(request.values, csrf_enabled=False) #uid = current_user.get_id() title = _("Register") messages = [] state = "" if form.validate_on_submit(): ruid = webuser.registerUser(req, form.email.data.encode('utf8'), form.password.data.encode('utf8'), form.nickname.data.encode('utf8'), ln=g.ln) if ruid == 0: title = _("Account created") messages.append(_("Your account has been successfully created.")) state = "success" if cfg.get('CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_NEW_ACCOUNT') == 1: messages.append(_("In order to confirm its validity, an email message containing an account activation key has been sent to the given email address.")) messages.append(_("Please follow instructions presented there in order to complete the account registration process.")) if cfg.get('CFG_ACCESS_CONTROL_LEVEL_ACCOUNTS') >= 1: messages.append(_("A second email will be sent when the account has been activated and can be used.")) elif cfg.get('CFG_ACCESS_CONTROL_NOTIFY_USER_ABOUT_NEW_ACCOUNT') != 1: user = User.query.filter(User.email == form.email.data.lower()).one() login_user(user.get_id()) messages.append(_("You can now access your account.")) else: title = _("Registration failure") state = "danger" if ruid == 5: messages.append(_("Users cannot register themselves, only admin can register them.")) elif ruid == 6 or ruid == 1: # Note, code 1 is used both for invalid email, and email sending # problems, however the email address is validated by the form, # so we only have to report a problem sending the email here messages.append(_("The site is having troubles in sending you an email for confirming your email address.")) messages.append(_("The error has been logged and will be taken in consideration as soon as possible.")) else: # Errors [-2, (1), 2, 3, 4] taken care of by form validation messages.append(_("Internal error %(ruid)s", ruid=ruid)) elif request.method == 'POST': title = _("Registration failure") state = "warning" return render_template('accounts/register.html', form=form, title=title, messages=messages, state=state)
def rss(collection, p, jrec, so, rm): """Render RSS feed.""" from invenio.legacy.search_engine import perform_request_search of = 'xr' argd = wash_search_urlargd(request.args) argd['of'] = 'id' # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = current_user.get('rg') rg = int(argd['rg']) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) ctx = dict(records=len( get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg) return response_formated_records(recids, collection, of, **ctx)
def sort_and_rank_records(recids, so=None, rm=None, sf=None, sp=None, p='', jrec=None, rg=None, of='id'): """TODO.""" from invenio.legacy.search_engine import sort_or_rank_records return sort_or_rank_records(request.get_legacy_request(), recids, rm, sf, so, sp, p, jrec=jrec, rg=rg, of=of)
def rss(collection, p, jrec, so, rm): of = 'xr' argd = argd_orig = wash_search_urlargd(request.args) argd['of'] = 'id' # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = current_user.get('rg') rg = int(argd['rg']) qid = get_search_query_id(**argd) recids = perform_request_search(req=request.get_legacy_request(), **argd) if so or rm: recids.reverse() ctx = dict(records=len( get_current_user_records_that_can_be_displayed(qid)), qid=qid, rg=rg) return response_formated_records(recids, collection, of, **ctx)
def search(collection, p, of, ot, so, sf, sp, rm): """Render search page.""" if 'action_browse' in request.args \ or request.args.get('action', '') == 'browse': return browse() if 'c' in request.args and len(request.args) == 1 \ and len(request.args.getlist('c')) == 1: return redirect(url_for('.collection', name=request.args.get('c'))) if 'f' in request.args: args = request.args.copy() args['p'] = "{0}:{1}".format(args['f'], args['p']) del args['f'] return redirect('.search', **args) argd = argd_orig = wash_search_urlargd(request.args) # fix for queries like `/search?p=+ellis` p = p.strip().encode('utf-8') jrec = request.values.get('jrec', 1, type=int) # update search arguments with the search user preferences if 'rg' not in request.values and current_user.get('rg'): argd['rg'] = int(current_user.get('rg')) rg = int(argd['rg']) collection_breadcrumbs(collection) qid = get_search_query_id(p=p, cc=collection.name) recids = Query(p).search(collection=collection.name) records = len(recids) recids = sort_and_rank_records(recids, so=so, rm=rm, sf=sf, sp=sp, p=p, of='id', rg=rg, jrec=jrec) # back-to-search related code if request and not isinstance(request.get_legacy_request(), cStringIO.OutputType): # store the last search results page session['websearch-last-query'] = request.get_legacy_request() \ .unparsed_uri hit_limit = current_app.config['CFG_WEBSEARCH_PREV_NEXT_HIT_LIMIT'] if len(recids) > hit_limit: last_query_hits = None else: last_query_hits = recids # store list of results if user wants to display hits # in a single list, or store list of collections of records # if user displays hits split by collections: session["websearch-last-query-hits"] = last_query_hits ctx = dict( facets=facets.get_facets_config(collection, qid), records=records, rg=rg, create_nearest_terms_box=lambda: _create_neareset_term_box(argd_orig), easy_search_form=EasySearchForm(csrf_enabled=False), ot=ot) # TODO add search services # # WebSearch services # from invenio.modules.search import services # if jrec <= 1 and \ # (em == "" and True or (EM_REPOSITORY["search_services"] in em)): # user_info = collect_user_info(req) # # display only on first search page, and only if wanted # # when 'em' param set. # for answer_relevance, answer_html in services.get_answers( # req, user_info, of, cc, colls_to_search, p, f, ln): # req.write('<div class="searchservicebox">') # req.write(answer_html) # if verbose > 8: # write_warning("Service relevance: %i" % # answer_relevance, req=req) # req.write('</div>') # TODO add external collection search # if not of in ['hcs', 'hcs2']: # perform_external_collection_search_with_em( # req, cc, [p, p1, p2, p3], f, ec, verbose, # ln, selected_external_collections_infos, em=em) return response_formated_records(recids, collection, of, **ctx)