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


Python session.clear方法代码示例

本文整理汇总了Python中flask.session.clear方法的典型用法代码示例。如果您正苦于以下问题:Python session.clear方法的具体用法?Python session.clear怎么用?Python session.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.session的用法示例。


在下文中一共展示了session.clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_session

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [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

示例2: login_post

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [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

示例3: home

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def home():
    # session.clear()
    if current_user.is_authenticated:
        # order = order
        session['order'] = OrderClient.get_order_from_session()

    try:
        products = ProductClient.get_products()
    except requests.exceptions.ConnectionError:
        products = {
            'results': []
        }

    return render_template('home/index.html', products=products)


# Login 
开发者ID:PacktPublishing,项目名称:Hands-on-Microservices-with-Python,代码行数:19,代码来源:routes.py

示例4: logout

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def logout():

    # The logout payload is an empty string but it is still needed
    payload = '""'
    tssa = functions.generateTssa(functions.BASE_URL + "account/logout", "POST", payload, session['accessToken'])

    headers = {'User-Agent':'Apache-HttpClient/UNAVAILABLE (java 1.4)',
               'Authorization':'%s' % tssa,
               'X-OsVersion':functions.OS_VERSION,
               'X-OsName':'Android',
               'X-DeviceID':session['DEVICE_ID'],
               'X-VmobID':functions.des_encrypt_string(session['DEVICE_ID']),
               'X-AppVersion':functions.APP_VERSION,
               'X-DeviceSecret':session['deviceSecret'],
               'Content-Type':'application/json; charset=utf-8'}

    response = requests.post(functions.BASE_URL + "account/logout", data=payload, headers=headers)

    # Clear all of the previously set session variables and then redirect to the index page
    session.clear()

    return redirect(url_for('index'))

# The confirmation page for a manual lock in 
开发者ID:freyta,项目名称:7Eleven-Python,代码行数:26,代码来源:app.py

示例5: test_extract_namespace_repo_from_session_present

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def test_extract_namespace_repo_from_session_present(app):
    encountered = []

    def somefunc(namespace, repository):
        encountered.append(namespace)
        encountered.append(repository)

    # Add the namespace and repository to the session.
    session.clear()
    session["namespace"] = "foo"
    session["repository"] = "bar"

    # Call the decorated method.
    extract_namespace_repo_from_session(somefunc)()

    assert encountered[0] == "foo"
    assert encountered[1] == "bar" 
开发者ID:quay,项目名称:quay,代码行数:19,代码来源:test_decorators.py

示例6: user_session

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def user_session(func):
    @wraps(func)
    def wrapper(**kwargs):
        from app.models import Utils
        if Utils.getParam(request.args, 'session', default=None):
            user_data = session.get('_user', None)
            if user_data and user_data['is_admin']:
                session.clear()

        user_data = session.get('_user', None)
        kwargs['props'] = {'user': user_data,
                            'cdn': webapp.config['S3_HOST']+'website/',
                            'host': webapp.config['HOST']+'/' 
                          }
        return func(**kwargs)
    return wrapper 
开发者ID:anantzoid,项目名称:Ostrich,代码行数:18,代码来源:decorators.py

示例7: test_post_with_token

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def test_post_with_token(client):
    session.clear()
    session['csrf_token'] = '123456'
    response = client.post(
        url_for('simplelogin.login'),
        data={
            'username': 'admin',
            'password': 'secret',
            'csrf_token': '123456'
        }
    )
    assert response.status_code == 200
    assert 'csrf_token The CSRF token is missing' not in str(response.data)
    # token is still invalid :(


# def test_is_logged_in(client):
#     session.clear()
#     session['csrf_token'] = '123456'
#     response = client.post(
#         url_for('simplelogin.login'),
#         data={
#             'username': 'admin',
#             'password': 'secret',
#             'csrf_token': '123456'
#         }
#     )
#     assert response.status_code == 200
#     print(response.data)
#     # assert is_logged_in() is True 
开发者ID:flask-extensions,项目名称:flask_simplelogin,代码行数:32,代码来源:test_app.py

示例8: logout

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def logout():
    """Clear the session."""
    session.clear() 
开发者ID:picoCTF,项目名称:picoCTF,代码行数:5,代码来源:user.py

示例9: get

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def get(self):
        username = session.get("username")
        session.clear()
        logout_user()
        user = User.query.filter_by(username=username).first()
        user.is_login = False
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('home.login', next=request.url)) 
开发者ID:liwanlei,项目名称:FXTest,代码行数:11,代码来源:views.py

示例10: __check_auth

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def __check_auth(self, view):
        headers = {x[0]: x[1] for x in request.headers}
        if 'Authorization' in headers:
            try:
                token = jwt.decode(
                    headers['Authorization'],
                    get_jwt_key_data()
                )

                if token['auth_system'] != current_app.active_auth_system.name:
                    self.log.error('Token is from another auth_system ({}) than the current one ({})'.format(
                        token['auth_system'],
                        current_app.active_auth_system.name
                    ))

                    return view.make_unauth_response()

                if has_access(session['user'], self.role):
                    return

                self.log.error('User {} attempted to access page {} without permissions'.format(
                    session['user'].username,
                    request.path
                ))
                return view.make_unauth_response()

            except (jwt.DecodeError, jwt.ExpiredSignatureError) as ex:
                session.clear()
                view.log.info('Failed to decode signature or it had expired: {0}'.format(ex))
                return view.make_unauth_response()

        session.clear()
        view.log.info('Failed to detect Authorization header')
        return view.make_unauth_response() 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:36,代码来源:wrappers.py

示例11: get

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def get(self):
        def dscb():
            session.clear()

        url = self.auth.process_slo(delete_session_cb=dscb)
        errors = self.auth.get_errors()

        if len(errors) == 0:
            if url:
                return self.auth.redirect_to(url)

        return redirect('/logout') 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:14,代码来源:__init__.py

示例12: logout

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def logout():
    session.clear()
    return redirect(url_for('frontend.home'))


# Product page 
开发者ID:PacktPublishing,项目名称:Hands-on-Microservices-with-Python,代码行数:8,代码来源:routes.py

示例13: set

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def set():
    session.clear()
    session['works'] = True
    return redirect(url_for('get')) 
开发者ID:realpython,项目名称:python-scripts,代码行数:6,代码来源:23_flask_session_test.py

示例14: auth_return

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def auth_return():
    auth = mendeley.start_authorization_code_flow(state=session['state'])
    mendeley_session = auth.authenticate(request.url)

    session.clear()
    session['token'] = mendeley_session.token

    return redirect('/listDocuments') 
开发者ID:Mendeley,项目名称:mendeley-api-python-example,代码行数:10,代码来源:mendeley-example.py

示例15: remove_login_cookie

# 需要导入模块: from flask import session [as 别名]
# 或者: from flask.session import clear [as 别名]
def remove_login_cookie():
    session.clear() 
开发者ID:datacats,项目名称:ckan-multisite,代码行数:4,代码来源:pw.py


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