def callback(id): """ 修改记录 """ # 检查用户权限 _common_logic.check_user_power() name = web_helper.get_form('name', '角色名称') department_id = convert_helper.to_int0( web_helper.get_form('department_id', '部门id')) page_power = web_helper.get_form('page_power', '权限列表', is_check_null=False) if page_power == ',': page_power = '' _positions_logic = positions_logic.PositionsLogic() positions_result = _positions_logic.get_model_for_cache(id) if department_id != positions_result.get('department_id'): return web_helper.return_msg(-1, '该角色所属部门错误,请与管理员联系') # 组合更新字段 fields = { 'name': string(name), 'page_power': string(page_power), } # 读取记录 result = _positions_logic.edit_model(id, fields) if result: # 直接输出json return web_helper.return_msg(0, '提交成功', result) else: return web_helper.return_msg(-1, "提交失败")
def callback(): """ 新增记录 """ # 检查用户权限 _common_logic.check_user_power() name = web_helper.get_form('name', '角色名称') department_id = convert_helper.to_int0( web_helper.get_form('department_id', '部门id')) page_power = web_helper.get_form('page_power', '权限列表', is_check_null=False) _department_logic = department_logic.DepartmentLogic() # 读取对应的部门记录 department_result = _department_logic.get_model_for_cache(department_id) if not department_result: return web_helper.return_msg(-1, "部门不存在") _positions_logic = positions_logic.PositionsLogic() # 组合更新字段 fields = { 'name': string(name), 'department_id': department_id, 'department_code': string(department_result.get('code', '')), 'department_name': string(department_result.get('name', '')), 'page_power': string(page_power), } # 读取记录 result = _positions_logic.add_model(fields) if result: # 直接输出json return web_helper.return_msg(0, '提交成功') else: return web_helper.return_msg(-1, "提交失败")
def callback(): """ 修改记录 """ # 检查用户权限 _common_logic.check_user_power() front_cover_img = web_helper.get_form('front_cover_img', '图片') content = web_helper.get_form('content', '内容', is_check_special_char=False) # 防sql注入攻击处理 content = string_helper.filter_str(content, "'") # 防xss攻击处理 content = string_helper.clear_xss(content) fields = { 'front_cover_img': string(front_cover_img), 'content': string(content), } # 更新记录 _infomation_logic = infomation_logic.InfomationLogic() result = _infomation_logic.edit_model(1, fields) if result: return web_helper.return_msg(0, '成功') else: return web_helper.return_msg(-1, "提交失败")
def add_operation_log(self, manager_id, manager_name, ip, remark): """记录用户登录日志""" # 组合要更新的字段内容 fields = { 'manager_id': manager_id, 'manager_name': string(manager_name), 'ip': string(ip), 'remark': string(remark) } # 更新记录 self.add_model(fields)
def callback(): """ 获取列表数据 """ # 检查用户权限 _common_logic.check_user_power() # 查询条件 wheres = [] start_time = convert_helper.to_date( web_helper.get_query('start_time', '开始时间', is_check_null=False)) if start_time: wheres.append('add_time>=' + string(start_time)) end_time = convert_helper.to_date( web_helper.get_query('end_time', '结束时间', is_check_null=False)) if end_time: end_time = datetime_helper.timedelta('d', end_time, 1) wheres.append('add_time<' + string(end_time)) manager_name = web_helper.get_query('manager_name', '管理员姓名', is_check_null=False) if manager_name: wheres.append('manager_name like \'%' + manager_name + '%\'') ip = web_helper.get_query('ip', 'ip', is_check_null=False) if ip: wheres.append('ip like \'' + ip + '%\'') remark = web_helper.get_query('remark', '操作内容', is_check_null=False) if remark: wheres.append('remark like \'%' + remark + '%\'') # 页面索引 page_number = convert_helper.to_int1( web_helper.get_query('page', '', is_check_null=False)) # 页面页码与显示记录数量 page_size = convert_helper.to_int0( web_helper.get_query('rows', '', is_check_null=False)) sidx = web_helper.get_query('sidx', '', is_check_null=False) sord = web_helper.get_query('sord', '', is_check_null=False) # 初始化排序字段 order_by = 'id desc' if sidx: order_by = sidx + ' ' + sord _manager_operation_log_logic = manager_operation_log_logic.ManagerOperationLogLogic( ) # 读取记录 result = _manager_operation_log_logic.get_list('*', wheres, page_number, page_size, order_by) if result: # 直接输出json return json.dumps(result, cls=json_helper.CJsonEncoder) else: return web_helper.return_msg(-1, "查询失败")
def callback(): """ 新增记录 """ # 检查用户权限 _common_logic.check_user_power() name = web_helper.get_form('name', '菜单名称') icon = web_helper.get_form('icon', '菜单小图标', True, 10, False, is_check_special_char=False) icon = icon.replace('\'', '').replace('|', '').replace('%', '') page_url = web_helper.get_form('page_url', '页面URL', is_check_null=False) interface_url = web_helper.get_form('interface_url', '接口url', is_check_null=False, is_check_special_char=False) # 替换编码 interface_url = interface_url.replace('@', '').replace('\'', '').replace('|', '').replace('%', '') parent_id = convert_helper.to_int0(web_helper.get_form('parent_id', '父id', is_check_null=False)) sort = convert_helper.to_int0(web_helper.get_form('sort', '排序', is_check_null=False)) is_leaf = web_helper.get_form('is_leaf', '是否最终节点', is_check_null=False) is_show = web_helper.get_form('is_show', '是否显示', is_check_null=False) is_enabled = web_helper.get_form('is_enabled', '是否启用', is_check_null=False) _menu_info_logic = menu_info_logic.MenuInfoLogic() # 计算深度级别,即当前菜单在哪一级 if parent_id == 0: level = 0 else: level = _menu_info_logic.get_value_for_cache(parent_id, 'level') + 1 # 如果没有设置排序,则自动获取当前级别最大的序号加1 if sort == 0: sort = _menu_info_logic.get_max('sort', 'parent_id=' + str(parent_id)) + 1 # 组合更新字段 fields = { 'name': string(name), 'icon': string(icon), 'page_url': string(page_url), 'interface_url': string(interface_url), 'parent_id': parent_id, 'sort': sort, 'level': level, 'is_leaf': is_leaf, 'is_show': is_show, 'is_enabled': is_enabled, } # 新增记录 result = _menu_info_logic.add_model(fields) if result: return web_helper.return_msg(0, '提交成功') else: return web_helper.return_msg(-1, "提交失败")
def callback(id): """ 修改记录 """ # 检查用户权限 _common_logic.check_user_power() name = web_helper.get_form('name', '部门名称') parent_id = convert_helper.to_int0(web_helper.get_form('parent_id', '父id', is_check_null=False)) sort = convert_helper.to_int0(web_helper.get_form('sort', '排序', is_check_null=False)) is_leaf = web_helper.get_form('is_leaf', '是否最终节点', is_check_null=False) _department_logic = department_logic.DepartmentLogic() # 如果没有设置排序,则自动获取当前级别最大的序号加1 if sort == 0: sort = _department_logic.get_max('parent_id', 'parent_id=' + str(parent_id)) + 1 # 组合更新字段 fields = { 'name': string(name), 'sort': sort, 'is_leaf': is_leaf, } # 修改记录 result = _department_logic.edit_model(id, fields) if result: return web_helper.return_msg(0, '提交成功', result) else: return web_helper.return_msg(-1, "提交查询失败")
def callback(): """ 新增记录 """ # 检查用户权限 _common_logic.check_user_power() name = web_helper.get_form('name', '部门名称') parent_id = convert_helper.to_int0(web_helper.get_form('parent_id', '父id', is_check_null=False)) sort = convert_helper.to_int0(web_helper.get_form('sort', '排序', is_check_null=False)) is_leaf = web_helper.get_form('is_leaf', '是否最终节点', is_check_null=False) _department_logic = department_logic.DepartmentLogic() # 计算深度级别,即当前部门在哪一级;并生成部门编码 if parent_id == 0: level = 0 code = _department_logic.create_code('') else: model = _department_logic.get_model_for_cache(parent_id) if not model: return web_helper.return_msg(-1, "您选择的部门不存在") level = model.get('level', 0) + 1 code = _department_logic.create_code(model.get('code', '')) # 如果没有设置排序,则自动获取当前级别最大的序号加1 if sort == 0: sort = _department_logic.get_max('parent_id', 'parent_id=' + str(parent_id)) + 1 # 组合更新字段 fields = { 'name': string(name), 'code': string(code), 'parent_id': parent_id, 'sort': sort, 'level': level, 'is_leaf': is_leaf, } # 新增记录 result = _department_logic.add_model(fields) if result: return web_helper.return_msg(0, '提交成功') else: return web_helper.return_msg(-1, "提交失败")
def callback(): """ 新增记录 """ # 检查用户权限 _common_logic.check_user_power() name = web_helper.get_form('name', '产品名称') code = web_helper.get_form('code', '产品编码') product_class_id = convert_helper.to_int0( web_helper.get_form('product_class_id', '产品分类')) standard = web_helper.get_form('standard', '产品规格') quality_guarantee_period = web_helper.get_form('quality_guarantee_period', '保质期') place_of_origin = web_helper.get_form('place_of_origin', '产地') front_cover_img = web_helper.get_form('front_cover_img', '封面图片') content = web_helper.get_form('content', '产品描述', is_check_special_char=False) # 防sql注入攻击处理 content = string_helper.filter_str(content, "'") # 防xss攻击处理 content = string_helper.clear_xss(content) is_enable = convert_helper.to_int0(web_helper.get_form( 'is_enable', '是否启用')) # 设置新增参数 fields = { 'name': string(name), 'code': string(code), 'product_class_id': product_class_id, 'standard': string(standard), 'quality_guarantee_period': string(quality_guarantee_period), 'place_of_origin': string(place_of_origin), 'front_cover_img': string(front_cover_img), 'content': string(content), 'is_enable': is_enable, } # 实例化product表操作类ProductLogic _product_logic = product_logic.ProductLogic() # 新增记录 result = _product_logic.add_model(fields) # 判断是否提交成功 if result: return web_helper.return_msg(0, '成功') else: return web_helper.return_msg(-1, "提交失败")
def callback(): """ 新增记录 """ # 检查用户权限 _common_logic.check_user_power() name = web_helper.get_form('name', '管理员名称') sex = web_helper.get_form('sex', '性别', is_check_null=False) if sex != '男': sex = '女' mobile = web_helper.get_form('mobile', '手机号码', is_check_null=False) if mobile and not string_helper.is_mobile(mobile): return web_helper.return_msg(-1, '手机号码格式不正确') birthday = web_helper.get_form('birthday', '出生日期', is_check_null=False) if birthday: birthday = convert_helper.to_date(birthday) email = web_helper.get_form('email', 'email', is_check_null=False) if email and not string_helper.is_email(email): return web_helper.return_msg(-1, 'Email格式不正确') remark = web_helper.get_form('remark', '备注', is_check_null=False) department_id = convert_helper.to_int0( web_helper.get_form('department_id', '所属部门')) positions_id = convert_helper.to_int0( web_helper.get_form('positions_id', '所属职位')) is_work = convert_helper.to_int0(web_helper.get_form('is_work', '工作状态')) is_enabled = web_helper.get_form('is_enabled', '是否启用', is_check_null=False) login_name = web_helper.get_form('login_name', '登录账号') login_password = web_helper.get_form('login_password1', '登录密码', is_check_special_char=False) if len(login_password) < 6: return web_helper.return_msg(-1, '登录密码长度必须大于等于6位') login_password = encrypt_helper.md5( encrypt_helper.md5(login_password)[2:24]) # 判断提交的部门id是否正确 _department_logic = department_logic.DepartmentLogic() department_result = _department_logic.get_model_for_cache(department_id) if not department_result: return web_helper.return_msg(-1, '所属部门不存在') # 判断提交的职位id是否正确 _positions_logic = positions_logic.PositionsLogic() positions_result = _positions_logic.get_model_for_cache(positions_id) if not positions_result or positions_result.get( 'department_id') != department_id: return web_helper.return_msg(-1, '所属职位不存在') _manager_logic = manager_logic.ManagerLogic() # 组合更新字段 fields = { 'name': string(name), 'sex': string(sex), 'mobile': string(mobile), 'email': string(email), 'remark': string(remark), 'department_id': department_id, 'department_code': string(department_result.get('code', '')), 'department_name': string(department_result.get('name', '')), 'positions_id': positions_id, 'positions_name': string(positions_result.get('name', '')), 'is_work': is_work, 'is_enabled': is_enabled, 'login_name': string(login_name), 'login_password': string(login_password), } if birthday: fields['birthday'] = string(str(birthday)) # 添加记录 result = _manager_logic.add_model(fields) if result: return web_helper.return_msg(0, '成功') else: return web_helper.return_msg(-1, "提交失败")
def test_string(self): print(string_helper.string(-1)) print(string_helper.string({'test': 'abc'})) print(string_helper.string('')) print(string_helper.string('aaa')) print(string_helper.string('', True))
def post_login(): """用户登陆验证""" ############################################################## # 获取并验证客户端提交的参数 ############################################################## username = web_helper.get_form('username', '帐号') password = web_helper.get_form('password', '密码') verify = web_helper.get_form('verify', '验证码') ip = web_helper.get_ip() ############################################################## # 从session中读取验证码信息 ############################################################## s = web_helper.get_session() verify_code = s.get('verify_code') # 删除session中的验证码(验证码每提交一次就失效) if 'verify_code' in s: del s['verify_code'] s.save() # 判断用户提交的验证码和存储在session中的验证码是否相同 if verify.upper() != verify_code: return web_helper.return_msg(-1, '验证码错误') ############################################################## ### 判断用户登录失败次数,超出次做登录限制 ### # 获取管理员登录密码错误限制次数,0=无限制,x次/小时 limit_login_count = 10 # 获取操作出错限制值 is_ok, msg, operation_times_key, error_count = security_helper.check_operation_times('login_error_count', limit_login_count, web_helper.get_ip(), False) # 判断操作的出错次数是否已超出了限制 if not is_ok: return web_helper.return_msg(-1, msg) ############################################################## ### 获取登录用户记录,并进行登录验证 ### ############################################################## # 初始化操作日志记录类 _manager_operation_log_logic = manager_operation_log_logic.ManagerOperationLogLogic() # 初始化管理员逻辑类 _manager_logic = manager_logic.ManagerLogic() # 从数据库中读取用户信息 manager_result = _manager_logic.get_model_for_cache_of_where('login_name=' + string(username)) # 判断用户记录是否存在 if not manager_result: return web_helper.return_msg(-1, '账户不存在') # 获取管理员id manager_id = manager_result.get('id', 0) # 获取管理员姓名 manager_name = manager_result.get('name', '') ############################################################## ### 验证用户登录密码与状态 ### ############################################################## # 对客户端提交上来的验证进行md5加密将转为大写(为了密码的保密性,这里进行双重md5加密,加密时从第一次加密后的密串中提取一段字符串出来进行再次加密,提取的串大家可以自由设定) # pwd = encrypt_helper.md5(encrypt_helper.md5(password)[1:30]).upper() # 对客户端提交上来的验证进行md5加密将转为大写(只加密一次) pwd = encrypt_helper.md5(password).upper() # 检查登录密码输入是否正确 if pwd != manager_result.get('login_password').upper(): # 记录出错次数 security_helper.add_operation_times(operation_times_key) # 记录日志 _manager_operation_log_logic.add_operation_log(manager_id, manager_name, ip, '【' + manager_name + '】输入的登录密码错误') return web_helper.return_msg(-1, '密码错误') # 检查该账号虽否禁用了 if not manager_result.get('is_enabled'): # 记录出错次数 security_helper.add_operation_times(operation_times_key) # 记录日志 _manager_operation_log_logic.add_operation_log(manager_id, manager_name, ip, '【' + manager_name + '】账号已被禁用,不能登录系统') return web_helper.return_msg(-1, '账号已被禁用') # 登录成功,清除登录错误记录 security_helper.del_operation_times(operation_times_key) ############################################################## ### 把用户信息保存到session中 ### ############################################################## manager_id = manager_result.get('id') s['id'] = manager_id s['login_name'] = username s['name'] = manager_result.get('name') s['positions_id'] = manager_result.get('positions_id') s.save() ############################################################## ### 更新用户信息到数据库 ### ############################################################## # 更新当前管理员最后登录时间、Ip与登录次数(字段说明,请看数据字典) fields = { 'last_login_time': 'now()', 'last_login_ip': string(ip), 'login_count': 'login_count+1', } # 写入数据库 _manager_logic.edit_model(manager_id, fields) # 记录日志 _manager_operation_log_logic.add_operation_log(manager_id, manager_name, ip, '【' + manager_name + '】登陆成功') return web_helper.return_msg(0, '登录成功')