Python bottle.response.set_cookie() Examples
The following are 10
code examples of bottle.response.set_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.response
, or try the search function
.
Example #1
Source File: api.py From ray with MIT License | 5 votes |
def _handle_ping_status(): cookie_name, user_token = increase_cookie_timestamp() bottle_resp.set_cookie(cookie_name, user_token.decode('utf-8'))
Example #2
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 #3
Source File: session.py From anom-py with BSD 3-Clause "New" or "Revised" License | 5 votes |
def create_session(user): session = Session.create(user) response.set_cookie("sid", session.key.str_id) # [END create-session]
Example #4
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 #5
Source File: youtube-dl-server.py From youtube-dl-nas with MIT License | 5 votes |
def dl_queue_login(): with open('Auth.json') as data_file: data = json.load(data_file) # Auth info, when docker run making file req_id = request.forms.get("id") req_pw = request.forms.get("myPw") if (req_id == data["MY_ID"] and req_pw == data["MY_PW"]): response.set_cookie("account", req_id, secret="34y823423b23b4234#$@$@#be") redirect("/youtube-dl") else: return template("./static/template/login.tpl", msg="id or password is not correct")
Example #6
Source File: main.py From indiwebmanager with GNU Lesser General Public License v2.1 | 5 votes |
def update_profile(name): """Update profile info (port & autostart & autoconnect)""" response.set_cookie("indiserver_profile", name, None, max_age=3600000, path='/') data = request.json port = data.get('port', args.indi_port) autostart = bool(data.get('autostart', 0)) autoconnect = bool(data.get('autoconnect', 0)) db.update_profile(name, port, autostart, autoconnect)
Example #7
Source File: main.py From indiwebmanager with GNU Lesser General Public License v2.1 | 5 votes |
def start_server(profile): """Start INDI server for a specific profile""" global saved_profile saved_profile = profile global active_profile active_profile = profile response.set_cookie("indiserver_profile", profile, None, max_age=3600000, path='/') start_profile(profile)
Example #8
Source File: webapp.py From modernpython with MIT License | 5 votes |
def check_credentials() -> None: user = request.forms.get('user', '') password = request.forms.get('password', '') if not pubsub.check_user(user, password): return show_main_page() token = secrets.token_bytes(32) logged_in_users[token] = user response.set_cookie('token', token, max_age=60, secret=secret) return show_main_page(user)
Example #9
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 #10
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)