本文整理汇总了Python中flask.session.permanent方法的典型用法代码示例。如果您正苦于以下问题:Python session.permanent方法的具体用法?Python session.permanent怎么用?Python session.permanent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.session
的用法示例。
在下文中一共展示了session.permanent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: before_request
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [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: build_session
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [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
示例3: login_post
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [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")
示例4: setup_session
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def setup_session(url: str) -> None:
discord = make_session(state=session.get('oauth2_state'))
token = discord.fetch_token(
TOKEN_URL,
client_secret=OAUTH2_CLIENT_SECRET,
authorization_response=url)
session.permanent = True
session['oauth2_token'] = token
discord = make_session(token=session.get('oauth2_token'))
user = discord.get(API_BASE_URL + '/users/@me').json()
session['id'] = user['id']
session['discord_id'] = user['id']
session['discord_locale'] = user['locale']
guilds = discord.get(API_BASE_URL + '/users/@me/guilds').json()
wrong_guilds = False # protect against an unexpected response from discord
session['in_guild'] = False
session['admin'] = False
session['demimod'] = False
for guild in guilds:
if isinstance(guild, dict) and 'id' in guild:
if guild['id'] == configuration.get('guild_id'):
session['admin'] = (guild['permissions'] & 0x10000000) != 0 # Check for the MANAGE_ROLES permissions on Discord as a proxy for "is admin".
session['demimod'] = (guild['permissions'] & 0x20000) != 0 # Check for the "Mention @everyone" permissions on Discord as a proxy for "is demimod".
session['in_guild'] = True
else:
wrong_guilds = True
if wrong_guilds:
logger.warning('auth.py: unexpected discord response. Guilds: {g}'.format(g=guilds))
示例5: common_login
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def common_login(user_uuid, permanent_session=True):
"""
Performs login of the given user, with optional non-permanence on the session.
Returns a tuple with (success, headers to set on success).
"""
user = model.get_user(user_uuid)
if user is None:
return (False, None)
if login_user(LoginWrappedDBUser(user_uuid)):
logger.debug("Successfully signed in as user %s with uuid %s", user.username, user_uuid)
new_identity = QuayDeferredPermissionUser.for_id(user_uuid)
identity_changed.send(app, identity=new_identity)
session["login_time"] = datetime.datetime.now()
if permanent_session and features.PERMANENT_SESSIONS:
session_timeout_str = app.config.get("SESSION_TIMEOUT", "31d")
session.permanent = True
session.permanent_session_lifetime = convert_to_timedelta(session_timeout_str)
# Force a new CSRF token.
headers = {}
headers[QUAY_CSRF_UPDATED_HEADER_NAME] = generate_csrf_token(force=True)
return (True, headers)
logger.debug("User could not be logged in, inactive?")
return (False, None)
示例6: signin_user
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def signin_user(user, permenent=True):
"""Sign in user."""
session.permanent = permenent
session['user_id'] = user.id
示例7: login
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def login(p: person.Person) -> None:
session['logged_person_id'] = p.id
session['person_id'] = p.id
session['mtgo_username'] = p.name
session.permanent = True
if p.locale != session.get('discord_locale'):
person.set_locale(p.id, session.get('discord_locale'))
示例8: login
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def login():
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(username=form.username.data).first()
if user is not None and user.verify_password(form.password.data):
login_user(user,remember=True)
session.permanent = True
if user.is_admin:
return redirect(url_for('home.admin_dashboard'))
else:
return redirect(url_for('home.dashboard'))
else:
flash('Invalid username or password.')
return render_template('auth/login.html', form=form, title='Login')
示例9: init_logout_timeout
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def init_logout_timeout(app):
"""Add logout user after timeout"""
def before_request():
_force_log_out_after = conf.getint('webserver', 'FORCE_LOG_OUT_AFTER', fallback=0)
if _force_log_out_after > 0:
flask.session.permanent = True
app.permanent_session_lifetime = datetime.timedelta(minutes=_force_log_out_after)
flask.session.modified = True
flask.g.user = flask_login.current_user
app.before_request(before_request)
示例10: init_permanent_session
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def init_permanent_session(app):
"""Make session permanent to allows us to store data"""
def make_session_permanent():
flask_session.permanent = True
app.before_request(make_session_permanent)
示例11: set_session_permanency
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def set_session_permanency():
session.permanent = True
# Register Markdown engine
示例12: authorized
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def authorized():
next_url = url_next() or url_for('/')
resp = oauth.github.authorize_access_token()
if resp is None or 'access_token' not in resp:
return redirect(next_url)
session.permanent = True
session['oauth_access_token'] = (resp['access_token'], resp['scope'].split(','))
result = oauth.github.get('user')
if result:
json = result.json()
user = user_get_or_create(json['id'], json['email'], json['login'])
session['user_id'] = user.id
return redirect(next_url)
示例13: login
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def login(username, password):
"""Authenticate a user."""
user = get_user(name=username, include_pw_hash=True)
if user is None:
raise PicoException("Incorrect username.", 401)
if user["disabled"]:
raise PicoException("This account has been deleted.", 403)
if not user["verified"]:
api.email.send_user_verification_email(username)
raise PicoException(
"This account has not been verified yet. An additional email has been sent to {}.".format(
user["email"]
),
403,
)
if confirm_password(password, user["password_hash"]):
session["uid"] = user["uid"]
session.permanent = True
else:
raise PicoException("Incorrect password", 401)
示例14: index
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def index():
if not "last_format" in session:
session["last_format"] = "svg"
session.permanent = True
try:
variantDescription = str(dataHub.variant).replace("::", " ").replace("-", "–")
return render_template('index.html',
samples=list(dataHub.samples.keys()),
annotations=dataHub.annotationSets,
results_table=dataHub.getCounts(),
insertSizeDistributions=[sample.name for sample in dataHub if sample.insertSizePlot],
dotplots=dataHub.dotplots,
variantDescription=variantDescription)
except Exception as e:
logging.error("ERROR:{}".format(e))
raise
示例15: login
# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def login(self, user):
session.permanent = True
session['auth'] = user.uid