def user_regist(): """ 用户注册 :arg {"username":"******", "password":"******", "nickname":"nickname"} :return json """ user_info = request.get_json() nickname = user_info.get("nickname") username = user_info.get("username") password = user_info.get("password") create_date = get_current_time() # 参数校验 if not _parameters_filter([username, password, nickname]): return json(get_json(code=-200, msg="参数存在空值,请检查参数!")) # 判断用户名是否已被占用 query_user_sql = "select * from t_user where username='******'" % username if query(query_user_sql): return json(get_json(code=-300, msg="用户名已存在!")) # 没被占用,进行注册 user_reg_sql = "insert into t_user values(NULL, '%s', '%s', '%s'," \ "NULL, 1,'','','',NULL,'','','','',NULL,'','%s',NULL)" % (username, password, nickname, create_date) if excute(user_reg_sql): return json(get_json(msg="注册成功!")) return get_json(code=-100, msg="注册失败,用户名可能已经存在了!")
def adminlogin(): ''' 管理员登陆 arg:{"username":"******","password":"******"} return: json ''' admininfo = request.get_json() username = admininfo["username"] password = admininfo["password"] if username != None and password != None: result = query( "SELECT * FROM tbl_admin where username = '******' and password = '******';" % (username, password)) if result: token = create_token() result[0]["token"] = token _set_admin_session(result[0]) excute( "UPDATE `tbl_admin` SET `token`='%s' WHERE (`id`='%d') LIMIT 1" % (token, result[0].get("id"))) return get_json(code=200, data={"token": token}, msg="登陆成功!") else: return get_json(code=200, data={"token": 0}, msg="账号或者密码错误!") else: return get_json(code=200, data={"token": 0}, msg="账号或者密码不能为空!")
def wrapper(*args, **kwargs): token = request.get_json().get("token") if token is not None and token != ""\ and token == session.get("user_token"): try: return func(*args, **kwargs) except: print(traceback.print_exc()) return json(get_json(code=500, msg="内部错误,请检查参数是否正确!")) return get_json(code=-300, msg="权限错误,请先登录!")
def logout(): # 如果会话中有用户名就删除它。 # 同时从客户端浏览器中删除 session的 name属性 session.pop('token', None) session.pop('admin', None) return get_json(code=200, data={"token": 1}, msg="退出登陆!")
def user_login(): """ 用户登录 :arg {"username":"******", "password":"******", "captcha":"123456"} :return json """ user_info = request.get_json() captcha = user_info.get("captcha") username = user_info.get("username") password = user_info.get("password") # 参数校验 if not _parameters_filter([username, password, captcha]): return json(get_json(code=-200, msg="参数存在空值,请检查参数!")) # 如果没有获取验证码接口,则指定默认的9527为默认验证码,方便接口测试 user_captcha = session.get("captcha") if captcha is None or captcha == "": user_captcha = "9527" if "9527" == captcha: query_login_sql = "select * from t_user where username='******' and password='******'" % (username, password) result = query(query_login_sql) if result: if 1 == 1: # 生成并插入token user_token = create_token() insert_token_sql = "update t_user set token='%s' where id=%d" % (user_token, result[0]["id"]) excute(insert_token_sql) # 查询IMG并更新Token try: query_img_sql = "select * from tbl_image_sources where id=%d" % result[0].get("imgId") result[0]["img"] = query(query_img_sql)[0].get("path") except: result[0]["img"] = "" result[0]["token"] = user_token # 保存用户信息 _set_user_session(result[0]) return get_json(data={"token": user_token}, msg="登录成功!") else: return get_json(msg="登录失败, 您已经禁止登陆网站, 请联系管理员处理!") return get_json(code="-100", msg="登录失败,用户名或密码不正确!")
def user_logout(): """ 用户退出,删除session :arg {"token":"xxxxx"} :return: """ session.pop("user", None) session.pop("user_token", None) return get_json()
URL_BD: str = config('url_bd', cast=str) database = Database(URL_BD, min_size=1, max_size=5) metadata = sqlalchemy.MetaData() tb_name_brest_dirty: str = "bus_stop_dirty_brest" tb_name_brest_clean: str = "bus_stop_clean_brest" tb_name_gomel_dirty: str = "bus_stop_dirty_gomel" tb_name_gomel_clean: str = "bus_stop_clean_gomel" tb_name_grodno_dirty: str = "bus_stop_dirty_grodno" tb_name_grodno_clean: str = "bus_stop_clean_grodno" # TEMPLATES templates = Jinja2Templates(directory="app/templates") # JSON path_to_json = 'app/configuration/json' stop_bus_brest: list = get_json(f'{path_to_json}/stopbus_brest.json') stop_bus_gomel: list = get_json(f'{path_to_json}/stopbus_gomel.json') stop_bus_grodno: list = get_json(f'{path_to_json}/stopbus_grodno.json') brestbus_stop: dict = get_json(f'{path_to_json}/busstop_brest.json') gomelbus_stop: dict = get_json(f'{path_to_json}/busstop_gomel.json') grodnobus_stop: dict = get_json(f'{path_to_json}/busstop_grodno.json') trolleybusesstop_brest: dict = get_json( f'{path_to_json}/trolleybusesstop_brest.json') trolleybusesstop_gomel: dict = get_json( f'{path_to_json}/trolleybusesstop_gomel.json') trolleybusesstop_grodno: dict = get_json( f'{path_to_json}/trolleybusesstop_grodno.json') # SORTING OPTIONS