def mobile_code_get(): try: req = ParamAuthMobileCodeSchema().load(request.args) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) try: code = login_usecase.send_login_code(req.mobile) except exception.LoginException as exc: return jsonify(ErrorResponse(exc.error, data=str(exc))) # White list for debug user. if req.mobile in WHITE_LIST: status = login_usecase.get_login_code_status(req.mobile) bearychat = "https://hook.bearychat.com/=bwD6u/incoming/38e28a304b97b7b67335c3be1cb2fe81" msg = "{} 码 {}\n1小时内发送次数 {}".format(req.mobile, code, status["counter"]) requests.post(bearychat, json={"text": msg}) current_app.logger.warning("mobile_code_get:{}:{}".format( req.mobile, code)) return jsonify( OKResponse({ "mobile": req.mobile, "code": None, "retry_time": None # 暂时没有显示发送次数的需求 }))
def mobile_login(): try: req = AuthMobileLoginRequestSchema().load(request.json) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) if not login_usecase.verify_login_code(req.mobile, req.password): return jsonify(ErrorResponse(error.InvalidLoginCode)) m_user, m_user_info = login_usecase.signup_user(g.db, req.mobile, MOBILE_CODE_CHINA, req.child_info) if not m_user: return jsonify(ErrorResponse(error.LoginFailed)) if m_user.status != UserStatus.Normal.value: return jsonify(ErrorResponse(error.UserIsBanned)) token = create_token(request.headers["did"], m_user.id) current_app.logger.warning("mobile_login:{}:{}:{}".format( m_user.id, m_user.mobile, token)) return jsonify( OKResponse({ "user_id": m_user.id, "token": token, "relation": m_user_info.child_relation }))
def hot_carers(): try: req = ParamRecommendCarerHotSchema().load(request.args) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) if req.city_id: req.city_id = (req.city_id // 100) * 100 # 参考GB码 -> 市GB码 if req.lat and req.lng and req.city_id: hot_carer_ids = recommend_usecase.retrieve_hot_carer_id_list( g.db, EntityFacade.redis_cli, req.city_id, req.lat, req.lng, req.offset, req.limit ) else: # TODO: KOL CITY_ID_BEIJINT = 110100 hot_carer_ids = recommend_usecase.retrieve_hot_carer_id_list( g.db, EntityFacade.redis_cli, CITY_ID_BEIJINT, req.lat, req.lng, req.offset, req.limit ) current_app.logger.warning(hot_carer_ids) carers = [] for id_ in hot_carer_ids: c = _build_recommend_carer_info(id_, req.city_id, req.lat, req.lng) if not c: current_app.logger.warning("invalid user id: %s", id_) continue carers.append(c) data = RecommendCarerResponseDataItemSchema(many=True).dump(carers) return jsonify(OKResponse(data))
def carer_apply_result(): application = carer_usecase.retrieve_carer_application( g.db, request.current_user_id, detail=False) if not application: result = dict(status=-1, reason=CARER_APPLY_REJECT_REASON.get(-1, "")) else: result = dict(status=application.status, reason=CARER_APPLY_REJECT_REASON.get( application.result, "")) return jsonify(OKResponse(result))
def guardian_get(): orm_guardians = guardian_usecase.retrieve_guardians_by_user_id( g.db, request.current_user_id) result = [ dict(id=guardian.id, id_card_no=obscure_id_card_no(guardian.id_card_no), realname=guardian.realname, mobile=obscure_mobile_no(guardian.mobile)) for guardian in orm_guardians ] return jsonify(OKResponse(result))
def following(): try: req = ParamUserFollowingSchema().load(request.args) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) following_user_infos = social_usecase.retrieve_user_following( g.db, request.current_user_id, req.offset, req.limit) data = UserFollowingItemSchema(many=True).dump(following_user_infos) return jsonify(OKResponse(data))
def profile(): balance = 0 wallet = point.find_user_wallet(g.db, request.current_user_id) if wallet: balance = wallet.balance if wallet.balance else 0 profile = dict(point_balance=balance, point_notification_count=0, order_notification_count=0) data = UserProfileSchema().dump(profile) return jsonify(OKResponse(data))
def upload_done(): try: req = UserUploadDoneRequestSchema().load(request.json) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) if req['category'] == 'video': pass result = {} resp = OKResponse(result) return jsonify(resp)
def carer_apply_get(): application = carer_usecase.retrieve_carer_application( g.db, request.current_user_id) if not application: # 如果没有申请记录 返回实名认证结果 identify_result = identity_usecase.is_user_identity_verified( g.db, request.current_user_id) return jsonify( ErrorResponse(error.NonExistentCarerApplication, data=dict(identify_result=identify_result))) application.result = CARER_APPLY_REJECT_REASON.get(application.result, "") result = CarerApplicationDataSchema().dump(application) return jsonify(OKResponse(result))
def identify_liveness_post(): try: req = UserIdentifyLivenessRequestSchema().load(request.json) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) result = identity_usecase.identify_liveness( g.db, request.current_user_id, req.liveness_id, req.id_card_no, req.realname, req.idcard_image, req.live_image, req.info ) resp = OKResponse({'result': result}) return jsonify(resp)
def guardian_post(): try: req = CreateGuardianRequestDataSchema().load(request.json) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) try: result = guardian_usecase.create_guardian(g.db, request.current_user_id, req.id_card_no, req.realname, req.mobile) except exception.UserException as exc: return jsonify(ErrorResponse(exc.error, data=str(exc))) return jsonify(OKResponse({"id": result.id}))
def child_me_post(): try: req = UserChildUpdateDataSchema().load(request.json) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) user_id = request.current_user_id try: result = child_usecase.create_or_update_child(g.db, user_id, req.id, req.id_card_no, req.realname, req.nickname) return jsonify(OKResponse({"id": result})) except exception.UserException as exc: return jsonify(ErrorResponse(exc.error, data=str(exc)))
def info_me_post(): try: req = UserInfoUpdateRequestSchema().load(request.json) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) try: result = user_info_usecase.update_user_info( g.db, request.current_user_id, req.id_card_no, req.realname, req.mobile, req.child_relation, req.avatar ) return jsonify(OKResponse(result)) except exception.UserException as exc: return jsonify(ErrorResponse(exc.error, data=str(exc)))
def carer_info(): try: req = ParamUserCarerInfoSchema().load(request.args) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) target_user_id = req.user_id user_info = user_info_usecase.retrieve_user_info(g.db, target_user_id) if not user_info: return jsonify(ErrorResponse(error.NonExistentUser)) carer_info = carer_usecase.retrieve_care_info(g.db, target_user_id) if not carer_info: return jsonify(ErrorResponse(error.NonExistentCarer)) # Nickname carer_info.nickname = user_info.nickname # Videos carer_info.videos = carer_usecase.videos_dict_to_list(carer_info.videos) # Distance distance = 0 if req.lat and req.lng and carer_info.address.lat and carer_info.address.lng: distance = lbs.distance_m( (req.lat, req.lng), (carer_info.address.lat, carer_info.address.lng)) carer_info['distance'] = distance_display(distance) # Degree carer_info.degree = DEGREE_INT2CN[carer_info.degree] # Like & Follow social_info = social_usecase.retrieve_user_social(g.db, request.current_user_id, target_user_id) carer_info.update(social_info) result = CarerInfoGetResponseDataSchema().dump(carer_info) resp = OKResponse(result) return jsonify(resp)
def preset_user_info(): try: req = UserInfoPresetRequestSchema().load(request.json) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) try: result = user_info_usecase.store_preset_user_info( g.db, request.current_user_id, req.born, req.nickname, req.relation, req.birth_ts, req.gender ) return jsonify(OKResponse(result)) except exception.UserException as exc: return jsonify(ErrorResponse(exc.error, data=str(exc)))
def child_me_delete(): try: req = UserChildDeleteRequestSchema().load(request.json) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) user_id = request.current_user_id result = child_usecase.delete_child(g.db, user_id, int(req.id)) if not result: return jsonify( ErrorResponse(error.InvalidParameter, data={ "action": "delete_last_child", "id": req.id })) resp = OKResponse(result) return jsonify(resp)
def info_me_get(): user_info = user_info_usecase.retrieve_user_info(g.db, request.current_user_id) if not user_info: return jsonify(ErrorResponse(error.InvalidParameter)) # Resolve `is_carer` carer_info = carer_usecase.retrieve_care_info(g.db, request.current_user_id) user_info.is_carer = carer_info is not None # Resolve `children_nicknames` children = child_usecase.retrieve_children_by_user_id(g.db, request.current_user_id) children_nicknames = [c.nickname for c in children] user_info.children_nicknames = children_nicknames # Resolve ui text if user_info.mobile: user_info.mobile = obscure_mobile_no(user_info.mobile) if user_info.id_card_no: user_info.id_card_no = obscure_id_card_no(user_info.id_card_no) if user_info.degree is not None: user_info.degree = DEGREE_INT2CN[user_info.degree] if user_info.child_relation is not None: user_info.child_relation = CHILD_RELATION_INT2CN[user_info.child_relation] if user_info.avatar_oss: user_info.avatar_url = qiniu.url_from_path(user_info.avatar_oss) if user_info.realname: user_info.realname = user_info.realname # Resolve `carer_apply_status` carer_application = carer_usecase.retrieve_carer_application( g.db, request.current_user_id ) if not carer_application: user_info.carer_apply_status = CarerApplicationStatus.NotSubmitted.value else: user_info.carer_apply_status = carer_application.status data = UserInfoSchema().dump(user_info) resp = OKResponse(data) return jsonify(resp)
def carer_apply_post(): try: req = CarerApplyRequestDataSchema().load(request.json) except marshmallow.ValidationError as err: return jsonify(ErrorResponse(error.InvalidParameter, data=err.messages)) try: result = carer_usecase.submit_carer_application( g.db, request.current_user_id, req) # TODO: Review carer application # carer_usecase.approve_carer_application( # g.db, request.current_user_id # ) except exception.CarerApplicationException as exc: return jsonify(ErrorResponse(exc.error, data=str(exc))) result = dict(qr=CARER_APPLY_QR_CODE_IMAGE_URL, wx_id=CARER_APPLY_WX_ID) return jsonify(OKResponse(result))
def child_me_get(): result = child_usecase.retrieve_children_by_user_id( g.db, request.current_user_id) data = ChildSchema(many=True).dump(result) resp = OKResponse(data) return jsonify(resp)
async def logout(): return jsonify(OKResponse(None))
def identify_liveness_get(): result = identity_usecase.is_user_identity_verified(g.db, request.current_user_id) resp = OKResponse({'result': result}) return jsonify(resp)