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


Python request.user方法代码示例

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


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

示例1: post

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def post(self):
        '''
        新建相册
        '''
        post_data = request.data
        user = request.user
        name = post_data.pop('name', None)
        description = post_data.pop('description', None)
        if name is None:
            return HTTP.BAD_REQUEST(message='相册名称不能为空')
        album = Album(name=name, user=user)
        if description is not None:
            album.description = description
        album.save()
        serializer = AlbumSerializer(album)
        return HTTP.OK(data=serializer.data) 
开发者ID:honmaple,项目名称:maple-file,代码行数:18,代码来源:router.py

示例2: get

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def get(self):
        '''
        获取图片列表
        '''
        query_dict = request.data
        user = request.user
        page, number = self.page_info
        keys = ['name', 'description']
        order_by = gen_order_by(query_dict, keys)
        filter_dict = gen_filter_dict(query_dict, keys, user=user)
        album = query_dict.pop('album', None)
        if album is not None:
            filter_dict.update(album__id=album)
        images = Image.query.filter_by(
            **filter_dict).order_by(*order_by).paginate(page, number)
        serializer = ImageSerializer(images.items, True)
        pageinfo = PageInfo(images)
        return HTTP.OK(data=serializer.data, pageinfo=pageinfo) 
开发者ID:honmaple,项目名称:maple-file,代码行数:20,代码来源:router.py

示例3: put

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def put(self, pk):
        '''
        修改图片信息
        '''
        post_data = request.data
        user = request.user
        name = post_data.pop('name', None)
        description = post_data.pop('description', None)
        image = Image.query.filter_by(id=pk, user=user).get_or_404('图片不存在')
        if name is not None:
            image.name = name
            image.url = os.path.join(image.path, name)
        if description is not None:
            image.description = description
        image.save()
        serializer = ImageSerializer(image)
        return HTTP.OK(data=serializer.data) 
开发者ID:honmaple,项目名称:maple-file,代码行数:19,代码来源:router.py

示例4: delete

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def delete(self, pk):
        '''
        删除图片
        '''
        user = request.user
        image = Image.query.filter_by(id=pk, user=user).get_or_404('图片不存在')
        serializer = ImageSerializer(image)
        img_path = os.path.join(current_app.config['UPLOAD_FOLDER_ROOT'],
                                image.url)
        # 删除原图
        if os.path.exists(img_path):
            os.remove(img_path)
        # 删除缩略图
        thumb_path = os.path.join(current_app.config['UPLOAD_FOLDER_ROOT'],
                                  image.url.replace('photo', 'thumb'))
        if os.path.exists(thumb_path):
            os.remove(thumb_path)
        image.delete()
        return HTTP.OK(data=serializer.data) 
开发者ID:honmaple,项目名称:maple-file,代码行数:21,代码来源:router.py

示例5: get

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def get(self, bucket):
        data = request.data
        user = request.user
        page, number = self.pageinfo

        bucket = user.buckets.filter_by(
            name=bucket).get_or_404("bucket not found")
        path = request.data.get("path", "/")

        params = filter_maybe(data, {
            "name": "name__contains",
        })
        rootpath = bucket.get_root_path(path)
        paths = rootpath.child_paths.filter_by(**params).paginate(page, number)
        serializer = FilePathSerializer(paths)
        return HTTP.OK(data=serializer.data) 
开发者ID:honmaple,项目名称:maple-blog,代码行数:18,代码来源:filepath.py

示例6: handle_cors

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def handle_cors(response):
    if not response:
        response = flask.Response()
    cors_allowed_headers = [
        'accept',
        'accept-encoding',
        'authorization',
        'content-type',
        'dnt',
        'origin',
        'user-agent',
        'x-csrftoken',
        'x-requested-with']
    response.headers['Access-Control-Allow-Origin'] = "http://localhost:8080"
    response.headers['Access-Control-Allow-Methods'] = ",".join(["GET","POST","OPTIONS"])
    response.headers['Access-Control-Allow-Headers'] = ",".join(cors_allowed_headers)
    return response 
开发者ID:hashedin,项目名称:squealy,代码行数:19,代码来源:views.py

示例7: remove_keypair

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def remove_keypair(path):
  if not request.user.can_manage:
    return abort(403)

  repo = get_target_for(path)
  if not isinstance(repo, Repository):
    return abort(404)

  session['errors'] = []

  private_key_path = utils.get_repo_private_key_path(repo)
  public_key_path = utils.get_repo_public_key_path(repo)

  try:
    file_utils.delete(private_key_path)
    file_utils.delete(public_key_path)
    utils.flash('SSH keypair removed.')
  except BaseException as exc:
    app.logger.info(exc)
    session['errors'].append('Could not remove SSH keypair.')

  return redirect(url_for('edit_repo', repo_id = repo.id)) 
开发者ID:NiklasRosenstein,项目名称:flux-ci,代码行数:24,代码来源:views.py

示例8: view_build

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def view_build(path):
  build = get_target_for(path)
  if not isinstance(build, Build):
    return abort(404)

  restart = request.args.get('restart', '').strip().lower() == 'true'
  if restart:
    if build.status != Build.Status_Building:
      build.delete_build()
      build.status = Build.Status_Queued
      build.date_started = None
      build.date_finished = None
      models.commit()
      enqueue(build)
    return redirect(build.url())

  stop = request.args.get('stop', '').strip().lower() == 'true'
  if stop:
    if build.status == Build.Status_Queued:
      build.status = Build.Status_Stopped
    elif build.status == Build.Status_Building:
      terminate_build(build)
    return redirect(build.url())

  return render_template('view_build.html', user=request.user, build=build) 
