def test(username_front, passwd_front): #前台传参数 # 要返回的数据 code = 500 # 返回给调用者的值,默认是500 Number类型的 msg = '注册失败' count = 0 data = [] # 默认是一个list形式的 if username_front is not None and passwd_front is not None: print('==注册==,前台传的-username====', username_front) print('==注册==,前台传的-password====', passwd_front) # 1. 加密passwd md5_passwd = utils.get_md5(passwd_front) """ sql字段: userid: int username: str password: str user_remark: str user_email: str user_level: int (1-管理员 2 普通用户) create_time: date (2020-01-01这种格式) session: str """ # 2. 加密结果存储 # insert_passwd_sql = 'insert into bugcount.user values(null, %s, %s, null, null, null, null, null)' insert_passwd_sql = 'select username from bugcount.user where username =%s' # 查看是否注册成功 # 返回值为list 0位状态码 1位sql结果个数 2位为查询结果 return_list = dbutils.execute_db_onesql(insert_passwd_sql, username_front, md5_passwd) print('dbutil 执行返回结果=======', return_list) #判断系统是否有此账号username print('注册成功') code = return_list[0] msg = '注册成功' count = return_list[2] data = return_list[3] print("??????????????????????????执行sql返回的tuple==", return_list[3]) #需要返回查询的sql数量,和查询结果 #返回一个num型的成功或者失败 return_list = [code, msg, count, data] print(f'注册方法返回结果list=={return_list}') return return_list
def editUser(): print('<app.py> 编辑单个用户') code = 500 print('??????????????code type=', type(code)) msg = '编辑用户失败,请重新尝试' count = 0 edituser_sql_return_json_data = list() # json数据 data = {} # GET请求 if request.method == "GET": print('get请求') msg = 'get请求,不处理' # POST请求 if request.method == "POST": print("====注册===== - post请求") print('requets.header=', request.headers) print('equest.json', request.json) print('equest.date', request.data) #需要获取的参数 userid 根据userid删除,requst请求通过form 或者value都能拿到,因为requst里参数就是form userid = request.values.get('userid') print('获取到的参数 userid ==', userid) username = request.form.get('username') password = request.form.get('password') user_remark = request.form.get('user_remark') user_email = request.form.get('user_email') user_level = request.form.get('user_level') create_time = request.form.get('create_time') session = request.form.get('session') # 1. 加密passwd md5_passwd = utils.get_md5(password) # 账号或密码不能为空 if userid is not None: if userid.strip() == '': msg = 'userid为空' else: # 执行sql , 除了userid 和username 不能改,其他都能改 edituser_return_json = admin.edit_user(userid, username, md5_passwd, user_remark, user_email, user_level, create_time, session) # 判断执行结果,我只要成功或者失败就可以了 # 获取到json需要解析 edituser_return_json_loads = json.loads(edituser_return_json) if edituser_return_json_loads['code'] == 200: code = edituser_return_json_loads['code'] msg = '编辑用户成功' count = edituser_return_json_loads['count'] edituser_sql_return_json_data = edituser_return_json_loads[ 'data'] if edituser_return_json_loads['code'] == 500: msg = edituser_return_json_loads['msg'] # 编辑用户失败 else: msg = 'userid为空,不做操作' print('userid为空,不做操作') # 什么条件都不符合,返回失败 data['code'] = code data['msg'] = msg data['count'] = count data['data'] = edituser_sql_return_json_data print('未转化json前的数据, ===', data) # 转化下查询结果为{},{},{}这种格式====================== json_str = json.dumps(data, ensure_ascii=False) # ensure_ascii=False传回utf8 print('《app.py》返回json==jsonStr=====', json_str) return json_str
def addUser(): print('<app.py> 添加用户') code = 500 print('??????????????code type=', type(code)) msg = '添加用户失败,请重新尝试' count = 0 adduser_sql_return_json_data = list() # json数据 data = {} # GET请求 if request.method == "GET": print('get请求') msg = 'get请求,不处理' # POST请求 if request.method == "POST": print("====注册===== - post请求") print('requets.header=', request.headers) print('equest.json', request.json) print('equest.date', request.data) # 获取数据并转化成字典 # user_info = request.form.to_dict() # print('type-username = '******'123456': # return redirect("/") #需要获取的参数 username, password, user_remark, user_email, user_level, create_time, session username = request.form.get('username') password = request.form.get('password') user_remark = request.form.get('user_remark') user_email = request.form.get('user_email') user_level = request.form.get('user_level') print('???????????????user level===============================', user_level) create_time = request.form.get('create_time') session = request.form.get('session') roleId = request.form.get('roleId') # 密码需要md5加密 # 1. 加密passwd md5_passwd = utils.get_md5(password) print('获取到的参数 ==', username, password) # 账号或密码不能为空 if username is not None and password is not None: if username.strip() == '' or password.strip() == '': msg = '用户名或密码为空' else: # 执行sql print( '???????????????user level===============================', user_level) adduser_return_json = admin.add_user(username, md5_passwd, user_remark, user_email, user_level, create_time, session, roleId) # 判断执行结果,我只要成功或者失败就可以了 # 获取到json需要解析 adduser_return_json_loads = json.loads(adduser_return_json) if adduser_return_json_loads['code'] == 200: code = adduser_return_json_loads['code'] msg = '添加用户成功' count = adduser_return_json_loads['count'] adduser_sql_return_json_data = adduser_return_json_loads[ 'data'] if adduser_return_json_loads['code'] == 500: msg = adduser_return_json_loads['msg'] # 此用户已存在 else: msg = '用户名或密码为空,不做操作' print('用户名或密码为空,不做操作') # 什么条件都不符合,返回失败 data['code'] = code data['msg'] = msg data['count'] = count data['data'] = adduser_sql_return_json_data print('未转化json前的数据, ===', data) # 转化下查询结果为{},{},{}这种格式====================== json_str = json.dumps(data, ensure_ascii=False) # ensure_ascii=False传回utf8 print('《app.py》返回json==jsonStr=====', json_str) return json_str
def login(username_front, passwd_front): #前台传参数 # json数据 data = {} # 要返回的数据 code = 500 # 返回给调用者的值,默认是500 Number类型的 msg = '登录失败' count = 0 userlevel = 2 # 普通用户 login_sql_return_json_data = list() if username_front is not None and passwd_front is not None: print('==登录==,前台传的-username====', username_front) print('==登录==,前台传的-password====', passwd_front) print('此用户不存在,可登录,严重密码是否正确') # 1. 加密passwd md5_passwd = utils.get_md5(passwd_front) print('c_acount 转移出来的md5=', md5_passwd) """ sql字段: userid: int username: str password: str user_remark: str user_email: str user_level: int (1-管理员 2 普通用户) create_time: date (2020-01-01这种格式) session: str """ #获取json数据 jsonloads json -> 字典 login_return_json = dbutils.login(username_front, md5_passwd) print('dbutil 执行返回结果=======', login_return_json) # 获取json后需要loads一下,转成字典形式 login_return_json_loads = json.loads(login_return_json) #判断系统是否有此账号username if login_return_json_loads['code'] == 200: print('登录成功') code = login_return_json_loads['code'] msg = login_return_json_loads['msg'] count = login_return_json_loads['count'] print('<c_account>=====json返回的data 类型是==《list》', type(login_return_json_loads['data'])) login_sql_return_json_data = login_return_json_loads['data'] # 获取用户权限 sql = 'select roleId from bugcount.user where username = %s' userlevel_tuple = dbutils.execute_onesql_returnint(sql, username_front) userlevel = userlevel_tuple[0] else: print('用户名或密码为空,不做操作') # 返回json格式的数据 data['code'] = code data['msg'] = msg data['count'] = count data['data'] = login_sql_return_json_data data['userlevel'] = userlevel # 转化下查询结果为{},{},{}这种格式====================== json_str = json.dumps(data, ensure_ascii=False) print('《c_account》返回json==jsonStr=====', json_str) return json_str
def register(username_front, passwd_front): #前台传参数 # json数据 data = {} # 要返回的数据 code = 500 # 返回给调用者的值,默认是500 Number类型的 msg = '注册失败' count = 0 regiser_sql_return_json_data = list() if username_front is not None and passwd_front is not None: print('==注册==,前台传的-username====', username_front) print('==注册==,前台传的-password====', passwd_front) # 查询数据是否有次username check_user_result_json = dbutils.check_username_is_registered( username_front) print('<dbutil查询回来josn==>', check_user_result_json) print('<dbutil查询回来josn==type ==>', type(check_user_result_json)) # 获取查询到的个数,传的json全部都是字符串 check_user_result_json_loads = json.loads(check_user_result_json) print('<c_account>?????????????????????josn count type = ', check_user_result_json_loads['count']) check_user_result_json_count = check_user_result_json_loads['count'] if check_user_result_json_count > 0: print('此用户已存在') msg = '此用户已存在' else: print('此用户不存在') # 1. 加密passwd md5_passwd = utils.get_md5(passwd_front) """ sql字段: userid: int username: str password: str user_remark: str user_email: str user_level: int (1-管理员 2 普通用户) create_time: date (2020-01-01这种格式) session: str """ # 2. 加密结果存储 # insert_passwd_sql = 'insert into bugcount.user values(null, %s, %s, null, null, null, null, null)' # insert_passwd_sql = 'select username from bugcount.user where username =%s' # 查看是否注册成功 # 返回值为list 0位状态码 1位sql结果个数 2位为查询结果 register_return_json = dbutils.register(username_front, md5_passwd) print('dbutil 执行返回结果=======', register_return_json) # 获取json后需要loads一下,转成字典形式 register_return_json_loads = json.loads(register_return_json) #判断系统是否有此账号username if register_return_json_loads['code'] == 200: print('注册成功') code = register_return_json_loads['code'] msg = '注册成功' count = register_return_json_loads['count'] print('<c_account>=====json返回的data 类型是==《list》', type(register_return_json_loads['data'])) regiser_sql_return_json_data = register_return_json_loads[ 'data'] else: print('用户名或密码为空,不做操作') # 返回json格式的数据 data['code'] = code data['msg'] = msg data['count'] = count data['data'] = regiser_sql_return_json_data # 转化下查询结果为{},{},{}这种格式====================== json_str = json.dumps(data, ensure_ascii=False) print('《c_account》返回json==jsonStr=====', json_str) return json_str