當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。