def post(self): form = self.form() metaModel = app.model.bc.meta() # 删除 if self.get_argument('deleteId' , False): metaModel.categoryDelete( self.get_argument('deleteId') ) return self.write( tornado.escape.json_encode( { 'success' : True } ) ) if form.validators(self.request.arguments) : form.values['name'] = tornado.escape.xhtml_escape(form.values['name']) # 编辑 if self.get_argument('id' , False): metaModel.attr = { 'name' : form.values['name'] } metaModel.save('[id] = %s' , form.values['id']) return self.write( tornado.escape.json_encode( { 'success' : True } ) ) # 添加 else: metaModel.attr = { 'name' : form.values['name'] } metaModel.attr['type'] = 'category' metaModel.add() return self.redirect('/admin/category') return self.write( tornado.escape.json_encode( { 'success' : False , 'msg' : form.msg } ) )
def post(self): model = app.model.sys.acl() import pylibmc mc = pylibmc.Client() # 删除 if self.get_argument('deleteId' , False) : data = model.find('[id] = %s' , int(self.get_argument('deleteId'))).query() # 清空缓存 if data and mc.get('ACL_URI_' + str(data['uri'])): mc.delete('ACL_URI_' + str(data['uri'])) model.delete('[id] = %s' , int(self.get_argument('deleteId')) ) return self.write( tornado.escape.json_encode({ 'success' : True }) ) form = self.form() if form.validators( self.request.arguments ): model.attr = form.values model.attr['deny'] = tornado.escape.json_encode( model.attr['deny'] ) model.attr['allow'] = tornado.escape.json_encode( model.attr['allow'] ) data = model.find('[id] = %s' , form.values['id']).query() # 清空缓存 if data and mc.get('ACL_URI_' + str(data['uri'])): mc.delete('ACL_URI_' + str(data['uri'])) # 添加 if not form.values['id']: model.add() # 编辑 else: model.save('[id] = %s' , form.values['id'] ) self.redirect("/admin/acl")
def post(self): form = self.form() passwordForm = self.passwordForm() user = self.acl_current_user() userModel = app.model.uc.user() # 资料编辑 if form.validators( self.request.arguments ): # 检查邮件是否重复 if 0 != userModel.find('[email] = %s AND [id] != %s' , form.values['email'] , user['id']).count() : return self.error( msg = '邮箱已经存在!' ) # 检查昵称是否重复 if 0 != userModel.find('[nickname] = %s AND [id] != %s' , form.values['nickname'] , user['id']).count() : return self.error( msg = '昵称已经存在!' ) userModel.attr = form.values userModel.save('[id] = %s' , user['id']) elif passwordForm.validators( self.request.arguments ): if passwordForm.values['password'] != passwordForm.values['confirm'] : return self.error( msg = '两次输入密码不相符' ) import hashlib user = userModel.find('[id] = %s' , user['id']).query() m = hashlib.md5() m.update( passwordForm.values['password'] ) m.update( user['encryption'] ) userModel.attr = { 'password' : m.hexdigest() } userModel.save('[id] = %s' , user['id']) self.redirect("/admin/profile")
def post(self): import time time.sleep(3) form = self.form() if form.validators(self.request.arguments): userModel = app.model.uc.user() data = userModel.find('[email] = %s', form.values['userEmail']).query() if not data: return self.error(msg='账户不存在 或 邮箱未能过验证') import hashlib m = hashlib.md5() m.update(form.values['password']) m.update(data['encryption']) if m.hexdigest() == data['password']: # 更新最后登陆时间 userModel.attr = {'last_login_time': time.time()} userModel.save('[email] = %s', form.values['userEmail']) # 写入登陆信息 roleCodes = app.model.uc.user.roleCodes(data['id']) self.set_acl_current_user(data, roleCodes) self.redirect("/admin/articles") else: return self.error(msg='密码错误')
def post(self): form = self.form() if form.validators( self.request.arguments ): option._options['site_comment'] = form.values self.redirect('/admin/comment')
def post(self): form = self.form() if form.validators( self.request.arguments ): # 添加 if not form.values['id']: id = False # 确保缩略名唯一 if 0 != app.model.bc.content().find('[slug] = %s' , form.values['slug']).count(): return self.error( msg = '缩略名已经存在' ) # 编辑 else: id = form.values['id'][0] id = int(id) # 确保缩略名唯一 if 0 != app.model.bc.content().find('[slug] = %s AND [id] != %s' , form.values['slug'] , id).count(): return self.error( msg = '缩略名已经存在' ) # 删除tag关联 app.model.bc.content.tagDelete( id ) # 标记为页面 form.values['type'] = 'page' # tags tags = form.values.pop('tags' , '[]') data = form.values data['user_id'] = self.acl_current_user()['id'] contentModel = app.model.bc.content() contentModel.attr = data # 编辑 if False != id : del contentModel.attr['id'] contentModel.attr['modified'] = time.time() contentModel.save('[id] = %s' , id) else : # 添加 contentModel.attr['created'] = time.time() id = contentModel.add() # 关联tag app.model.bc.content.tagAdd( tags , id ) else: return self.error( msg = form.msg ) self.redirect("/admin/pages")
def post(self): type = self.get_argument('type' , False) if type: if 'enable' == type and self.get_argument('name' , False): return self.enable( self.get_argument('name') ) elif 'disable' == type and self.get_argument('name' , False): return self.disable( self.get_argument('name') ) elif 'config' == type and self.get_argument('name' , False): name = self.get_argument('name') form = self.getForm( name ) if form and form.validators( self.request.arguments ): pluginModel = app.model.sys.plugin() data = pluginModel.getData( name ) data['config'] = form.values pluginModel.setData(name , **data) self.redirect('/admin/plugin')
def post(self): if False == self.allowInstallation(): return self.error( msg = '已经完成安装' ) if self.mysqlIsConnection() and self.storageIsConnection() and self.memcacheIsConnection() : step = int( self.get_argument('step' , '1') ) # 安装第一步 if step == 1: file = open( os.path.join( self.settings['root_path'] , 'qcore.sql' ) , 'r' ) sql = file.read().split(';') del sql[ len(sql) - 1 ] import core.db dbModel = core.db.base() for v in sql: dbModel.db.execute( v ) return self.redirect('/install?step=2') elif step == 2: form = self.form() # 资料编辑 if form.validators( self.request.arguments ): userModel = app.model.uc.user() import hashlib userModel.attr = form.values userModel.attr['encryption'] = app.model.uc.user.buildEncryption() m = hashlib.md5() m.update( userModel.attr['password'] ) m.update( userModel.attr['encryption'] ) userModel.attr['password'] = m.hexdigest() id = userModel.add() # 绑定管理员 userModel.bindRoles( id , [1] ) return self.redirect('/install?step=3') else: return self.error( msg = form.msg ) else: return self.error( msg = '请检查安装环境' )
def post(self): # 删除 if self.get_argument('deleteId' , False) : app.model.uc.role().remove( self.get_argument('deleteId') ) return self.write( tornado.escape.json_encode({ 'success' : True }) ) form = self.form(); if form.validators( self.request.arguments ): roleModel = app.model.uc.role() # 添加 if None == form.values['id']: roleModel.attr = form.values roleModel.add() # 修改 else: roleModel.attr = form.values roleModel.edit('id = %s' , form.values['id']) self.redirect("/admin/role")
def post(self): form = self.form() roleForm = self.roleForm() # 资料编辑 if form.validators( self.request.arguments ): userModel = app.model.uc.user() import hashlib # 添加 if not form.values['id']: userModel.attr = form.values userModel.attr['encryption'] = app.model.uc.user.buildEncryption() m = hashlib.md5() m.update( userModel.attr['password'] ) m.update( userModel.attr['encryption'] ) userModel.attr['password'] = m.hexdigest() userModel.add() # 编辑 else: # 不为空,修改密码 if form.values['password'] != None: user = userModel.find('[id] = %s' , form.values['id']).query() m = hashlib.md5() m.update( form.values['password'] ) m.update( user['encryption'] ) form.values['password'] = m.hexdigest() else: del form.values['password'] userModel.attr = form.values userModel.save('[id] = %s' , form.values['id']) # 角色绑定 elif roleForm.validators( self.request.arguments ): app.model.uc.user.bindRoles( roleForm.values['id'] , roleForm.values['roleIds'] ) else: return self.error( msg = form.msg ) self.redirect("/admin/user")
def post(self): form = self.form() if form.validators( self.request.arguments ): # 添加 if not form.values['id']: id = False # 确保缩略名唯一 if 0 != app.model.bc.content().find('[slug] = %s' , form.values['slug']).count(): return self.error( msg = '缩略名已经存在' ) # 编辑 else: id = form.values['id'][0] id = int(id) # 确保缩略名唯一 if 0 != app.model.bc.content().find('[slug] = %s AND [id] != %s' , form.values['slug'] , id).count(): return self.error( msg = '缩略名已经存在' ) # 删除旧分类关联 app.model.bc.content.categoryDelete( id ) # 删除tag关联 app.model.bc.content.tagDelete( id ) metaId = form.values.pop('category_id') # tags tags = form.values.pop('tags' , '[]') data = form.values data['user_id'] = self.acl_current_user()['id'] contentModel = app.model.bc.content() contentModel.attr = data # 编辑 if False != id : del contentModel.attr['id'] contentModel.attr['modified'] = time.time() contentModel.save('[id] = %s' , id) else : # 添加 contentModel.attr['created'] = time.time() id = contentModel.add() # 关联分类 metaHasContentModel = app.model.bc.metaHasContent() metaHasContentModel.attr = { 'meta_id' : metaId , 'content_id' : id } # 关联tag app.model.bc.content.tagAdd( tags , id ) metaHasContentModel.add() app.model.bc.meta().updateCount([{ 'meta_id' : metaId }]) else: return self.error( msg = form.msg ) self.redirect("/admin/articles")