Пример #1
0
    def CreateDropRequest(self):
        try:
            db.drop_all()
            db.create_all()

            s = db.session()
            admin = Admin(
                admin_id=uuid.uuid4(),
                username=u'Admin',
                password=Config().get_md5('123456'),
                avatarUrl='',
                role_id=1
            )
            s.add(admin)
            s.commit()

            role_id = uuid.uuid4()
            role = Role(role_id=role_id, name=u'超级管理员', checkKey='[]')
            s.add(role)
            s.commit()

            self.__init_routes(init_route, '0', role_id)
            self.__init_menus(init_menu, '0', role_id)
            return True
        except Exception as e:
            print e
            return str(e.message)
Пример #2
0
    def CreateDropRequest(self, isInit, params=None):
        db.drop_all()
        db.create_all()

        s = db.session()
        try:
            s.add(InitSql(isInit=False))
            s.commit()

            role_id = uuid.uuid4()
            role = Role(
                role_id=role_id,
                name=self.role_name,
                mark=default['role_mark']
            )
            s.add(role)
            s.commit()

            password = self.__get_code()
            if not isInit:
                admin = Admin(
                    admin_id=uuid.uuid4(),
                    username=self.user_name,
                    password=Config().get_md5(password),
                    avatarUrl='',
                    role_id=role_id
                )
            else:
                admin = Admin(
                    admin_id=params['admin_id'],
                    username=self.user_name,
                    password=params['password'],
                    avatarUrl='',
                    role_id=role_id
                )
            s.add(admin)
            s.commit()

            self.__init_menus(s, init_menu)

            folder = Folder(
                folder_id=uuid.uuid4(),
                admin_id=None,
                name=u'系统文件',
                is_sys=True
            )
            s.add(folder)
            s.commit()

            sql = s.query(InitSql).one()
            sql.isInit = True
            s.commit()
            return {
                'username': '******',
                'password': password
            }
        except Exception as e:
            s.rollback()
            print e
            return str(e.message)
Пример #3
0
    def CreateRoleRequest(self, params):
        '''
        新建权限
        '''
        s = db.session()
        is_exists = self.isCreateExists(s, params)

        if is_exists != True:
            return str(is_exists['error'].encode('utf8'))

        try:
            item = Role(name=params['name'],
                        mark=params['mark'],
                        role_id=uuid.uuid4(),
                        is_disabled=params['is_disabled'],
                        role_list=json.dumps({
                            'I': params['role_list'],
                            'M': params['menu']
                        }))
            s.add(item)
            s.commit()
            return True
        except Exception as e:
            s.rollback()
            print e
            return str(e.message)
Пример #4
0
    def CreateRoleRequest(self, params):
        '''
        新建鉴权
        '''
        s = db.session()
        is_exists = self.isCreateExists(s, params)

        if is_exists != True:
            return str(is_exists['error'])

        try:
            item = Role(
                name=params['name'],
                mark=params['mark'],
                role_id=str(uuid.uuid4()),
                disable=params['disable'],
                menus=s.query(Menu).filter(Menu.menu_id.in_(params.getlist('menu[]'))).all(),
                interfaces=s.query(Interface).filter(Interface.interface_id.in_(params.getlist('interface[]'))).all()
            )
            s.add(item)
            s.commit()
            return True
        except Exception as e:
            s.rollback()
            print(e)
            return str(e)
Пример #5
0
    def CreateDropRequest(self, isInit):
        try:
            s = db.session()

            if isInit:
                try:
                    res = s.query(InitSql).first()
                    if res.isInit:
                        return str('已经初始化~~~')
                except:
                    pass

            db.drop_all()
            db.create_all()

            admin = Admin(admin_id=uuid.uuid4(),
                          username=u'Admin',
                          password=Config().get_md5('123456'),
                          avatarUrl='',
                          role_id=1)
            s.add(admin)
            s.commit()

            role_id = uuid.uuid4()
            role = Role(role_id=role_id, name=u'超级管理员', checkKey='[]')
            s.add(role)
            s.commit()

            self.__init_routes(init_route, '0', role_id)
            self.__init_menus(init_menu, '0', role_id)

            if not isInit:
                sql = InitSql(isInit=True)
                s.add(sql)
                s.commit()

            return True
        except Exception as e:
            print e
            return str(e.message)
Пример #6
0
    def CreateDropRequest(self, is_init, params=None):
        db.session.remove()
        db.drop_all()
        db.create_all()

        s = db.session()
        try:
            role_id = str(uuid.uuid4())
            role = Role(role_id=role_id,
                        name=self.role_name,
                        mark=default['role_mark'])

            self.__init_menus(role, s, init_menu)

            password = self.__get_code()
            if not is_init:
                admin = Admin(admin_id=str(uuid.uuid4()),
                              username=self.user_name,
                              password=_config.get_md5(password),
                              role_id=role_id)
            else:
                admin = Admin(admin_id=params['admin_id'],
                              username=self.user_name,
                              password=params['password'],
                              role_id=role_id)

            folder = Folder(folder_id=str(uuid.uuid4()), name=self.folder_name)

            init = InitSql(is_init=True)

            s.add_all([role, admin, folder, init])
            s.commit()
            return {'username': self.user_name, 'password': password}
        except Exception as e:
            print(e)
            s.rollback()
            s.add(InitSql(is_init=False))
            s.commit()
            return str(e)
Пример #7
0
    def CreateRoleRequest(self, params):
        '''
        新建权限
        '''
        s = db.session()
        try:
            route = s.query(Route).filter(
                Route.route_id.in_(params['route_id'])).all()
            menu = s.query(Menu).filter(Menu.menu_id.in_(
                params['menu_id'])).all()

            item = Role(name=params['name'],
                        role_id=uuid.uuid4(),
                        checkKey=params['checkKey'],
                        routes=route,
                        menus=menu)
            s.add(item)
            s.commit()
            return True
        except Exception as e:
            s.rollback()
            print e
            return str(e.message)
Пример #8
0
    def CreateRoleRequest(self, params):
        '''
        新建权限
        '''
        s = db.session()
        try:
            interface = s.query(Interface).filter(
                Interface.interface_id.in_(params['interface_id'])).all()
            menu = s.query(Menu).filter(Menu.menu_id.in_(
                params['menu_id'])).all()

            item = Role(name=params['name'],
                        mark=params['mark'],
                        role_id=uuid.uuid4(),
                        interfaces=interface,
                        menus=menu)
            s.add(item)
            s.commit()
            return True
        except Exception as e:
            s.rollback()
            print e
            return str(e.message)