本文整理汇总了Python中flask.session.clear方法的典型用法代码示例。如果您正苦于以下问题:Python session.clear方法的具体用法?Python session.clear怎么用?Python session.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.session
的用法示例。
在下文中一共展示了session.clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_session
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def build_session(user_obj, is_permanent=True):
"""On login+signup, builds the server-side session dict with the data we
need. userid being the most important."""
assert user_obj
assert user_obj.id
# make sure session is empty
session.clear()
# fill with relevant data
session['userid'] = user_obj.id
session['role'] = user_obj.role # if you update user.role, update this too
# remember session even over browser restarts?
session.permanent = is_permanent
# could also store ip + browser-agent to verify freshness
# of the session: only allow most critical operations with a fresh
# session
示例2: login_post
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def login_post():
"""
the function handles the login post request and if all information are correct
a session variable is set to store the login information
"""
utils = Webutils()
hostname = platform.node().encode("utf-8")
salt = hashlib.sha512(hostname).hexdigest()
pw_hash = hashlib.sha512(
str(salt + request.form['password']).encode("utf-8")).hexdigest()
if request.form['username'] == utils.cfg.get_value(
"WEB", "username") and pw_hash == utils.cfg.get_value(
"WEB", "password"):
session.clear()
session['logged_in'] = True
session['ip_address'] = request.remote_addr
session.permanent = True
return redirect("/")
return login("Incorrect username or password.", "danger")
示例3: home
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def home():
# session.clear()
if current_user.is_authenticated:
# order = order
session['order'] = OrderClient.get_order_from_session()
try:
products = ProductClient.get_products()
except requests.exceptions.ConnectionError:
products = {
'results': []
}
return render_template('home/index.html', products=products)
# Login
示例4: logout
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def logout():
# The logout payload is an empty string but it is still needed
payload = '""'
tssa = functions.generateTssa(functions.BASE_URL + "account/logout", "POST", payload, session['accessToken'])
headers = {'User-Agent':'Apache-HttpClient/UNAVAILABLE (java 1.4)',
'Authorization':'%s' % tssa,
'X-OsVersion':functions.OS_VERSION,
'X-OsName':'Android',
'X-DeviceID':session['DEVICE_ID'],
'X-VmobID':functions.des_encrypt_string(session['DEVICE_ID']),
'X-AppVersion':functions.APP_VERSION,
'X-DeviceSecret':session['deviceSecret'],
'Content-Type':'application/json; charset=utf-8'}
response = requests.post(functions.BASE_URL + "account/logout", data=payload, headers=headers)
# Clear all of the previously set session variables and then redirect to the index page
session.clear()
return redirect(url_for('index'))
# The confirmation page for a manual lock in
示例5: test_extract_namespace_repo_from_session_present
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def test_extract_namespace_repo_from_session_present(app):
encountered = []
def somefunc(namespace, repository):
encountered.append(namespace)
encountered.append(repository)
# Add the namespace and repository to the session.
session.clear()
session["namespace"] = "foo"
session["repository"] = "bar"
# Call the decorated method.
extract_namespace_repo_from_session(somefunc)()
assert encountered[0] == "foo"
assert encountered[1] == "bar"
示例6: user_session
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def user_session(func):
@wraps(func)
def wrapper(**kwargs):
from app.models import Utils
if Utils.getParam(request.args, 'session', default=None):
user_data = session.get('_user', None)
if user_data and user_data['is_admin']:
session.clear()
user_data = session.get('_user', None)
kwargs['props'] = {'user': user_data,
'cdn': webapp.config['S3_HOST']+'website/',
'host': webapp.config['HOST']+'/'
}
return func(**kwargs)
return wrapper
示例7: test_post_with_token
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def test_post_with_token(client):
session.clear()
session['csrf_token'] = '123456'
response = client.post(
url_for('simplelogin.login'),
data={
'username': 'admin',
'password': 'secret',
'csrf_token': '123456'
}
)
assert response.status_code == 200
assert 'csrf_token The CSRF token is missing' not in str(response.data)
# token is still invalid :(
# def test_is_logged_in(client):
# session.clear()
# session['csrf_token'] = '123456'
# response = client.post(
# url_for('simplelogin.login'),
# data={
# 'username': 'admin',
# 'password': 'secret',
# 'csrf_token': '123456'
# }
# )
# assert response.status_code == 200
# print(response.data)
# # assert is_logged_in() is True
示例8: logout
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def logout():
"""Clear the session."""
session.clear()
示例9: get
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def get(self):
username = session.get("username")
session.clear()
logout_user()
user = User.query.filter_by(username=username).first()
user.is_login = False
db.session.add(user)
db.session.commit()
return redirect(url_for('home.login', next=request.url))
示例10: __check_auth
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def __check_auth(self, view):
headers = {x[0]: x[1] for x in request.headers}
if 'Authorization' in headers:
try:
token = jwt.decode(
headers['Authorization'],
get_jwt_key_data()
)
if token['auth_system'] != current_app.active_auth_system.name:
self.log.error('Token is from another auth_system ({}) than the current one ({})'.format(
token['auth_system'],
current_app.active_auth_system.name
))
return view.make_unauth_response()
if has_access(session['user'], self.role):
return
self.log.error('User {} attempted to access page {} without permissions'.format(
session['user'].username,
request.path
))
return view.make_unauth_response()
except (jwt.DecodeError, jwt.ExpiredSignatureError) as ex:
session.clear()
view.log.info('Failed to decode signature or it had expired: {0}'.format(ex))
return view.make_unauth_response()
session.clear()
view.log.info('Failed to detect Authorization header')
return view.make_unauth_response()
示例11: get
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def get(self):
def dscb():
session.clear()
url = self.auth.process_slo(delete_session_cb=dscb)
errors = self.auth.get_errors()
if len(errors) == 0:
if url:
return self.auth.redirect_to(url)
return redirect('/logout')
示例12: logout
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def logout():
session.clear()
return redirect(url_for('frontend.home'))
# Product page
示例13: set
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def set():
session.clear()
session['works'] = True
return redirect(url_for('get'))
示例14: auth_return
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def auth_return():
auth = mendeley.start_authorization_code_flow(state=session['state'])
mendeley_session = auth.authenticate(request.url)
session.clear()
session['token'] = mendeley_session.token
return redirect('/listDocuments')
示例15: remove_login_cookie
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def remove_login_cookie():
session.clear()