当前位置: 首页>>代码示例>>Python>>正文


Python session.permanent方法代码示例

本文整理汇总了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 
开发者ID:ngoduykhanh,项目名称:PowerDNS-Admin,代码行数:19,代码来源:dashboard.py

示例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 
开发者ID:tomimick,项目名称:restpie3,代码行数:22,代码来源:account.py

示例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") 
开发者ID:jpylypiw,项目名称:easywall,代码行数:21,代码来源:login.py

示例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)) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:30,代码来源:oauth.py

示例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) 
开发者ID:quay,项目名称:quay,代码行数:30,代码来源:common.py

示例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 
开发者ID:Akagi201,项目名称:learning-python,代码行数:6,代码来源:account.py

示例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')) 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:9,代码来源:auth.py

示例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') 
开发者ID:helix-iot,项目名称:helix-sandbox,代码行数:16,代码来源:views.py

示例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) 
开发者ID:apache,项目名称:airflow,代码行数:14,代码来源:init_session.py

示例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) 
开发者ID:apache,项目名称:airflow,代码行数:9,代码来源:init_session.py

示例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 
开发者ID:contentful,项目名称:the-example-app.py,代码行数:7,代码来源:app.py

示例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) 
开发者ID:kkamkou,项目名称:gitmostwanted.com,代码行数:19,代码来源:user_oauth.py

示例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) 
开发者ID:picoCTF,项目名称:picoCTF,代码行数:25,代码来源:user.py

示例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 
开发者ID:svviz,项目名称:svviz,代码行数:19,代码来源:web.py

示例15: login

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import permanent [as 别名]
def login(self, user):
        session.permanent = True
        session['auth'] = user.uid 
开发者ID:whiteclover,项目名称:white,代码行数:5,代码来源:user.py


注:本文中的flask.session.permanent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。