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


Python flask.session方法代码示例

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


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

示例1: _authenticate

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def _authenticate(self, client, interactive=True):
        if not client.is_registered():
            self._register_client(client)

        flask.session['destination'] = flask.request.url
        flask.session['state'] = rndstr()
        flask.session['nonce'] = rndstr()

        # Use silent authentication for session refresh
        # This will not show login prompt to the user
        extra_auth_params = {}
        if not interactive:
            extra_auth_params['prompt'] = 'none'

        login_url = client.authentication_request(flask.session['state'],
                                                  flask.session['nonce'],
                                                  extra_auth_params)

        auth_params = dict(parse_qsl(login_url.split('?')[1]))
        flask.session['fragment_encoded_response'] = AuthResponseHandler.expect_fragment_encoded_response(auth_params)
        return redirect(login_url) 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:23,代码来源:flask_pyoidc.py

示例2: _logout

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def _logout(self):
        logger.debug('user logout')
        try:
            session = UserSession(flask.session)
        except UninitialisedSession as e:
            logger.info('user was already logged out, doing nothing')
            return None

        id_token_jwt = session.id_token_jwt
        client = self.clients[session.current_provider]
        session.clear()

        if client.provider_end_session_endpoint:
            flask.session['end_session_state'] = rndstr()

            end_session_request = EndSessionRequest(id_token_hint=id_token_jwt,
                                                    post_logout_redirect_uri=self._get_post_logout_redirect_uri(client),
                                                    state=flask.session['end_session_state'])

            logger.debug('send endsession request: %s', end_session_request.to_json())

            return redirect(end_session_request.request(client.provider_end_session_endpoint), 303)
        return None 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:25,代码来源:flask_pyoidc.py

示例3: oidc_logout

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def oidc_logout(self, view_func):
        self._logout_view = view_func

        @functools.wraps(view_func)
        def wrapper(*args, **kwargs):
            if 'state' in flask.request.args:
                # returning redirect from provider
                if flask.request.args['state'] != flask.session.pop('end_session_state'):
                    logger.error("Got unexpected state '%s' after logout redirect.", flask.request.args['state'])
                return view_func(*args, **kwargs)

            redirect_to_provider = self._logout()
            if redirect_to_provider:
                return redirect_to_provider

            return view_func(*args, **kwargs)

        return wrapper 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:20,代码来源:flask_pyoidc.py

示例4: test_handle_authentication_response_POST

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def test_handle_authentication_response_POST(self):
        access_token = 'test_access_token'
        state = 'test_state'

        authn = self.init_app()
        auth_response = AuthorizationResponse(**{'state': state, 'token_type': 'Bearer', 'access_token': access_token})

        with self.app.test_request_context('/redirect_uri',
                                           method='POST',
                                           data=auth_response.to_dict(),
                                           mimetype='application/x-www-form-urlencoded'):
            UserSession(flask.session, self.PROVIDER_NAME)
            flask.session['destination'] = '/test'
            flask.session['state'] = state
            flask.session['nonce'] = 'test_nonce'
            response = authn._handle_authentication_response()
            session = UserSession(flask.session)
            assert session.access_token == access_token
            assert response == '/test' 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:21,代码来源:test_flask_pyoidc.py

示例5: test_token_error_response_calls_to_error_view_if_set

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def test_token_error_response_calls_to_error_view_if_set(self):
        token_endpoint = self.PROVIDER_BASEURL + '/token'
        error_response = {'error': 'invalid_request', 'error_description': 'test error'}
        responses.add(responses.POST, token_endpoint, json=error_response)

        authn = self.init_app(provider_metadata_extras={'token_endpoint': token_endpoint})
        error_view_mock = self.get_view_mock()
        authn.error_view(error_view_mock)
        state = 'test_tate'
        with self.app.test_request_context('/redirect_uri?code=foo&state={}'.format(state)):
            UserSession(flask.session, self.PROVIDER_NAME)
            flask.session['state'] = state
            flask.session['nonce'] = 'test_nonce'
            result = authn._handle_authentication_response()

        self.assert_view_mock(error_view_mock, result)
        error_view_mock.assert_called_with(**error_response) 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:19,代码来源:test_flask_pyoidc.py

