Example #1
0
    def put(self):
        """
        修改用户密码
        """

        req = modify_password.parse_args(strict=True)
        if req["newPassword"] != req["verifyPassword"]:
            return Msg.PARAMS_ERROR, 400
        user = request.current_user
        if user.verify_password(req["oldPassword"]):
            user.generate_password(req["newPassword"])
            db.session.commit()
            key = "support_jwt_{}".format(request.current_user.code)
            redis_delete(key)
            msg = "SUPPORT | B_USER | MODIFY_PASSOWRD | SUCCESS | USER_CODE: {} | USER_NAME: {}".format(
                user.code, user.name)
            operation = TbOperation(operator_code=user.code,
                                    content=msg,
                                    category="USER",
                                    type="EDIT")
            db.session.add(operation)
            db.session.commit()
            logger.info(msg)
            return {}, 200
        return Msg.OLD_PASSWORD_ERROR, 400
Example #2
0
 def put(self):
     req = active_user.parse_args(strict=True)
     user = TbUser.query.filter_by(code=req["id"]).first()
     if not user:
         return Msg.USER_NOT_EXISTS, 400
     user.active = req["status"]
     if req["status"] is False:
         redis_delete("support_jwt_{}".format(user.code))
     msg = "SUPPORT | B_USER | ACTIVE_USER | SUCCESS | EDITOR: {} {} | USER: {} {} | STATUS: {}".format(
         request.current_user.code, request.current_user.name, user.code,
         user.name, req["status"])
     operation = TbOperation(operator_code=user.code,
                             content=msg,
                             category="USER_MANAGE",
                             type="EDIT")
     db.session.add(operation)
     db.session.commit()
     logger.info(msg)
     return {}, 200
Example #3
0
 def put(self):
     # 修改产品开关
     merchant_code = request.json.pop("merchant_code", None)
     production_code = request.json.pop("production_code", None)
     production_flag = request.json.pop("production_flag", None)
     request.json.pop("id", None)
     production = TbProduction.query.filter(
         TbProduction.code == production_code,
         TbMerchant.code == merchant_code).first()
     if not production:
         return Msg.PRODUCTION_NOT_EXIST, 400
     if not isinstance(production_flag, bool):
         return "参数错误", 400
     production.status = production_flag
     # 删除 redis 产品的缓存
     appid_key = "tb_production:merchant_code:{}".format(
         production.merchant_code)
     redis_delete(appid_key)
     db.session.commit()
     return get_data(production, TbProduction, exclude=self.exclude)
Example #4
0
 def put(self):
     schema = Schema({
         "id": And(str),
         "name": And(str, len),
         "production": And(str, len)
     })
     req, error = validate_schema(schema, request.json, remove_blank=True)
     if error:
         return error, 400
     mer = TbMerchant.query.filter_by(code=req["id"]).first()
     dup_mer = TbMerchant.query.filter_by(name=req["name"]).first()
     if dup_mer and dup_mer.code != mer.code:
         return Msg.MERCHANT_NAME_ALREADY_EXIST, 400
     mer.name = req["name"]
     production = TbProduction.query.filter_by(
         merchant_code=req["id"]).first()
     if not production:
         return Msg.PRODUCTION_NOT_EXIST, 400
     production.name = req.get("production")
     msg = "SUPPORT | B_USER | EDIT_MERCHAT | SUCCESS | USER: {} {} | MERCHAT: {} {} | PRODUCTION: {} {}".format(
         request.current_user.code, request.current_user.name, mer.code,
         mer.name, production.code, production.name)
     operation = TbOperation(operator_code=request.current_user.code,
                             content=msg,
                             category="MERCHANT",
                             type="EDIT")
     db.session.add(operation)
     db.session.commit()
     app.logger.info(msg)
     # 删除 redis 商户的缓存
     key = "tb_merchant:code:{}".format(mer.code)
     redis_delete(key)
     # 删除 redis 产品的缓存
     key = "tb_production:merchant_code:{}".format(mer.code)
     redis_delete(key)
     return {}, 200
Example #5
0
 def put(self):
     """
     更新产品信息
     """
     schema = Schema({
         "production": [{
             Optional("appid"): And(str),
             Optional("official_account_name"): And(str),
             Optional("amount_limit"): And(int),
             "name": And(str),
             "code": And(str),
             "logo": And(str),
             "icon": And(str),
             "face_flag": And(bool),
             "e_sign": And(bool)
         }],
         "merchant_code":
         And(str),
         "user_code":
         And(str)
     })
     req, error = validate_schema(schema, request.json, remove_blank=True)
     if error:
         return error, 400
     user = TbUser.query.filter_by(code=req["user_code"]).first()
     if not user:
         return Msg.USER_NOT_EXISTS, 400
     query_set = TbProduction.query.filter_by(
         merchant_code=req["merchant_code"])
     for i in req["production"]:
         pro = query_set.filter_by(code=i["code"]).first()
         if not pro:
             return Msg.PRODUCTION_NOT_EXIST, 400
         # 如果用户传了 appid
         if i.get("appid"):
             if TbMerchantPublic.query.filter(
                     TbMerchantPublic.production_code != pro.code,
                     TbMerchantPublic.appid == i["appid"]).first():
                 return Msg.OFFICIAL_ACCOUNT_ALREADY_EXIST, 400
             public = TbMerchantPublic.query.filter_by(
                 production_code=pro.code).first()
             # 如果没有检测到公众号,就创建一个,否则进行一次修改
             if not public:
                 pub = TbMerchantPublic(name=i.get("official_account_name"),
                                        appid=i["appid"],
                                        creator_code=user.code,
                                        merchant_code=req["merchant_code"],
                                        production_code=pro.code)
                 db.session.add(pub)
             else:
                 public.appid = i["appid"]
                 public.name = i.get("official_account_name")
                 # 删除 redis 公众号的缓存
                 appid_key = "merchant_public:appid:{}".format(
                     i.get("appid"))
                 redis_delete(appid_key)
         pro.name = i["name"]
         pro.logo = i["logo"]
         pro.icon = i["icon"]
         pro.face_flag = i["face_flag"]
         pro.e_sign = i["e_sign"]
         pro.amount_limit = i.get("amount_limit") if i["face_flag"] else 0
         # 删除 redis 产品的缓存
         pro_key = "tb_production:merchant_code:{}".format(
             req["merchant_code"])
         redis_delete(pro_key)
     msg = "SUPPORT | PRODUCTION | EDIT_PRODUCTION | SUCCESS | USER: {} {} | PRODUCTION: {}".format(
         user.code,
         user.name,
         req["production"],
     )
     try:
         operation = TbOperation(operator_code=req["user_code"],
                                 content=msg,
                                 type="EDIT",
                                 category="PRODUCTION")
         db.session.add(operation)
         db.session.commit()
         logger.info(msg)
         return {}, 200
     except Exception as e:
         logger.warn(
             "SUPPORT PRODUCTION | EDIT_PRODUCTION | FAILED | USER: {} {} | ERROR: {}"
             .format(user.code, user.name, str(e)))
         db.session.rollback()
         return Msg.UPDATE_PRODUCTION_FAILED, 400
Example #6
0
 def get(self):
     key = "support_jwt_{}".format(request.current_user.code)
     redis_delete(key)
     return {}, 200