示例#1
0
    def create_syndicate(self):
        name = self.get_argument("name","")
        desc = self.get_argument("desc","")
        uuid = self.get_argument("uuid","")
        user_name = self.get_argument("user_name","")
        telephone = self.get_argument("telephone","")
        self.logger.info("name:"+name+"  desc:"+desc+"  user_name:"+user_name+"  telephone:"+telephone)

        if name == "" or user_name == "" or telephone == "" or uuid == "":
            self.set_status(400)
            return {"result":False,'msg':err_msgs['PARAMS_MISSING']}

        usr_db = UserDao(session= self.session)
        # 一个超级运营员只允许管理一个集团
        if usr_db.exist_role_group_by_tel(telephone, Users.ROLE_SUP_MGR):
            result = {
                    'result': False,
                    'msg': err_msgs['ROLE_SUP_MGR_EXIST']
                }
            self.set_status(400)
            return result

        match, usr_id, user_name = usr_db.insert_user(user_name,telephone, Users.ROLE_SUP_MGR)
        if not match:
            result = {
                    'result': False,
                    'msg': err_msgs['TEL_NAME_NOT_MATCH'],
                    'name': user_name
                }
            self.set_status(400)
            return result

        token = self.request.headers.get("user_token",None)
        redis = RedisBase()
        token_info = redis.get_token_info(token)
        user_id = token_info['uuid']

        com_db = CompanyDao(session=self.session)
        # 当uuid已存在时插入失败,返回推荐uuid
        if not com_db.insert_company(name,desc,None,user_id,Company.NO_PARENT,uuid,None):
            result = {
                'result': False,
                'msg': err_msgs['COM_UUID_EXIST'],
                'recommendation': self.build_company_uuid(uuid)
            }
            self.set_status(400)
            return result

        usr_rle_db = UserConfDao(session=self.session)
        usr_rle_db.insert_role(usr_id,uuid,UserConf.SUB_ROLE_SUP_MGR,UserConf.TYPE_ROLE_SUPMGR)
        # 日志
        self.log_user_action(token_info.get("uuid"),"create_syndicate",uuid)

        result = {
            'result': True
        }
        return result
示例#2
0
    def add_supmanager(self):
        user_name = self.get_argument("user_name", "")
        telephone = self.get_argument("telephone", "")
        syndicate = self.get_argument("syndicate", "")

        self.logger.info("username:"******"  telephone:" + telephone +
                         "  syndicate:" + syndicate)

        if user_name == '' or telephone == '' or syndicate == '':
            self.set_status(400)
            return {"result": False, 'msg': err_msgs['PARAMS_MISSING']}

        usr_db = UserDao(session=self.session)

        # 一个超级运营员只允许管理一个集团
        if usr_db.exist_role_group_by_tel(telephone, Users.ROLE_SUP_MGR):
            result = {'result': False, 'msg': err_msgs['ROLE_SUP_MGR_EXIST']}
            self.set_status(400)
            return result

        match, usr_id, user_name = usr_db.insert_user(user_name, telephone,
                                                      Users.ROLE_SUP_MGR)
        if not match:
            result = {
                'result': False,
                'msg': err_msgs['TEL_NAME_NOT_MATCH'],
                'name': user_name
            }
            self.set_status(400)
            return result

        usr_rle_db = UserConfDao(session=self.session)
        usr_rle_db.insert_role(usr_id, syndicate, UserConf.SUB_ROLE_SUP_MGR,
                               UserConf.TYPE_ROLE_SUPMGR)
        # 日志
        self.log_user_action(self.get_token().get("uuid"), "add_supmgr",
                             usr_id)

        result = {'result': True, 'user_id': usr_id}
        return result
示例#3
0
    def add_admin(self):
        user_name = self.get_argument("user_name", "")
        telephone = self.get_argument("telephone", "")
        roles = self.get_arguments("role[]")

        if user_name == '' or telephone == '':
            self.set_status(400)
            return {"result": False, 'msg': err_msgs['PARAMS_MISSING']}

        usr_db = UserDao(session=self.session)
        # 一个手机号只能存在一个管理员角色
        if usr_db.exist_role_group_by_tel(telephone, Users.ROLE_ADMIN):
            result = {'result': False, 'msg': err_msgs['ROLE_ADMIN_EXIST']}
            self.set_status(400)
            return result

        match, usr_id, user_name = usr_db.insert_user(user_name, telephone,
                                                      Users.ROLE_ADMIN)
        if not match:
            result = {
                'result': False,
                'msg': err_msgs['TEL_NAME_NOT_MATCH'],
                'name': user_name
            }
            self.set_status(400)
            return result

        usr_rle_db = UserConfDao(session=self.session)
        for role in roles:
            usr_rle_db.insert_role(usr_id, UserConf.ACC_COM_ID, role,
                                   UserConf.TYPE_ROLE_ADMIN)
        # 日志
        self.log_user_action(self.get_token().get("uuid"), "add_admin", usr_id)

        result = {'result': True, 'user_id': usr_id}
        return result