示例6: get_random_edit

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def get_random_edit():
    # Check first that we are logged in
    access_token =flask.session.get('access_token', None)
    if not access_token:
        return flask.redirect(flask.url_for('login', next_url=flask.url_for('get_random_edit')))

    # Then, redirect to a random cached edit
    for page_name in list_cache_contents():
        # Randomly skip or pick the current one, about 1 % chance.
        if random() > 0.01:
            continue

        cache_fname = "cache/"+to_cache_name(page_name)
        with open(cache_fname, 'r') as f:
            page_json = json.load(f)

        proposed_edits = page_json.get('proposed_edits', [])
        proposed_edits = [template_edit for template_edit in proposed_edits if (template_edit['classification'] != 'rejected')]
        if proposed_edits:
            edit_idx = randint(0, len(proposed_edits)-1)
            orig_hash = proposed_edits[edit_idx]['orig_hash']
            return flask.redirect(
                flask.url_for('review_one_edit', name=page_name, edit=orig_hash))

    return flask.redirect(flask.url_for('index')) 
开发者ID:dissemin,项目名称:oabot,代码行数:27,代码来源:app.py

示例7: login

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def login():
    """Initiate an OAuth login.

    Call the MediaWiki server to get request secrets and then redirect
the
    user to the MediaWiki server to sign the request.
    """
    consumer_token = mwoauth.ConsumerToken(
        app.config['CONSUMER_KEY'], app.config['CONSUMER_SECRET'])
    try:
        redirect, request_token = mwoauth.initiate(
            app.config['OAUTH_MWURI'], consumer_token)
    except Exception:
        app.logger.exception('mwoauth.initiate failed')
        return flask.redirect(flask.url_for('index'))
    else:
        flask.session['request_token'] = dict(zip(
            request_token._fields, request_token))
        return flask.redirect(redirect) 
开发者ID:dissemin,项目名称:oabot,代码行数:21,代码来源:app.py

示例8: enter_sudo

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def enter_sudo():
    password_check_form = LoginForm()

    if password_check_form.validate_on_submit():
        password = password_check_form.password.data

        if current_user.check_password(password):
            session["sudo_time"] = int(time())

            # User comes to sudo page from another page
            next_url = request.args.get("next")
            if next_url:
                LOG.debug("redirect user to %s", next_url)
                return redirect(next_url)
            else:
                LOG.debug("redirect user to dashboard")
                return redirect(url_for("dashboard.index"))
        else:
            flash("Incorrect password", "warning")

    return render_template(
        "dashboard/enter_sudo.html", password_check_form=password_check_form
    ) 
开发者ID:simple-login,项目名称:app,代码行数:25,代码来源:enter_sudo.py

示例9: demo

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def demo():
    """Step 1: User Authorization.
    Redirect the user/resource owner to the OAuth provider (i.e. SimpleLogin)
    using an URL with a few key OAuth parameters.
    """
    simplelogin = OAuth2Session(
        client_id, redirect_uri="http://127.0.0.1:5000/callback"
    )
    authorization_url, state = simplelogin.authorization_url(authorization_base_url)

    # State is used to prevent CSRF, keep this for later.
    session["oauth_state"] = state
    return redirect(authorization_url)


# Step 2: User authorization, this happens on the provider. 
开发者ID:simple-login,项目名称:app,代码行数:18,代码来源:oauth_tester.py

示例10: login

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def login():
    if g.user is not None:
        return redirect(url_for('index'))

    form = LoginForm(request.form)

    if request.method == 'POST' and form.validate():
        user = users.User.query.filter_by(username=form.username.data).first()
        if user is None:
            flash(u'El usuario no existe')
        elif not user.checkpassword(form.password.data):
            flash(u'Contraseña incorrecta')
            app.logger.info('[%s] login failed', user)
        else:
            flash(u'Bienvenido de nuevo, %s'%user.username)
            session['user_id'] = user.id
            g.user = user
            app.logger.info('[%s] login succeeded', user)
            return level.autosolve(app) or redirect(url_for('index'))

    return redirect(url_for('index')) 
