本文整理汇总了Python中flask.session.pop方法的典型用法代码示例。如果您正苦于以下问题:Python session.pop方法的具体用法?Python session.pop怎么用?Python session.pop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.session
的用法示例。
在下文中一共展示了session.pop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cancel_github_authorization
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def cancel_github_authorization(dev_key):
print('cancel github authorization')
developer = Developer.query.filter_by(dev_key=dev_key).first()
if developer is None:
abort(400)
authorization = Authorization.query.filter_by(developer=developer, type='github').first()
if authorization:
try:
db.session.delete(authorization)
db.session.commit()
except:
db.session.rollback()
abort(500)
session.pop('user', None)
session.pop('github_token', None)
return jsonify({}), 200
示例2: google_login
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def google_login():
# to avoid flask-login displaying the login error message
session.pop("_flashes", None)
next_url = request.args.get("next")
# Google does not allow to append param to redirect_url
# we need to pass the next url by session
if next_url:
session["google_next_url"] = next_url
google = OAuth2Session(GOOGLE_CLIENT_ID, scope=_scope, redirect_uri=_redirect_uri)
authorization_url, state = google.authorization_url(_authorization_base_url)
# State is used to prevent CSRF, keep this for later.
session["oauth_state"] = state
return redirect(authorization_url)
示例3: facebook_login
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def facebook_login():
# to avoid flask-login displaying the login error message
session.pop("_flashes", None)
next_url = request.args.get("next")
# Facebook does not allow to append param to redirect_uri
# we need to pass the next url by session
if next_url:
session["facebook_next_url"] = next_url
facebook = OAuth2Session(
FACEBOOK_CLIENT_ID, scope=_scope, redirect_uri=_redirect_uri
)
facebook = facebook_compliance_fix(facebook)
authorization_url, state = facebook.authorization_url(_authorization_base_url)
# State is used to prevent CSRF, keep this for later.
session["oauth_state"] = state
return redirect(authorization_url)
示例4: consent
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def consent():
# redirect to next url when current user has already consented
if current_user.has_consented:
return redirect(session.pop("next_url", default_url()))
form = ConsentForm()
if form.validate_on_submit():
current_user.consented_at = datetime.utcnow()
current_user.profile_consent = True
current_user.org_consent = True
current_user.cookies_consent = True
current_user.age_consent = True
current_user.save()
next_url = session.pop("next_url", default_url())
return redirect(next_url)
return {"form": form}
示例5: do_create
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def do_create():
session.pop('username', None)
if request.method == 'POST':
username = request.form.get('username')
password = request.form.get('password')
email = request.form.get('password')
session['username'] = libuser.login(username, password)
if session['username']:
return redirect('/')
return render_template('user.create.html')
示例6: do_create
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def do_create():
session.pop('username', None)
if request.method == 'POST':
username = request.form.get('username')
password = request.form.get('password')
#email = request.form.get('password')
if not username or not password:
flash("Please, complete username and password")
return render_template('user.create.html')
libuser.create(username, password)
flash("User created. Please login.")
return redirect('/user/login')
#session['username'] = libuser.login(username, password)
#if session['username']:
# return redirect('/')
return render_template('user.create.html')
示例7: authorize_view
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def authorize_view(self):
"""Flask view that starts the authorization flow.
Starts flow by redirecting the user to the OAuth2 provider.
"""
args = request.args.to_dict()
# Scopes will be passed as mutliple args, and to_dict() will only
# return one. So, we use getlist() to get all of the scopes.
args['scopes'] = request.args.getlist('scopes')
return_url = args.pop('return_url', None)
if return_url is None:
return_url = request.referrer or '/'
flow = self._make_flow(return_url=return_url, **args)
auth_url = flow.step1_get_authorize_url()
return redirect(auth_url)
示例8: dropsession
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def dropsession():
try:
if session.get('user'):
username = session.get('user')
session.pop('user', None)
session.pop('is_admin', False)
Message = f"Session for user: {username} terminated."
app.logger.warning(Message)
Create_Event(Message)
return render_template('index.html', loggedout=True)
except Exception as e:
app.logger.error(e)
return redirect(url_for('index'))
示例9: reset_settings
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def reset_settings():
session.pop('space_id', None)
session.pop('delivery_token', None)
session.pop('preview_token', None)
session.pop('editorial_features', None)
space = contentful().space(api_id())
return render_with_globals(
'settings',
title=translate('settingsLabel', locale().code),
errors={},
has_errors=False,
success=False,
space=space,
host=request.url_root
)
示例10: with_logger
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def with_logger(kwarg='logger', stream_dest_kwarg='stream', replace=True):
''' Decorator that creates a new :class:`logging.Logger` object
additionally to or in-place for the *stream* parameter passed to
the wrapped function. This is usually used in combination with
the :func:`with_io_response` decorator.
Note that exceptions with this decorator will be logged and the
returned status code will be 500 Internal Server Error. '''
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
if replace:
stream = kwargs.pop(stream_dest_kwarg)
else:
stream = kwargs[stream_dest_kwarg]
kwargs[kwarg] = logger = create_logger(stream)
try:
return func(*args, **kwargs)
except BaseException as exc:
logger.exception(exc)
return 500
return wrapper
return decorator
示例11: logout
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def logout():
session.pop('logged_in', None)
session.pop('active_user', None)
flask.flash('You were logged out!')
return redirect(url_for("index"))
示例12: logout_oauth_user
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def logout_oauth_user():
for oauth_key in oauth_check.keys():
if str(oauth_key) + '_oauth_user_id' in session:
session.pop(str(oauth_key) + '_oauth_user_id')
示例13: logout
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def logout():
session.pop('qq_token', None)
return redirect(url_for('main.index'))
示例14: revoke
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def revoke(self):
"""This method clears current discord token, state and all session data from flask
`session <http://flask.pocoo.org/docs/1.0/api/#flask.session>`_. Which means user will have
to go through discord authorization token grant flow again. Also tries to remove the user from internal
cache if they exist.
"""
self.users_cache.pop(self.user_id, None)
for session_key in self.SESSION_KEYS:
try:
session.pop(session_key)
except KeyError:
pass
示例15: preprocess_request
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import pop [as 别名]
def preprocess_request():
if request.endpoint in {'redirect_view', 'proxy_view', 'pending_view', 'leaderboard_view', 'user_leaderboard_view'}:
if request.view_args.get('object_key'):
session['object_key'] = request.view_args.get('object_key')
if session.get('verified') != True:
session['next'] = request.url
return redirect(url_for('login_view'))
if session.get('next'):
return redirect(session.pop('next'))
if not s3:
flash('Your S3 keys are invalid!', 'danger')
return 'Your S3 keys are invalid!'