Exemple #1
0
    def delete(self, request):
        result, message = BkUser.objects.unbind_wx_user_info(request.user)

        if not result:
            return ApiV1FailJsonResponse(message)

        return ApiV1OKJsonResponse(_("解绑成功"))
Exemple #2
0
 def get(self, request):
     # 验证Token参数
     is_valid, user, message = validate_bk_token(request.GET)
     if not is_valid:
         return ApiV1FailJsonResponse(message,
                                      code=ApiErrorCodeEnum.PARAM_NOT_VALID)
     return ApiV1OKJsonResponse(_("用户验证成功"),
                                data={'username': user.username})
Exemple #3
0
    def get(self, request):
        # 验证Token参数
        is_valid, user, message = validate_bk_token(request.GET)
        if not is_valid:
            # 如果是ESB的请求,可以直接从参数中获取用户名
            is_from_esb = is_request_from_esb(request)
            username = request.GET.get('username')
            if not is_from_esb or not username:
                return ApiV1FailJsonResponse(
                    message, code=ApiErrorCodeEnum.PARAM_NOT_VALID)
        else:
            username = user.username

        # 获取用户数据
        result, data, message = BkUser.objects.get_user_info(username)
        if not result:
            return ApiV1FailJsonResponse(
                message, code=ApiErrorCodeEnum.USER_NOT_EXISTS2)

        return ApiV1OKJsonResponse(_("用户信息获取成功"), data=data)
Exemple #4
0
    def put(self, request):
        try:
            request_param = json.loads(request.body)
        except Exception:
            return ApiV1FailJsonResponse(_("请求参数格式错误,必须为json格式"),
                                         code=ApiErrorCodeEnum.PARAM_NOT_VALID)

        form = PasswordForm(request_param)

        if not form.is_valid():
            message = first_error_message(form)
            return ApiV1FailJsonResponse(message,
                                         code=ApiErrorCodeEnum.PARAM_NOT_VALID)

        result, error_code, message = BkUser.objects.modify_password_by_username(
            request.user.username, form.cleaned_data["new_password"])
        if not result:
            return ApiV1FailJsonResponse(message, code=error_code)

        return ApiV1OKJsonResponse(_("密码重置成功"))
Exemple #5
0
    def post(self, request):
        try:
            request_param = json.loads(request.body)
        except Exception:
            return ApiV1FailJsonResponse(_("请求参数格式错误,必须为json格式"),
                                         code=ApiErrorCodeEnum.PARAM_NOT_VALID)

        form = WeixinInfoForm(request_param)

        if not form.is_valid():
            message = first_error_message(form)
            return ApiV1FailJsonResponse(message,
                                         code=ApiErrorCodeEnum.PARAM_NOT_VALID)

        result, message = BkUser.objects.bind_wx_user_info(
            request.user, form.cleaned_data["wx_userid"])

        if not result:
            return ApiV1FailJsonResponse(message)

        return ApiV1OKJsonResponse(_("绑定成功"))
Exemple #6
0
    def post(self, request):
        try:
            request_param = json.loads(request.body)
        except Exception:
            return ApiV1FailJsonResponse(_("请求参数格式错误,必须为json格式"),
                                         code=ApiErrorCodeEnum.PARAM_NOT_VALID)

        form = BaseUserInfoForm(request_param)

        if not form.is_valid():
            message = first_error_message(form)
            return ApiV1FailJsonResponse(message,
                                         code=ApiErrorCodeEnum.PARAM_NOT_VALID)

        result, error_code, message = BkUser.objects.modify_user_info(
            request.user.username, form.cleaned_data["chname"],
            form.cleaned_data["phone"], form.cleaned_data["email"])
        if not result:
            return ApiV1FailJsonResponse(message, code=error_code)

        return ApiV1OKJsonResponse(_("用户信息修改成功"))
Exemple #7
0
    def post(self, request):
        try:
            post_data = json.loads(request.body)
        except Exception:
            return ApiV1FailJsonResponse(_("请求参数格式错误,必须为json格式"),
                                         code=ApiErrorCodeEnum.PARAM_NOT_VALID)

        # 非ESB的请求需要验证登录态 bk_token
        if not is_request_from_esb(request):
            # 验证Token参数
            is_valid, user, message = validate_bk_token(post_data)
            if not is_valid:
                return ApiV1FailJsonResponse(
                    message, code=ApiErrorCodeEnum.PARAM_NOT_VALID)

        username_list = post_data.get('username_list')
        if not username_list:
            return ApiV1FailJsonResponse(_("缺少参数:username_list"),
                                         code=ApiErrorCodeEnum.PARAM_NOT_VALID)

        # 获取用户信息
        data = BkUser.objects.get_batch_user_with_dict(username_list)
        return ApiV1OKJsonResponse(_("用户信息获取成功"), data=data)
Exemple #8
0
    def get(self, request):
        # 非ESB的请求需要验证登录态 bk_token
        if not is_request_from_esb(request):
            # 验证Token参数
            is_valid, user, message = validate_bk_token(request.GET)
            if not is_valid:
                return ApiV1FailJsonResponse(
                    message, code=ApiErrorCodeEnum.PARAM_NOT_VALID)

        # 获取用户角色参数,空为所有用户
        role = request.GET.get('role', '')

        # 获取用户信息
        data = BkUser.objects.get_all_user(role)
        return ApiV1OKJsonResponse(_("用户信息获取成功"), data=data)