开发者ID:marcan,项目名称:hackit,代码行数:23,代码来源:app.py

示例11: autosolve

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def autosolve(app):
    if 'autosolve' not in session:
        return None
    if g.user is None:
        return None

    last_res = None
    try:
        for name, idx, password in session['autosolve']:
            app.logger.info('[%s] autosolve %r, %r, %r', g.user, name, idx, password)
            level = routes_by_name[name].levels[idx]
            res = level.solve(password, auto=True)
            if res is not None:
                last_res = res
    except:
        app.logger.exception('[%s] autosolve failed: (%r)', g.user, session['autosolve'])

    del session['autosolve']
    return last_res 
开发者ID:marcan,项目名称:hackit,代码行数:21,代码来源:level.py

示例12: auth_logout

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def auth_logout():  # pragma: no cover
    """ Method to log out from the application. """
    return_point = flask.url_for("ui_ns.index")
    if "next" in flask.request.args:
        if pagure.utils.is_safe_url(flask.request.args["next"]):
            return_point = flask.request.args["next"]

    if not pagure.utils.authenticated():
        return flask.redirect(return_point)

    logout()
    flask.flash("You have been logged out")
    flask.session["_justloggedout"] = True
    return flask.redirect(return_point)


# pylint: disable=unused-argument 
开发者ID:Pagure,项目名称:pagure,代码行数:19,代码来源:flask_app.py

示例13: signin_user_db

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def signin_user_db(user_db):
  if not user_db:
    return flask.redirect(flask.url_for('signin'))
  flask_user_db = FlaskUser(user_db)
  auth_params = flask.session.get('auth-params', {
    'next': flask.url_for('welcome'),
    'remember': False,
  })
  flask.session.pop('auth-params', None)
  if flask_login.login_user(flask_user_db, remember=auth_params['remember']):
    user_db.put_async()
    if user_db.github:
      return flask.redirect(flask.url_for('gh_account', username=user_db.github))
    return flask.redirect(util.get_next_url(auth_params['next']))
  flask.flash('Sorry, but you could not sign in.', category='danger')
  return flask.redirect(flask.url_for('signin')) 
开发者ID:lipis,项目名称:github-stats,代码行数:18,代码来源:auth.py

示例14: modify_developer

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def modify_developer(dev_key):
    developer = Developer.query.filter_by(dev_key=dev_key).first()
    if developer is None:
        abort(404)
    if 'name' in request.json:
        developer.username = request.json['name']
    if 'desc' in request.json:
        developer.description = request.json['desc']
    if 'avatar' in request.json:
        developer.avatar = request.json['avatar']
    if 'email' in request.json:
        developer.email = request.json['email']
    db.session.add(developer)
    try:
        db.session.commit()
        return jsonify({'modified': True}), 200
    except:
        db.session.rollback()
        abort(500)


# 在dev_key 下创建一个 channel 
开发者ID:jpush,项目名称:jbox,代码行数:24,代码来源:developers.py

示例15: modificate_integration

# 需要导入模块: import flask [as 别名]
# 或者: from flask import session [as 别名]
def modificate_integration(dev_key, integration_id):
    if not request.json or not 'channel' in request.json:
        abort(400)
    developer = get_developer_with_devkey(dev_key)
    integration = Integration.query.filter_by(developer_id=developer.id, integration_id=integration_id).first()
    if integration is None:
        abort(400)
    integration.channel.channel = request.json['channel']
    if 'name' in request.json:
        integration.name = request.json['name']
    if 'description' in request.json:
        integration.description = request.json['description']
    if 'icon' in request.json:
        integration.icon = request.json['icon']
    db.session.add(integration)
    try:
        db.session.commit()
    except:
        db.session.rollback()
        abort(500)
    return jsonify({'modification': True}), 200


# 保存 github 集成,将所选的仓库与之前的仓库比较,新增则生成 webhook, 否则去掉之前的 webhook 
开发者ID:jpush,项目名称:jbox,代码行数:26,代码来源:developers.py


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