本文整理汇总了Python中flask.session.modified方法的典型用法代码示例。如果您正苦于以下问题:Python session.modified方法的具体用法?Python session.modified怎么用?Python session.modified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.session
的用法示例。
在下文中一共展示了session.modified方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: before_request
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def before_request():
# Check if user is anonymous
g.user = current_user
login_manager.anonymous_user = Anonymous
# Check site is in maintenance mode
maintenance = Setting().get('maintenance')
if maintenance and current_user.is_authenticated and current_user.role.name not in [
'Administrator', 'Operator'
]:
return render_template('maintenance.html')
# Manage session timeout
session.permanent = True
current_app.permanent_session_lifetime = datetime.timedelta(
minutes=int(Setting().get('session_timeout')))
session.modified = True
示例2: update_session
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def update_session(i, uid=None, encrypted=None, key_logged=None, chatstatus=None):
if 'sessions' not in session:
session['sessions'] = dict()
if i not in session['sessions'] or uid is not None:
if uid is None:
raise Exception("update_session: cannot create new session without a uid")
if encrypted is None:
encrypted = True
if key_logged is None:
key_logged = False
if chatstatus is None:
chatstatus = 'off'
session['sessions'][i] = dict(uid=uid, encrypted=encrypted, key_logged=key_logged, chatstatus=chatstatus)
else:
if uid is not None:
session['sessions'][i]['uid'] = uid
if encrypted is not None:
session['sessions'][i]['encrypted'] = encrypted
if key_logged is not None:
session['sessions'][i]['key_logged'] = key_logged
if chatstatus is not None:
session['sessions'][i]['chatstatus'] = chatstatus
session.modified = True
return session['sessions'][i]
示例3: set_locale
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def set_locale():
locale = request.json.get('locale')
if locale is not None:
session['locale'] = locale
session.modified = True
return jsonify({'locale': locale})
示例4: set_cache_headers
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def set_cache_headers(f):
"""
Returns HTTP headers suitable for caching.
"""
@wraps(f)
def wrapper(*args, **kwargs):
# Set TTL to 1 year by default
ttl = 31536000
expires = datetime.fromtimestamp(int(time()) + ttl)
expires = expires.strftime("%a, %d %b %Y %H:%M:%S GMT")
headers = {
"Cache-Control": "public, max-age={0}".format(ttl),
"Expires": expires,
"Last-Modified": "Thu, 01 Jan 1970 00:00:00 GMT",
}
if "If-Modified-Since" in request.headers:
response = make_response("Not modified", 304)
response.headers.extend(headers)
return response
kwargs["headers"] = headers
# Prevent the Cookie to be sent when the object is cacheable
session.modified = False
return f(*args, **kwargs)
return wrapper
示例5: _persist_data
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def _persist_data(**kwargs):
"""Save data in session."""
if _session_key not in session:
session[_session_key] = dict()
session[_session_key].update(**kwargs)
session.modified = True
示例6: signin
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def signin():
json = request.get_json()
if "username" not in json or "password" not in json:
raise InvalidUsage("Must supply username or password.")
user = User.query.filter(User.username == json["username"]).first()
if user is not None:
current_app.logger.debug(
"Login attempt", username=user.username, user_id=user.id
)
if user.is_correct_password(json["password"]):
two_factor = user.two_factor_auth
if two_factor is not None and two_factor.enabled:
if "two_factor_code" not in json or json["two_factor_code"] == "":
raise InvalidUsage(
"Must supply a two-factor authentication code.",
payload={"need_two_factor": True},
)
try:
two_factor.validate(json["two_factor_code"])
except (Unauthorized, binascii.Error):
two_factor.validate_backup_code(json["two_factor_code"])
login_user(user, remember=False)
identity_changed.send(
current_app._get_current_object(), identity=Identity(user.id)
)
session.modified = True
return jsonify(
{
"logged_in": True,
"is_admin": user.is_admin,
"require_two_factor_setup": current_user.two_factor_setup_required,
}
)
current_app.logger.debug("Failed login attempt", username=json["username"])
raise Unauthorized("Incorrect username or password.")
示例7: signout
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def signout():
logout_user()
for key in ("identity.name", "identity.auth_type"):
session.pop(key, None)
session.modified = True
# Tell Flask-Principal the user is anonymous
identity_changed.send(
current_app._get_current_object(), identity=AnonymousIdentity()
)
return jsonify({"logged_in": False})
示例8: before_request
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def before_request():
# Manage session timeout
session.permanent = True
current_app.permanent_session_lifetime = datetime.timedelta(
minutes=int(Setting().get('session_timeout')))
session.modified = True
示例9: configure_app
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def configure_app(app, config_object):
"""General application configuration:
- register the app's config
- register Jinja extensions
- register functions to run on before/after request
"""
# automatically configure a migrations folder for each bundle
config_object.ALEMBIC['version_locations'] = [
(bundle._name, os.path.join(PROJECT_ROOT,
bundle.module_name.replace('.', os.sep),
'migrations'))
for bundle in app.bundles if bundle.has_models
]
app.config.from_object(config_object)
app.jinja_env.add_extension('jinja2_time.TimeExtension')
@app.before_request
def enable_session_timeout():
session.permanent = True # set session to use PERMANENT_SESSION_LIFETIME
session.modified = True # reset the session timer on every request
@app.after_request
def set_csrf_cookie(response):
if response:
response.set_cookie('csrf_token', generate_csrf())
return response
示例10: _add_to_compare_basket
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def _add_to_compare_basket(self, uid):
compare_uid_list = get_comparison_uid_list_from_session()
compare_uid_list.append(uid)
session.modified = True
return redirect(url_for('analysis/<uid>', uid=uid))
示例11: _remove_from_compare_basket
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def _remove_from_compare_basket(self, analysis_uid, compare_uid):
compare_uid_list = get_comparison_uid_list_from_session()
if compare_uid in compare_uid_list:
session['uids_for_comparison'].remove(compare_uid)
session.modified = True
return redirect(url_for('analysis/<uid>', uid=analysis_uid))
示例12: _remove_all_from_compare_basket
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def _remove_all_from_compare_basket(self, analysis_uid):
compare_uid_list = get_comparison_uid_list_from_session()
compare_uid_list.clear()
session.modified = True
return redirect(url_for('analysis/<uid>', uid=analysis_uid))
示例13: test_remove_from_compare_basket
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def test_remove_from_compare_basket(self):
with self.frontend.app.test_request_context():
session['uids_for_comparison'] = [TEST_FW.uid, TEST_FW_2.uid]
session.modified = True
assert 'uids_for_comparison' in session
assert TEST_FW.uid in session['uids_for_comparison']
assert TEST_FW_2.uid in session['uids_for_comparison']
CompareRoutes._remove_from_compare_basket(self.frontend, 'some_uid', TEST_FW.uid)
assert TEST_FW.uid not in session['uids_for_comparison']
assert TEST_FW_2.uid in session['uids_for_comparison']
示例14: test_remove_all_from_compare_basket
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def test_remove_all_from_compare_basket(self):
with self.frontend.app.test_request_context():
session['uids_for_comparison'] = [TEST_FW.uid, TEST_FW_2.uid]
session.modified = True
assert 'uids_for_comparison' in session
assert TEST_FW.uid in session['uids_for_comparison']
assert TEST_FW_2.uid in session['uids_for_comparison']
CompareRoutes._remove_all_from_compare_basket(self.frontend, 'some_uid')
assert TEST_FW.uid not in session['uids_for_comparison']
assert TEST_FW_2.uid not in session['uids_for_comparison']
示例15: fetch
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import modified [as 别名]
def fetch():
guild_id = request.args.get("guild_id")
channel_id = request.args.get('channel_id')
after_snowflake = request.args.get('after', 0, type=int)
if user_unauthenticated():
key = session['user_keys'][guild_id]
else:
key = None
status = update_user_status(guild_id, session['username'], key)
messages = {}
if status['banned'] or status['revoked']:
status_code = 403
if user_unauthenticated():
session['user_keys'].pop(guild_id, None)
session.modified = True
else:
chan = filter_guild_channel(guild_id, channel_id)
if not chan:
abort(404)
if not chan.get("read") or chan["channel"]["type"] != "text":
status_code = 401
else:
messages = redisqueue.get_channel_messages(guild_id, channel_id, after_snowflake)
status_code = 200
response = jsonify(messages=messages, status=status)
response.status_code = status_code
return response