本文整理汇总了Python中bottle.response.set_cookie方法的典型用法代码示例。如果您正苦于以下问题:Python response.set_cookie方法的具体用法?Python response.set_cookie怎么用?Python response.set_cookie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle.response
的用法示例。
在下文中一共展示了response.set_cookie方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_pass
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import set_cookie [as 别名]
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
示例2: _handle_ping_status
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import set_cookie [as 别名]
def _handle_ping_status():
cookie_name, user_token = increase_cookie_timestamp()
bottle_resp.set_cookie(cookie_name, user_token.decode('utf-8'))
示例3: session
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import set_cookie [as 别名]
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
示例4: create_session
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import set_cookie [as 别名]
def create_session(user):
session = Session.create(user)
response.set_cookie("sid", session.key.str_id)
# [END create-session]
示例5: get_pagination_limit
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import set_cookie [as 别名]
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
示例6: dl_queue_login
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import set_cookie [as 别名]
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")
示例7: update_profile
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import set_cookie [as 别名]
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)
示例8: start_server
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import set_cookie [as 别名]
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)
示例9: check_credentials
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import set_cookie [as 别名]
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)
示例10: index
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import set_cookie [as 别名]
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)