def login(req, username, password): user = dms.username.get_by_id(username) if user and user.username==username: if user.password == password: if not sessions.has_key(username): sessions.add(username, req.connection.remote_addr[0]) # establish random 20 character session_id. # chars = string.letters + string.digits session_id = '' for x in range(20): session_id += whrandom.choice(chars) user.session_id = session_id user.save() log(3, 'setting cookie') req.headers_out['Set-Cookie']='lampadas=' + session_id + '; path=/; expires=Wed, 09-Nov-2030 23:59:00 GMT' uri = URI('home' + referer_lang_ext(req)) uri.base = '../../' return page_factory.page(uri) else: return "Wrong password" else: return "User not found"
def logout(req, username): sessions.delete(username) user = dms.username.get_by_id(username) user.session_id = '' user.save() log(3, 'clearing cookie') req.headers_out['Set-Cookie']='lampadas=foo; path=/; expires=Wed, 09-Nov-1980 23:59:00 GMT' uri = URI('home' + referer_lang_ext(req)) uri.base = '../../' return page_factory.page(uri)
def document(req, title='', short_title='', pub_status_code='', type_code='', topic_code='', username='', maintained='', maintainer_wanted='', lang='', review_status_code='', tech_review_status_code='', pub_date='', last_update='', tickle_date='', isbn='', encoding='', rating='', format_code='', dtd_code='', license_code='', copyright_holder='', sk_seriesid='', abstract='', short_desc='', collection_code='', columns={}, layout='compact'): """ Returns the results of a document search. """ # Read session state sessions.get_session(req) uri = URI(req.uri) page = dms.page.get_by_id('doctable') # serve search results by manually replacing the # doctable here instead of during the regular call. # It's a bit ugly, but works. # We store and restore the contents to avoid doing # a copy.deepcopy() which I haven't tested but imagine to # be rather expensive. -- DCM save_page = page.page[uri.lang] table = tables.doctable(uri, title=title, short_title=short_title, pub_status_code=pub_status_code, type_code=type_code, topic_code=topic_code, username=username, maintained=maintained, maintainer_wanted=maintainer_wanted, lang=lang, review_status_code=review_status_code, tech_review_status_code=tech_review_status_code, pub_date=pub_date, last_update=last_update, tickle_date=tickle_date, isbn=isbn, encoding=encoding, rating=rating, format_code=format_code, dtd_code=dtd_code, license_code=license_code, copyright_holder=copyright_holder, sk_seriesid=sk_seriesid, abstract=abstract, short_desc=short_desc, collection_code=collection_code, layout=layout, show_search=1) page.page[uri.lang] = page.page[uri.lang].replace('|tabdocs|', table) uri = URI('doctable' + referer_lang_ext(req)) uri.base = '../../' html = page_factory.build_page(page, uri) # Restore the original page page.page[uri.lang] = save_page return html
def document(req, title='', short_title='', pub_status_code='', type_code='', topic_code='', username='', maintained='', maintainer_wanted='', lang='', review_status_code='', tech_review_status_code='', pub_date='', last_update='', tickle_date='', isbn='', encoding='', rating='', format_code='', dtd_code='', license_code='', copyright_holder='', sk_seriesid='', abstract='', short_desc='', collection_code='', columns={}, layout='compact' ): """ Returns the results of a document search. """ # Read session state sessions.get_session(req) uri = URI(req.uri) page = dms.page.get_by_id('doctable') # serve search results by manually replacing the # doctable here instead of during the regular call. # It's a bit ugly, but works. # We store and restore the contents to avoid doing # a copy.deepcopy() which I haven't tested but imagine to # be rather expensive. -- DCM save_page = page.page[uri.lang] table = tables.doctable(uri, title = title, short_title = short_title, pub_status_code = pub_status_code, type_code = type_code, topic_code = topic_code, username = username, maintained = maintained, maintainer_wanted = maintainer_wanted, lang = lang, review_status_code = review_status_code, tech_review_status_code = tech_review_status_code, pub_date = pub_date, last_update = last_update, tickle_date = tickle_date, isbn = isbn, encoding = encoding, rating = rating, format_code = format_code, dtd_code = dtd_code, license_code = license_code, copyright_holder = copyright_holder, sk_seriesid = sk_seriesid, abstract = abstract, short_desc = short_desc, collection_code = collection_code, layout = layout, show_search = 1) page.page[uri.lang] = page.page[uri.lang].replace('|tabdocs|', table) uri = URI('doctable' + referer_lang_ext(req)) uri.base = '../../' html = page_factory.build_page(page, uri) # Restore the original page page.page[uri.lang] = save_page return html