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)
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)
def CreateAdminRequest(self, params): ''' 新建管理员 ''' s = db.session() try: if params['role_id'] == 1: return str('不能设为为超级管理员') admin = s.query(Admin).filter(Admin.username == params['username']).first() if admin: return str('管理员已存在') item = Admin( admin_id=uuid.uuid4(), username=params['username'], password=Config().get_md5(params['password']), sex=int(params['sex']), nickname=params['nickname'], role_id=int(params['role_id']), avatarUrl=params['avatarUrl'] ) s.add(item) s.commit() return True except Exception as e: s.rollback() print e return str(e.message)
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)
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)
def CreateAdminRequest(self, params): ''' 新建管理员 ''' s = db.session() try: role = s.query(Role).filter( Role.role_id == params['role_id']).first() if not role: return str('角色不存在') if role.mark == default['role_mark']: return str('不能设为为超级管理员') admin = s.query(Admin).filter( Admin.username == params['username']).first() if admin: return str('管理员已存在') item = Admin(admin_id=uuid.uuid4(), username=params['username'], password=Config().get_md5(params['password']), sex=int(params['sex']), email=params['email'], nickname=params['nickname'], avatarUrl=params['avatarUrl'], role_id=params['role_id'], is_disabled=params['is_disabled']) s.add(item) role.admins.append(item) s.commit() return True except Exception as e: s.rollback() print e return str(e.message)