Python bottle.request.get_cookie() Examples
The following are 13
code examples of bottle.request.get_cookie().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
bottle.request
, or try the search function
.
Example #1
Source File: main.py From indiwebmanager with GNU Lesser General Public License v2.1 | 6 votes |
def main_form(): """Main page""" global saved_profile drivers = collection.get_families() if not saved_profile: saved_profile = request.get_cookie('indiserver_profile') or 'Simulators' profiles = db.get_profiles() return template(os.path.join(views_path, 'form.tpl'), profiles=profiles, drivers=drivers, saved_profile=saved_profile, hostname=hostname) ############################################################################### # Profile endpoints ###############################################################################
Example #2
Source File: main.py From indiwebmanager with GNU Lesser General Public License v2.1 | 6 votes |
def stop_server(): """Stop INDI Server""" indihub_agent.stop() indi_server.stop() global active_profile active_profile = "" # If there is saved_profile already let's try to reset it global saved_profile if saved_profile: saved_profile = request.get_cookie("indiserver_profile") or "Simulators" ############################################################################### # Driver endpoints ###############################################################################
Example #3
Source File: web.py From mailur with GNU General Public License v3.0 | 5 votes |
def session(callback): cookie_name = 'session' serializer = URLSafeSerializer(conf['SECRET']) def inner(*args, **kwargs): data_raw = data = request.get_cookie(cookie_name) if data_raw: try: data = serializer.loads(data_raw) except (BadSignature, BadData): data = None if data: conf['USER'] = data['username'] request.session = data or {} try: return callback(*args, **kwargs) finally: if request.session: save(request.session) elif not data_raw: pass else: response.delete_cookie(cookie_name) def save(session): cookie_opts = { # keep session for 3 days 'max_age': 3600 * 24 * 3, # for security 'httponly': True, 'secure': request.headers.get('X-Forwarded-Proto') == 'https', } data = serializer.dumps(session) response.set_cookie(cookie_name, data, **cookie_opts) return inner
Example #4
Source File: bottleroutes.py From anvio with GNU General Public License v3.0 | 5 votes |
def before_request(self): # /app/ contains static files and not password protected. if self.password_protected and not request.path.startswith('/app/'): if not self.authentication_secret == request.get_cookie('authentication_secret'): redirect('/app/login.html') response.set_header('Content-Type', 'application/json') response.set_header('Pragma', 'no-cache') response.set_header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate') response.set_header('Expires', 'Thu, 01 Dec 1994 16:00:00 GMT')
Example #5
Source File: session.py From anom-py with BSD 3-Clause "New" or "Revised" License | 5 votes |
def user_required(*permissions): def decorator(fn): def wrapper(*args, **kwargs): session_id = request.get_cookie("sid") if not session_id: return redirect("/login") session = Session.get(session_id) if not session: return redirect("/login") user = session.user.get() if user is None: return redirect("/login") for permission in permissions: if permission not in user.permissions: return abort(403) return fn(user, *args, **kwargs) return wrapper return decorator # [END user-required] # [START create-session]
Example #6
Source File: web.py From CuckooSploit with GNU General Public License v3.0 | 5 votes |
def get_pagination_limit(new_limit): """Defines the right pagination limit and sets cookies accordingly. @params new_limit: new pagination limit """ default_limit = 50 limit_cookie = request.get_cookie("pagination_limit") logging.info("Got cookie: {0}".format(limit_cookie)) cookie_expires = time.mktime((datetime.now() + timedelta(days=365)).timetuple()) if new_limit <= 0: if limit_cookie: try: limit = int(limit_cookie) logging.info("Using limit from cookie: {0}".format(limit)) response.set_cookie("pagination_limit", str(limit), path="/", expires=cookie_expires) except Exception as e: logging.error("Cookie: {0}, exception: {1}".format(limit_cookie, e)) limit = default_limit else: limit = default_limit logging.info("Using default limit: {0}".format(limit)) else: limit = new_limit logging.info("Setting new limit: {0}".format(limit)) response.set_cookie("pagination_limit", str(limit), path="/", expires=cookie_expires) return limit
Example #7
Source File: youtube-dl-server.py From youtube-dl-nas with MIT License | 5 votes |
def dl_queue_list(): with open('Auth.json') as data_file: data = json.load(data_file) userNm = request.get_cookie("account", secret="34y823423b23b4234#$@$@#be") print("CHK : ", userNm) if (userNm == data["MY_ID"]): return template("./static/template/index.tpl", userNm=userNm) else: print("no cookie or fail login") redirect("/")
Example #8
Source File: app.py From aerial_wildlife_detection with MIT License | 5 votes |
def checkAuthenticated(self, admin=False): if self.demoMode: return True try: username = html.escape(request.get_cookie('username')) sessionToken = html.escape(request.get_cookie('session_token')) return self.middleware.isAuthenticated(username, sessionToken, admin) except: return False
Example #9
Source File: webapp.py From modernpython with MIT License | 5 votes |
def get_logged_in_user() -> Optional[User]: token = request.get_cookie('token', secret=secret) if token is not None: return logged_in_users.get(token) return None
Example #10
Source File: proxy.py From github-pages-basic-auth-proxy with MIT License | 4 votes |
def check_pass(username, password): # # First check if already valid JWT Token in Cookie # auth_cookie = request.get_cookie("cs-proxy-auth") if auth_cookie and valid_jwt_token(auth_cookie): print ('PROXY-AUTH: found valid JWT Token in cookie') return True # # GitHub Basic Auth - also working with username + personal_access_token # print ('PROXY-AUTH: doing github basic auth - authType: {0}, owner: {1}'.format(auth_type, owner)) basic_auth = HTTPBasicAuth(username, password) auth_response = requests.get('https://api.github.com/user', auth=basic_auth) if auth_response.status_code == 200: if auth_type == 'onlyGitHubOrgUsers': print ('PROXY-AUTH: doing org membership request') org_membership_response = requests.get('https://api.github.com/user/orgs', auth=basic_auth) if org_membership_response.status_code == 200: for org in org_membership_response.json(): if org['login'] == owner: response.set_cookie("cs-proxy-auth", create_jwt_token()) return True return False else: response.set_cookie("cs-proxy-auth", create_jwt_token()) return True return False
Example #11
Source File: login.py From ray with MIT License | 4 votes |
def _get_logged_user(): token = bottle_req.get_cookie(_COOKIE_NAME) if not token: return None return application.get_authentication().unpack_jwt(token)
Example #12
Source File: webserver.py From pagan with GNU General Public License v2.0 | 4 votes |
def index(): """main functionality of webserver""" default = ["pagan", "python", "avatar", "github"] slogan = request.forms.get("slogan") if not slogan: if request.get_cookie("hist1"): slogan = request.get_cookie("hist1") else: slogan = "pagan" if not request.get_cookie("hist1"): hist1, hist2, hist3, hist4 = default[:] else: hist1 = request.get_cookie("hist1") hist2 = request.get_cookie("hist2") hist3 = request.get_cookie("hist3") hist4 = request.get_cookie("hist4") if slogan in (hist1, hist2, hist3, hist4): history = [hist1, hist2, hist3, hist4] history.remove(slogan) hist1, hist2, hist3 = history[0], history[1], history[2] response.set_cookie("hist1", slogan, max_age=60*60*24*30, httponly=True) response.set_cookie("hist2", hist1, max_age=60*60*24*30, httponly=True) response.set_cookie("hist3", hist2, max_age=60*60*24*30, httponly=True) response.set_cookie("hist4", hist3, max_age=60*60*24*30, httponly=True) # slogan, hist1, hist2, hist3 = escape(slogan), escape(hist1),\ # escape(hist2), escape(hist3) md5 = hashlib.md5() md5.update(slogan) slogan_hash = md5.hexdigest() md5.update(hist1) hist1_hash = md5.hexdigest() md5.update(hist2) hist2_hash = md5.hexdigest() md5.update(hist3) hist3_hash = md5.hexdigest() return template(TEMPLATEINDEX, slogan=slogan, hist1=hist1, hist2=hist2, hist3=hist3, sloganHash=slogan_hash, hist1Hash=hist1_hash, hist2Hash=hist2_hash, hist3Hash=hist3_hash)
Example #13
Source File: app.py From aerial_wildlife_detection with MIT License | 4 votes |
def _initBottle(self): with open(os.path.abspath(os.path.join('modules/ProjectConfiguration/static/templates/projectConfiguration.html')), 'r') as f: self.projConf_template = SimpleTemplate(f.read()) @self.app.route('/config/static/<filename:re:.*>') def send_static(filename): return static_file(filename, root=self.staticDir) @self.app.route('/configuration') def configuration_page(): if self.loginCheck(True): username = html.escape(request.get_cookie('username')) response = self.projConf_template.render( username=username, projectTitle=self.config.getProperty('Project', 'projectName'), projectDescr=self.config.getProperty('Project', 'projectDescription'), numImagesPerBatch=self.config.getProperty('LabelUI', 'numImagesPerBatch'), minImageWidth=self.config.getProperty('LabelUI', 'minImageWidth') ) # response.set_header("Cache-Control", "public, max-age=604800") else: response = bottle.response response.status = 303 response.set_header('Location', '/') return response @self.app.post('/getProjectConfiguration') def get_project_configuration(): if not self.loginCheck(True): abort(401, 'forbidden') @self.app.post('/saveProjectConfiguration') def save_project_configuration(): if not self.loginCheck(True): abort(401, 'forbidden')