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