本文整理汇总了Python中bottle.request.get_cookie方法的典型用法代码示例。如果您正苦于以下问题:Python request.get_cookie方法的具体用法?Python request.get_cookie怎么用?Python request.get_cookie使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle.request
的用法示例。
在下文中一共展示了request.get_cookie方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main_form
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_cookie [as 别名]
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
###############################################################################
示例2: stop_server
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_cookie [as 别名]
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
###############################################################################
示例3: check_pass
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_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
示例4: session
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_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
示例5: before_request
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_cookie [as 别名]
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')
示例6: user_required
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_cookie [as 别名]
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]
示例7: get_pagination_limit
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_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
示例8: dl_queue_list
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_cookie [as 别名]
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("/")
示例9: checkAuthenticated
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_cookie [as 别名]
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
示例10: get_logged_in_user
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_cookie [as 别名]
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
示例11: _get_logged_user
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_cookie [as 别名]
def _get_logged_user():
token = bottle_req.get_cookie(_COOKIE_NAME)
if not token:
return None
return application.get_authentication().unpack_jwt(token)
示例12: index
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_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)
示例13: _initBottle
# 需要导入模块: from bottle import request [as 别名]
# 或者: from bottle.request import get_cookie [as 别名]
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')