开发者ID:NiklasRosenstein,项目名称:flux-ci,代码行数:27,代码来源:views.py

示例9: build

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def build():
  repo_id = request.args.get('repo_id', '')
  ref_name = request.args.get('ref', '')
  if not repo_id or not ref_name:
    return abort(400)
  if not request.user.can_manage:
    return abort(403)

  commit = '0' * 32
  repo = Repository.get(id=repo_id)
  build = Build(
    repo=repo,
    commit_sha=commit,
    num=repo.build_count,
    ref=ref_name,
    status=Build.Status_Queued,
    date_queued=datetime.now(),
    date_started=None,
    date_finished=None)
  repo.build_count += 1

  models.commit()
  enqueue(build)
  return redirect(repo.url()) 
开发者ID:NiklasRosenstein,项目名称:flux-ci,代码行数:26,代码来源:views.py

示例10: overrides_delete

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def overrides_delete(path):
  if not request.user.can_manage:
    return abort(403)

  separator = "/"

  repo_path, overrides_path = file_utils.split_url_path(path)
  repo = get_target_for(repo_path)
  if not isinstance(repo, Repository):
    return abort(404)

  return_path_parts = path.split(separator)
  return_path = separator.join(return_path_parts[:-1])
  cwd = os.path.join(utils.get_override_path(repo), overrides_path.replace('/', os.sep))

  session['errors'] = []
  try:
    file_utils.delete(cwd)
    utils.flash('Object was deleted.')
  except BaseException as exc:
    app.logger.info(exc)
    session['errors'].append('Could not delete \'' + return_path_parts[-1] + '\'.')

  return redirect(url_for('overrides_list', path = return_path)) 
开发者ID:NiklasRosenstein,项目名称:flux-ci,代码行数:26,代码来源:views.py

示例11: requires_auth

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def requires_auth(func):
  ''' Decorator for view functions that require basic authentication. '''

  @functools.wraps(func)
  def wrapper(*args, **kwargs):
    ip = request.remote_addr
    token_string = session.get('flux_login_token')
    token = models.LoginToken.select(lambda t: t.token == token_string).first()
    if not token or token.ip != ip or token.expired():
      if token and token.expired():
        flash("Your login session has expired.")
        token.delete()
      return redirect(url_for('login'))

    request.login_token = token
    request.user = token.user
    return func(*args, **kwargs)

  return wrapper 
开发者ID:NiklasRosenstein,项目名称:flux-ci,代码行数:21,代码来源:utils.py

示例12: test_token_populate_default_account_if_request_account_is_empty

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def test_token_populate_default_account_if_request_account_is_empty(self):
        with application.test_client() as client:
            r = client.get(
                "/v2/apps",
                headers=self.auth_header(USER_WITH_MULTIPLE_ACCOUNTS_AUTH_KEY),
            )
            self.assertEqual(200, r.status_code)
            self.assertEqual(
                USER_WITH_MULTIPLE_ACCOUNTS_EMAIL, request.user.tx_email
            )
            self.assertEqual(
                self.account_dev.id, request.user.current_account.id
            )
            self.assertEqual(
                self.account_dev.namespace,
                request.user.current_account.namespace,
            )
            self.assertEqual(
                self.account_dev.owner, request.user.current_account.owner
            ) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:22,代码来源:test_auth.py

示例13: test_jwt_populate_default_account_if_request_account_is_empty

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def test_jwt_populate_default_account_if_request_account_is_empty(self):
        """
        Como quem gera o token JWT é o server e ele *sempre* coloca account_id (Um user sem nennhuma account associada não se loga), esse request nunca vai acontecer.
        Não acontece pois é impossivel gerar um JWT válido sem ter a SECRET_KEY que só o server tem.
        """
        test_client = application.test_client()
        with application.app_context():
            jwt_token = jwt_auth.jwt_encode_callback(
                {"email": "user@host.com.br"}
            )
            auth_header = {
                "Authorization": "JWT {}".format(jwt_token.decode("utf-8"))
            }
            r = test_client.get("/v2/apps", headers=auth_header)
            self.assertEqual(200, r.status_code)
            self.assertEqual(3, r.user.current_account) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:18,代码来源:test_auth.py

示例14: test_jwt_return_401_if_user_is_not_linked_to_account

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def test_jwt_return_401_if_user_is_not_linked_to_account(self):
        """
        If user tries to access account without being associated to this account
        """
        test_client = application.test_client()
        with application.app_context():
            jwt_token = jwt_encode(self.user, self.account_with_no_user)
            auth_header = {
                "Authorization": "JWT {}".format(jwt_token.decode("utf-8"))
            }
            r = test_client.get("/v2/apps", headers=auth_header)
            self.assertEqual(401, r.status_code)
            self.assertEqual(
                "Permission Denied to access this account",
                json.loads(r.data)["msg"],
            ) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:18,代码来源:test_auth.py

示例15: test_jwt_auth_with_token_from_session_if_headers_not_present

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import user [as 别名]
def test_jwt_auth_with_token_from_session_if_headers_not_present(self):
        """
        Se não encontrarmos o token JWT no header, olhamos na flask session procurando por ele.
        """
        test_client = application.test_client()

        with application.app_context(), patch.object(
            routes,
            "check_authentication_successful",
            return_value={"email": self.user.email},
        ):
            jwt_token = jwt_encode(self.user, self.account_dev)

            with test_client.session_transaction() as flask_session:
                flask_session["jwt"] = jwt_token

            response = test_client.get("/v2/apps")
            self.assertEqual(200, response.status_code) 
开发者ID:b2wdigital,项目名称:asgard-api,代码行数:20,代码来源:test_auth.py


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