Exemple #1
0
    def post(self):
        user_log.info("BindPhoneHandler.")
        
        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["phone"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            user_log.error("Bind phone protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        phone = req_json["phone"]
        acc_id = self.get_current_user()

        if True != dao.bindPhone(acc_id, phone):
            user_log.error("Bind phone failed! Account id: %s, Phone: %s", acc_id, phone)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_BIND_PHONE_FAILED 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return
            
        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #2
0
    def post(self):
        user_log.info("LoginHandler POST.")

        request = HTTPRequest(CONFIG.AUTH_URL, "POST", body=self.request.body)
        http = AsyncHTTPClient()
        response = yield http.fetch(request)
        rep_json = json.loads(response.body)
        err = rep_json["err"]
        if FD_AUTH_NOERR != err:
            body = {}
            body["err"] = FD_ERR_USER_LOGIN_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(body))
            return

        acc_id = rep_json["accID"]
        self.set_secure_cookie("id", str(acc_id))
        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        cur_login_dev = req_json["dev"]

        last_login_dev = dao.recordLoginDevice(acc_id, cur_login_dev)

        body = {}
        body["err"] = FD_USER_NOERR
        body["accID"] = acc_id
        body["dev"] = last_login_dev
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(body))
        return
Exemple #3
0
    def get(self):
        user_log.info("QueryUserInfoHandler GET.")

        user_id_list = self.get_arguments("uid")
        if not user_id_list:
            user_log.error("Query user info list protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        user_info_list = dao_friend.queryUserInfoList(user_id_list)
        if user_info_list is None:
            user_log.error("Query user info list failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_USER_INFO_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["userList"] = user_info_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #4
0
    def get(self):
        user_log.info("QueryFriendInfoHandler GET.")

        frd_id_list = self.get_arguments("uid")
        if not frd_id_list:
            user_log.error("Query friend info list protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        user_id = self.get_current_user()

        frd_list = dao_friend.queryFriendInfoList(user_id, frd_id_list)
        if frd_list is None:
            user_log.error("Query friend info list failed! Friend id list: %s", frd_id_list)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_FRIEND_ID_LIST_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["frdList"] = frd_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #5
0
    def get(self):
        user_log.info("QueryLatestVersionHandler GET.")

        system = self.get_argument("sys", None)
        if system is None:
            user_log.error("Query latest version protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        version = dao.queryLatestVersion(system)
        if version is None:
            user_log.error("Query latest version failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_LATEST_VERSION_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["version"] = version
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #6
0
    def get(self):
        user_log.info("QueryFriendFavoriteGoodsHandler GET.")

        frd_id = self.get_argument("uid", None)
        offset = self.get_argument("offset", None)
        count = self.get_argument("count", None)
        if frd_id is None or offset is None or count is None:
            user_log.error("Query friend favorite goods protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        user_id = self.get_current_user()

        goods_list = dao_shop.queryFriendFavoriteGoods(int(user_id), int(frd_id), int(offset), int(count))
        if goods_list is None:
            user_log.error("Query friend favorite goods failed! User id: %s, friend id: %s", user_id, frd_id)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_FRIEND_FAVORITE_GOODS_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["goodsList"] = goods_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #7
0
    def get(self):
        user_log.info("QueryShopCurrentCustomerHandler GET.")

        shop_id = self.get_argument("sid", None)
        if shop_id is None:
            user_log.error("Query shop current customer count protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        url = CONFIG.FD_CHAT_SERVER + "/chat/shop/" + str(shop_id) + "/userstotalnum"
        request = HTTPRequest(url, "GET")
        http = AsyncHTTPClient()
        response = yield http.fetch(request)
        rep_json = json.loads(response.body)
        is_success = rep_json["is_success"]
        if is_success:
            customer_count = rep_json["total_num"]
            rep_json = {}
            rep_json["err"] = FD_USER_NOERR
            rep_json["count"] = customer_count
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return
        else:
            user_log.error("Query shop current customer count failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_SHOP_CUSTOMER_COUNT_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return
Exemple #8
0
    def post(self):
        user_log.info("FeedbackHandler POST.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["feedback"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            req_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(req_json, cls=ExtendedJsonEncoder))
            return

        feedback = req_json["feedback"]

        user_id = self.get_current_user()

        if True != dao.feedback(user_id, feedback):
            user_log.error("Feedback failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_FEEDBACK_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #9
0
    def post(self):
        user_log.info("AddressDefaultSettingHandler.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["addrID"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            user_log.error("Bind phone protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        addr_id = req_json["addrID"]
        user_id = self.get_current_user()

        if True != dao.setDefaultAddress(user_id, addr_id):
            user_log.error("Bind phone failed! Account id: %s, Phone: %s", acc_id, phone)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_SET_DEFAULT_ADDRESS_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #10
0
    def get(self):
        user_log.info("QueryShopNameHandler GET.")

        shop_id = self.get_argument("sid", None)
        if shop_id is None:
            user_log.error("Query shop name protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        shop_name = dao.queryShopName(shop_id)
        if shop_name is None:
            user_log.error("Query shop name failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_SHOP_NAME_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["shopName"] = shop_name
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #11
0
    def post(self):
        user_log.info("BindPhoneHandler.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["phone"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            user_log.error("Bind phone protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        phone = req_json["phone"]
        acc_id = self.get_current_user()

        if True != dao.bindPhone(acc_id, phone):
            user_log.error("Bind phone failed! Account id: %s, Phone: %s", acc_id, phone)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_BIND_PHONE_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #12
0
    def post(self):
        user_log.info("MessageSettingHandler POST.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["shopID", "msgEnable"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            req_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(req_json, cls=ExtendedJsonEncoder))
            return

        shop_id = req_json["shopID"]
        msg_enable = req_json["msgEnable"]

        user_id = self.get_current_user()

        if True != dao.modifyMessageSetting(user_id, shop_id, msg_enable):
            user_log.error("Modify message setting failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_MODIFY_MESSAGE_SETTING_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #13
0
    def post(self):
        user_log.info("PrivateSettingHandler POST.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["favoriteEnable", "fansEnable", "visitEnable"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            req_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(req_json, cls=ExtendedJsonEncoder))
            return

        favorite_enable = req_json["favoriteEnable"]
        fans_enable = req_json["fansEnable"]
        visit_enable = req_json["visitEnable"]

        user_id = self.get_current_user()

        if True != dao.modifyPrivateSetting(user_id, favorite_enable,
                                            fans_enable, visit_enable):
            user_log.error("Modify private setting failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_MODIFY_PRIVATE_SETTING_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #14
0
    def delete(self):
        user_log.info("ConcerShopHandler DELETE.")

        shop_id = self.get_argument("sid")
        if shop_id is None:
            rep_json = {}
            user_log.error("Unconcern shop protocol data error!")
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        user_id = self.get_current_user()

        if True != dao.concernShop(user_id, shop_id, FD_UNCONCERN):
            user_log.error("Unconcer shop failed! User id: %s, shop id: %s", user_id, shop_id)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_UNCONCERN_SHOP_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return 
Exemple #15
0
    def get(self):
        user_log.info("QueryGoodsByShopHandler GET.")

        shop_id = self.get_argument("sid", None)
        offset = self.get_argument("offset", None)
        count = self.get_argument("count", None)
        if shop_id is None or offset is None or count is None:
            user_log.error("Query goods by shop protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        goods_list = dao.queryGoodsByPage(int(shop_id), int(offset), int(count))
        if goods_list is None:
            user_log.error("Query goods by page failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_GOODS_BY_PAGE_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["goodsList"] = goods_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #16
0
    def get(self):
        user_log.info("QueryFansShopNewsHandler POST.")

        fans_shop_id_list = self.get_arguments("sid")
        if not fans_shop_id_list:
            rep_json = {}
            user_log.error("Query fans shop news protocol data error!")
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        fans_shop_list = dao.queryFansShopNewsList(fans_shop_id_list)
        if fans_shop_list is None:
            user_log.error("Query fans shop news list failed! Shop id list: %s", fans_shop_id_list)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_FANS_SHOP_NEWS_LIST_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["shopList"] = fans_shop_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #17
0
    def get(self):
        user_log.info("QueryActivityByShopHandler GET.")

        shop_id = self.get_argument("sid", None)
        if shop_id is None:
            user_log.error("Query shop activity protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        act_list = dao.queryActivityByShop(shop_id)
        if act_list is None:
            user_log.error("Query shop activity list failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_ACTIVITY_BY_SHOP_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["actList"] = act_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #18
0
    def post(self):
        user_log.info("PrivateSettingHandler POST.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["favoriteEnable", "fansEnable", "visitEnable"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            req_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(req_json, cls=ExtendedJsonEncoder))
            return

        favorite_enable = req_json["favoriteEnable"]
        fans_enable = req_json["fansEnable"]
        visit_enable = req_json["visitEnable"]

        user_id = self.get_current_user()

        if True != dao.modifyPrivateSetting(user_id, favorite_enable, fans_enable, visit_enable):
            user_log.error("Modify private setting failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_MODIFY_PRIVATE_SETTING_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #19
0
    def get(self):
        user_log.info("QueryActivitiesHandler GET.")

        city_id = int(self.get_argument("city"))
        offset = int(self.get_argument("offset"))
        count = int(self.get_argument("count"))
        if city_id is None or offset is None or count is None:
            user_log.error("Query activities protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        act_list = dao.queryActivities(city_id, offset, count)
        if act_list is None:
            user_log.error("Query activities failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_ACTIVITIES_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["actList"] = act_list
        rep_json["count"] = dao.queryActivityNum(city_id)
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #20
0
    def get(self):
        user_log.info("QueryFriendPrivateSettingHandler GET.")

        frd_id = self.get_argument("uid", None)
        if frd_id is None:
            user_log.error("Query friend private setting protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        user_id = self.get_current_user()

        setting = dao_friend.queryFriendPrivateSetting(user_id, frd_id)
        if setting is None:
            user_log.error("Query friend private setting failed! User id: %s, friend id: %s", user_id, frd_id)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_FRIEND_PRIVATE_SETTING_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["setting"] = setting
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #21
0
    def get(self):
        user_log.info("QueryRecommendHandler GET.")

        city_id = self.get_argument("city", None)
        if city_id is None or city_id < 0:
            user_log.error("Query recommend shop protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        shop_list = dao.queryRecommendShops(city_id)
        if shop_list is None:
            user_log.error("Query recommend shop failed! City ID: %s", city_id)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_RECOMMEND_SHOP_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["shopList"] = shop_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #22
0
    def get(self):
        user_log.info("QueryFriendVisitedShopHandler GET.")

        frd_id = self.get_argument("uid", None)
        offset = self.get_argument("offset", None)
        count = self.get_argument("count", None)
        if frd_id is None or offset is None or count is None:
            user_log.error("Query friend fans shop protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        user_id = self.get_current_user()

        shop_list = dao_shop.queryFriendVisitedShop(int(user_id), int(frd_id), int(offset), int(count))
        if shop_list is None:
            user_log.error("Query friend visited shop failed! User id: %s, friend id: %s", user_id, frd_id)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_FRIEND_VISITED_SHOP_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["shopList"] = shop_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #23
0
    def get(self):
        user_log.info("QueryGoodsDetailHandler GET.")

        goods_id = self.get_argument("gid", None)
        bar_code = self.get_argument("barcode", None)
        if goods_id is None:
            user_log.error("Query goods detail protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        goods = dao.queryGoodsDetail(goods_id, bar_code)
        if goods is None:
            user_log.error("Query goods detail failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_GOODS_DETAIL_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["info"] = goods
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #24
0
    def get(self):
        user_log.info("QueryUserFFVCountHandler GET.")

        user_id = self.get_argument("uid", None)
        if user_id is None:
            user_log.error("Query user ffv count protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        ffv_count = dao_friend.queryUserFFVCount(user_id)
        if ffv_count is None:
            user_log.error("Query user ffv count failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_USER_FFV_COUNT_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["ffvCount"] = ffv_count
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #25
0
    def get(self):
        user_log.info("QueryCustomerFittingHandler GET.")

        goods_id = self.get_argument("gid", None)
        offset = self.get_argument("offset", None)
        count = self.get_argument("count", None)
        if goods_id is None or offset is None or count is None:
            user_log.error("Query goods customer fitting protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        pic_list = dao.queryGoodsFitting(int(goods_id), int(offset), int(count))
        if pic_list is None:
            user_log.error("Query goods fitting picture list failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_GOODS_FITTING_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["picList"] = pic_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #26
0
    def delete(self):
        user_log.info("AddressHandler DELETE.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["addrID"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            user_log.error("Modify address info protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        addr_id = req_json["addrID"]
        
        acc_id = self.get_current_user()

        if True != dao.deleteAddress(acc_id, addr_id):
            user_log.error("Delete address info failed! Account id: %s", acc_id)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_DELETE_ADDRESS_INFO_FAILED 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return
            
        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #27
0
    def put(self):
        user_log.info("CustomerFittingHandler PUT.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["goodsID", "picURL"]
        optional_args = ["description"]
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            user_log.error("Add customer fitting picture protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        goods_id = req_json["goodsID"]
        pic_url = req_json["picURL"]
        description = req_json["description"]

        acc_id = self.get_current_user()

        if True != dao.addCustomerFitting(acc_id, goods_id, pic_url, description):
            user_log.error("Add customer fitting picture failed! Account id: %s", acc_id)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_ADD_CUSTOMER_FITTING_PICTURE_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #28
0
    def post(self):
        user_log.info("AddressDefaultSettingHandler.")
        
        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["addrID"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            user_log.error("Bind phone protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        addr_id = req_json["addrID"]
        user_id = self.get_current_user()

        if True != dao.setDefaultAddress(user_id, addr_id):
            user_log.error("Bind phone failed! Account id: %s, Phone: %s", acc_id, phone)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_SET_DEFAULT_ADDRESS_FAILED 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return
            
        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #29
0
    def get(self):
        user_log.info("QueryVisitedShopsHandler GET.")

        time = self.get_argument("time", None)
        direct = self.get_argument("direct", None)
        count = self.get_argument("count", None)
        if time is None or count is None:
            user_log.error("Query goods customer fitting protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        visit_time = datetime.datetime.fromtimestamp(int(time))
        user_id = self.get_current_user()

        shop_list = dao.queryVisitedShops(user_id, visit_time, int(direct), int(count))
        if shop_list is None:
            user_log.error("Query visited shop list failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_VISITED_SHOPS_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["shopList"] = shop_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #30
0
    def post(self):
        user_log.info("ResetPasswordHandler POST.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["phone", "password"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            user_log.error("Reset password protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        phone = req_json["phone"]
        password = req_json["password"]

        if True != dao.resetPassword(phone, password):
            user_log.error("Reset password failed! Phone: %s", phone)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_RESET_PASSWORD_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #31
0
    def post(self):
        user_log.info("LoginHandler POST.")

        request = HTTPRequest(CONFIG.AUTH_URL, "POST", body=self.request.body)
        http = AsyncHTTPClient()
        response = yield http.fetch(request)
        rep_json = json.loads(response.body)
        err = rep_json["err"]
        if FD_AUTH_NOERR != err:
            body = {}
            body["err"] = FD_ERR_USER_LOGIN_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(body))
            return

        acc_id = rep_json["accID"]
        self.set_secure_cookie("id", str(acc_id))
        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        cur_login_dev = req_json["dev"]

        last_login_dev = dao.recordLoginDevice(acc_id, cur_login_dev)

        body = {}
        body["err"] = FD_USER_NOERR
        body["accID"] = acc_id
        body["dev"] = last_login_dev
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(body))
        return
Exemple #32
0
    def post(self):
        user_log.info("QueryFansShopDifferenceHandler POST.")

        front_fans_id_list = self.arg.shopIDs
        user_id = self.get_current_user()

        end_fans_id_list = dao.queryFansShopIDList(user_id)
        if end_fans_id_list is None:
            user_log.error("Query fans shop id list failed! User id: %s", user_id)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_FANS_SHOP_ID_LIST_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        front_fans_id_set = set(front_fans_id_list)
        end_fans_id_set = set(end_fans_id_list)

        add_fans_id_set = end_fans_id_set - front_fans_id_set
        delete_fans_id_set = front_fans_id_set - end_fans_id_set

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["addShopIDs"] = list(add_fans_id_set)
        rep_json["delShopIDs"] = list(delete_fans_id_set)
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #33
0
    def post(self):
        user_log.info("ResetPasswordHandler POST.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["phone", "password"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            user_log.error("Reset password protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        phone = req_json["phone"]
        password = req_json["password"]

        if True != dao.resetPassword(phone, password):
            user_log.error("Reset password failed! Phone: %s", phone)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_RESET_PASSWORD_FAILED 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return
            
        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #34
0
    def get(self):
        user_log.info("FeedbackHandler GET.")
        
        offset = self.get_argument("offset", None)
        count = self.get_argument("count", None)
        if offset is None or count is None:
            user_log.error("Query feedback info protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        user_id = self.get_current_user()

        feed_list = dao.queryFeedbackListByPage(user_id, offset, count)
        if feed_list is None:
            user_log.error("Query feedback info failed! User id: %s", user_id)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_FEEDBACK_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["feedList"] = feed_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #35
0
    def get(self):
        user_log.info("QueryGoodsPromotHandler GET.")

        goods_id_list = self.get_arguments("gid")

        if not goods_id_list:
            user_log.error("Query goods promotion list failed! goods id list: %s", goods_id_list)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_GOODS_PROMOTION_LIST_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        goods_list = dao.queryGoodsPromotionList(goods_id_list)
        if goods_list is None:
            user_log.error("Query goods promotion list failed! goods id list: %s", goods_id_list)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_GOODS_PROMOTION_LIST_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["goodsList"] = goods_list
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return 
Exemple #36
0
    def get(self):
        user_log.info("QueryLatestVersionHandler GET.")

        system = self.get_argument("sys", None)
        if system is None:
            user_log.error("Query latest version protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR 
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        version = dao.queryLatestVersion(system)
        if version is None:
            user_log.error("Query latest version failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_QUERY_LATEST_VERSION_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        rep_json["version"] = version
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #37
0
    def post(self):
        user_log.info("ModifyFriendRemarkNameHandler POST.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["frdID", "rmkName"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            user_log.error("Modify friend remark name protocol data error!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        frd_id = req_json["frdID"]
        rmk_name = req_json["rmkName"]
        user_id = self.get_current_user()

        if True != dao_friend.modifyFriendName(user_id, frd_id, rmk_name):
            user_log.error("Modify friend remark name failed! User id: %s, friend id: %s", user_id, frd_id)
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_MODIFY_FRIEND_NAME_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #38
0
    def post(self):
        user_log.info("MessageSettingHandler POST.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["shopID", "msgEnable"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            req_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(req_json, cls=ExtendedJsonEncoder))
            return

        shop_id = req_json["shopID"]
        msg_enable = req_json["msgEnable"]

        user_id = self.get_current_user()

        if True != dao.modifyMessageSetting(user_id, shop_id, msg_enable):
            user_log.error("Modify message setting failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_MODIFY_MESSAGE_SETTING_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return
Exemple #39
0
    def post(self):
        user_log.info("FeedbackHandler POST.")

        json_msg_str = self.request.body
        req_json = json.loads(json_msg_str)
        required_args = ["feedback"]
        optional_args = []
        if True != httpJSONArgsCheck(req_json, required_args, optional_args):
            req_json["err"] = FD_ERR_USER_PROTOCOL_DATA_ERROR
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(req_json, cls=ExtendedJsonEncoder))
            return

        feedback = req_json["feedback"]

        user_id = self.get_current_user()

        if True != dao.feedback(user_id, feedback):
            user_log.error("Feedback failed!")
            rep_json = {}
            rep_json["err"] = FD_ERR_USER_FEEDBACK_FAILED
            self.set_header("Content-type", "application/json")
            self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
            return

        rep_json = {}
        rep_json["err"] = FD_USER_NOERR
        self.set_header("Content-type", "application/json")
        self.write(json.dumps(rep_json, cls=ExtendedJsonEncoder))
        return