def upload_img(): if PARAM_IMG not in request.files: return get_response(error_code=ERROR_MISS_IMG, message='img should not be null') return get_response(message='upload img success', data=get_config().CDN_SERVER)
def forget_pass(): # 忘记密码 data = get_json_data() res = User.forget_password(data[PARAM_ACCOUNT], data[PARAM_PASSWORD], data[PARAM_NEW_PASSWORD]) if not res: return get_response(message='账号或者密码有误,请检查后再输入', error_code=ERROR_ACCOUNT_NOT_EXIST) return get_response(message='修改成功')
def all_device(permission): user = g.user if user.character != 4 and not get_json_data().get(PARAM_UID, 0): return get_response('ok', data=Device.get_all_device( get_json_data().get(PARAM_UID, user.id), 1)) return get_response('ok', data=Device.get_all_device(get_json_data().get( PARAM_UID, user.id)))
def get_user(permission): user = g.user uid = get_json_data().get(PARAM_ID, 0) if uid: u = User.query.filter(User.id == uid).first() if u and ((user.character == 1 and u.factory_id == user.id) or (user.character == 2 and u.agent_id == user.id) or (user.character == 3 and u.ser_acc_id == user.id)): return get_response(message='ok', data=u.get_user_info()) return get_response(message='没有权限查看', error_code=ERROR_GET_USER) return get_response(message='ok', data=user.get_user_info())
def login(): data = get_json_data() user = User.query.filter(User.account == data[PARAM_ACCOUNT]).first() if not user: return get_response(message='账号有误,请检查后再输入', error_code=ERROR_ACCOUNT_NOT_EXIST) if not user.verify_pwd(data[PARAM_PASSWORD]): return get_response(message='密码有误,请检查后再输入', error_code=ERROR_PASSWORD) print(user.get_user_info()) return get_response(message='登录成功', data=user.get_user_info())
def notice_list(permission): data = get_json_data() return get_response('ok', data=g.user.get_user_list(permission, 0, r=data.get(PARAM_REMOVE, 0), p=data.get(PARAM_REPAIR, 0)))
def del_user(permission): data = get_json_data() user = User.query.filter(User.id == data[PARAM_ID]).first() user.will_remove = True db.session.query(User).filter(User.id == user.factory_id).update( {User.notice: True}) db.session.commit() return get_response('ok')
def upper_info(permission): user = g.user if user.character == 4: uid = user.ser_acc_id elif user.character == 3: uid = user.agent_id else: uid = user.factory_id u_user = User.query.filter(User.id == uid).first() return get_response(message='ok', data=u_user.get_user_info())
def agree_del(permission): data = get_json_data() user = User.query.filter(User.id == data[PARAM_ID]).first() if not PARAM_REJECT: db.session.delete(user) else: user.will_remove = False if not db.session.query.filter( User.id).filter(User.will_remove == True).first(): db.session.query(User).filter(User.id == user.factory_id).update( {User.notice: False}) db.session.commit() return get_response('ok')
def create_user(permission): data = get_json_data() user = g.user print(user) print(permission) factory_id = user.id if user.character == 1 else user.factory_id agent_id = user.id if user.character == 2 else user.agent_id s_id = user.id if user.character == 3 else user.ser_acc_id character = user.character + 1 uid = User.create_user(data[PARAM_NAME], data[PARAM_PHONE], data[PARAM_ADDRESS], character, data[PARAM_PROVINCE], data[PARAM_CITY], data[PARAM_AREA], factory_id, agent_id, s_id) if character == 4: # print(data[PARAM_IMAGES]) Device.create_device(data[PARAM_DEVICE_TYPE], data[PARAM_DEVICE_ID], data[PARAM_AMOUNT], data[PARAM_DATE], data[PARAM_IMAGE1], data[PARAM_IMAGE2], data[PARAM_IMAGE3], data[PARAM_TYPE], uid) return get_response('ok')
def get_user_list(permission): data = get_json_data() uid = request.args.get(PARAM_ID, 0) print('data', data, request.method) return get_response(message='ok', data=g.user.get_user_list(permission, data))
def broken(permission): Device.device_broken(get_json_data()[PARAM_ID]) return get_response('ok')