Example #1
0
    def post(self):
        if User_tool.check_before_start("removeContactCar", self) >= 0:

            dati = json.loads(self.request.body)

            user_data = dati["User"]

            latitude = dati["Latitude"]
            longitude = dati["Longitude"]
            temp_user = User.static_querySearch_email(user_data["Email"])
            id_user = temp_user.get().key.id()
            timestamp = dati["Timestamp"]

            if History_park.parky(id_user, latitude, longitude,
                                  timestamp) == 1:
                if static_variable.DEBUG:
                    logging.debug(
                        "The application has to send notification? --> " +
                        str(True))

                right = StatusReturn(20, "getNotification", True)
                self.response.write(right.print_result())

            else:
                if static_variable.DEBUG:
                    logging.debug(
                        "The application has to send notification? --> " +
                        str(False))

                right = StatusReturn(21, "getNotification", False)
                self.response.write(right.print_result())
Example #2
0
    def post(self):
        if User_tool.check_before_start("getCars", self) >= 0:

            dati = json.loads(self.request.body)

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(dati)

            user_data = dati["User"]
            lower_email = user_data["Email"].lower()
            temp_user = User.static_querySearch_email(lower_email)

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(temp_user)

            id_user = temp_user.get()

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(id_user.key.id())

            cars = User_car.getCarFromUser(id_user.key.id())

            if (cars.count() == 0):
                allcars = []
                right = StatusReturn(3, "getAllCars_fromEmail", allcars)
                self.response.write(right.print_result())
            else:
                allcars = []
                for id_carTemp in cars:
                    if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                        logging.debug(id_carTemp)
                    allcars.append(Car.get_json(long(id_carTemp.id_car)))

                right = StatusReturn(3, "getCars", allcars)
                self.response.write(right.print_result())
Example #3
0
    def post(self):
        if User_tool.check_before_start("removeContactCar", self) >= 0:

            dati = json.loads(self.request.body)

            user_data = dati["User"]

            latitude = dati["Latitude"]
            longitude = dati["Longitude"]
            temp_user = User.static_querySearch_email(user_data["Email"])
            id_user = temp_user.get().key.id()
            timestamp = dati["Timestamp"]

            if History_park.parky(id_user, latitude, longitude, timestamp) == 1:
                if static_variable.DEBUG:
                    logging.debug("The application has to send notification? --> "+str(True))

                right = StatusReturn(20, "getNotification", True)
                self.response.write(right.print_result())

            else:
                if static_variable.DEBUG:
                    logging.debug("The application has to send notification? --> "+str(False))

                right = StatusReturn(21, "getNotification", False)
                self.response.write(right.print_result())
Example #4
0
    def post(self):
        if User_tool.check_before_start("getCars", self) >= 0:

            dati = json.loads(self.request.body)

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(dati)

            user_data = dati["User"]
            lower_email = user_data["Email"].lower()
            temp_user = User.static_querySearch_email(lower_email)

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(temp_user)

            id_user = temp_user.get()

            if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                logging.debug(id_user.key.id())

            cars = User_car.getCarFromUser(id_user.key.id())

            if (cars.count() == 0):
                allcars = []
                right = StatusReturn(3, "getAllCars_fromEmail", allcars)
                self.response.write(right.print_result())
            else:
                allcars = []
                for id_carTemp in cars:
                    if static_variable.DEBUG and static_variable.DEBUG_ALL_CARS:
                        logging.debug(id_carTemp)
                    allcars.append(Car.get_json(long(id_carTemp.id_car)))

                right = StatusReturn(3, "getCars", allcars)
                self.response.write(right.print_result())
Example #5
0
    def post(self):
        if User_tool.check_before_start("insertContactCar", self) >= 0:
            dati = json.loads(self.request.body)
            user_data = dati["User"]
            car_data = dati["Car"]
            for userClass in car_data["Users"]:
                user = userClass["Email"]
                user_key = User.is_user_check(user)
                if user_key == 0:
                    new_user = User(id_android=None,
                                    code=0,
                                    temp_code=0,
                                    email=user,
                                    nickname=user,
                                    is_user=0)
                    temp_user_key = new_user.put()
                    user_key = temp_user_key.id()

                if User_car.check_user_exist(user_key, int(
                        car_data["ID_car"])) > 0:
                    new_contact_car = User_car(id_user=user_key,
                                               id_car=int(car_data["ID_car"]))
                    new_contact_car.put()

                if User.is_registered_check(user_key) == 0:
                    Send_email.send_adding_group(user, user_data["Name"],
                                                 car_data["Name"])
                else:
                    Push_notification.send_push_add_group(
                        User.get_id_android(user_key), user_data["Name"],
                        car_data["Name"])

            right = StatusReturn(10, "insertContactCar")
            self.response.write(right.print_result())
Example #6
0
    def post(self):
        if User_tool.check_before_start("editCar", self) >= 0:

            dati = json.loads(self.request.body)

            car_data = dati["Car"]
            bluetooth_MAC = ""
            bluetooth_name = ""
            register = ""
            maker_color = None
            if "Bluetooth_MAC" in car_data:
                bluetooth_MAC = car_data["Bluetooth_MAC"]
            if "Bluetooth_Name" in car_data:
                bluetooth_name = car_data["Bluetooth_Name"]
            if "Register" in car_data:
                register = car_data["Register"]
            if "Marker_Color" in car_data:
                maker_color = car_data["Marker_Color"]

            Car.update_car(car_data["ID_car"], bluetooth_MAC, bluetooth_name,
                           car_data["Brand"], car_data["Name"], register,
                           maker_color)

            right = StatusReturn(19, "editCar")
            self.response.write(right.print_result())
Example #7
0
    def post(self):
        if User_tool.check_before_start("createGroup", self) >= 0:
            data = json.loads(self.request.body)
            new_group = Group(name=data["Name"], timestamp=str(datetime.datetime.now()))
            new_group.put()
            new_user_group = User_group(id_user=int(User_tool.return_id_from_email(str(data["Email"]))),
                                        id_group=int(new_group.key.id()))
            new_user_group.put()

            list_user = data["List_email"]
            # logging.debug(list_user)
            for user in list_user:

                user_key = User.is_user_check(user)
                if user_key == 0:
                    new_user = User(id_android=None, code=0, temp_code=0, email=user, nickname=None, is_user=0)
                    temp_user_key = new_user.put()
                    # logging.debug(temp_user_key)
                    user_key = temp_user_key.id()

                if User_group.check_user_exist(user_key, int(new_group.key.id())) > 0:
                    new_contact_group = User_group(id_user=user_key, id_group=int(new_group.key.id()))
                    new_contact_group.put()

            right = StatusReturn(6, "createGroup", long(new_group.key.id()))
            self.response.write(right.print_result())
Example #8
0
    def post(self):
        if User_tool.check_before_start("updatePosition", self) >= 0:
            data = json.loads(self.request.body)
            latitude = data["Latitude"]
            longitude = data["Longitude"]
            id_car = data["ID_car"]
            try:
                Car.update_position_ID(id_car, latitude, longitude)

                # push_class.send_post_request("APA91bFKpc1XNokg3Gv9GTWI49oE-UXe-ED6JMam2YPdAYG23yJf_P3c7Tl_55f9iECuhSNVa86PfZfcZ4knQ2VzFuBy_lNrq5_DLRHcghMkTQtRl9jyCbL6tV5TquDrse-dMQlGx9HKDLbtCNwEhGEFVeWXQH9EBjCt-VewSitHtgk2BxIB-w20ZLZtz2MCGAqRnTKD8B5n")

                temp_car_group = Car_group.getGroupFromCar(long(id_car))
                for group_result in temp_car_group:
                    list_user = User_group.getUserFromGroup(group_result.id_group)
                    result_id_android = []
                    for user_result in list_user:
                        temp_user = User.get_user_by_id(user_result.id_user)
                        if temp_user.email != data["Email"]:
                            if temp_user.is_user == 1:
                                logging.debug("Indirizzo email utente del push: " + str(temp_user.email))
                                result_id_android.append(temp_user.id_android)
                                # push_class.send_push_park(temp_user.id_android)
                            else:
                                Send_email.send_position(temp_user.email, latitude, longitude)
                    if len(result_id_android) > 0:
                        push_class.send_push_park(result_id_android , Car.get_name_id(long(id_car)))

                right = StatusReturn(5, "updatePosition")
                self.response.write(right.print_result())
            except:
                self.error(500)
                error = StatusReturn(8, "updatePosition", str(sys.exc_info()))
                self.response.write(error.print_general_error())
Example #9
0
    def post(self):
        if User_tool.check_before_start("updateGCM", self) >= 0:

            dati = json.loads(self.request.body)
            car_data = dati["Car"]
            if Car.updateUUID(id=car_data["ID_car"], uuid=car_data["UUID"], bmaj=car_data["Bmaj"], bmin=car_data["Bmin"]) == 0:
                right = StatusReturn(15, "updateUUID")
                self.response.write(right.print_result())
Example #10
0
    def post(self):
        if User_tool.check_before_start("updatePosition", self) >= 0:
            dati = json.loads(self.request.body)

            car_data = dati["Car"]
            Car.pick_car(car_data["ID_car"])

            right = StatusReturn(22, "pickCar", False)
            self.response.write(right.print_result())
Example #11
0
    def post(self):
        if User_tool.check_before_start("updateGCM", self) >= 0:

            dati = json.loads(self.request.body)
            user_data = dati["User"]

            if User.update_google_code(user_data["Email"], user_data["ID_gcm"]) == 0:
                right = StatusReturn(15, "updateGCM")
                self.response.write(right.print_result())
Example #12
0
    def post(self):
        if User_tool.check_before_start("updatePosition", self) >= 0:
            dati = json.loads(self.request.body)

            car_data = dati["Car"]
            Car.pick_car(car_data["ID_car"])

            right = StatusReturn(22, "pickCar", False)
            self.response.write(right.print_result())
Example #13
0
    def post(self):
        if User_tool.check_before_start("updateGCM", self) >= 0:

            dati = json.loads(self.request.body)
            user_data = dati["User"]

            if User.update_google_code(user_data["Email"],
                                       user_data["ID_gcm"]) == 0:
                right = StatusReturn(15, "updateGCM")
                self.response.write(right.print_result())
Example #14
0
    def post(self):
        if User_tool.check_before_start("getPositionCar", self) >= 0:
            data = json.loads(self.request.body)
            result = Car.get_position_id(data["ID"])
            result_JSON = {}
            result_JSON["latitude"] = result.latitude
            result_JSON["longitude"] = result.longitude

            right = StatusReturn(9, "getPositionCar", result_JSON)
            self.response.write(right.print_result())
Example #15
0
    def post(self):
        if User_tool.check_before_start("insertCarGroup", self) >= 0:
            data = json.loads(self.request.body)
            id_car = data["ID_car"]
            id_group = data["ID_group"]

            temp_car_group = Car_group(id_car=long(id_car), id_group=long(id_group))
            temp_car_group.put()

            right = StatusReturn(13, "insertCarGroup")
            self.response.write(right.print_result())
Example #16
0
    def post(self):
        if User_tool.check_before_start("updateGCM", self) >= 0:

            dati = json.loads(self.request.body)
            car_data = dati["Car"]
            if Car.updateUUID(id=car_data["ID_car"],
                              uuid=car_data["UUID"],
                              bmaj=car_data["Bmaj"],
                              bmin=car_data["Bmin"]) == 0:
                right = StatusReturn(15, "updateUUID")
                self.response.write(right.print_result())
Example #17
0
 def post(self):
     if User_tool.check_before_start("editGroup", self) >= 0:
         data = json.loads(self.request.body)
         name = data["Name"]
         id = data["ID_group"]
         try:
             Group.update_group(id, name)
             right = StatusReturn(17, "editGroup")
             self.response.write(right.print_result())
         except:
             self.error(500)
             error = StatusReturn(8, "editGroup", str(sys.exc_info()))
             self.response.write(error.print_general_error())
Example #18
0
    def post(self):
        if User_tool.check_before_start("removeContactGroup", self) >= 0:
            data = json.loads(self.request.body)
            list_user = data["List_email"]
            logging.debug(list_user)
            for user in list_user:

                user_key = User.is_user_check(user)

                if User_group.check_user_exist(user_key, data["ID_group"]) > 0:
                    User_group.delete_contact_group(user_key, data["ID_group"])

            right = StatusReturn(18, "removeContactGroup")
            self.response.write(right.print_result())
Example #19
0
    def post(self):
        if User_tool.check_before_start("createCar", self) >= 0:
            data = json.loads(self.request.body)
            if "Bluetooth_MAC" in data:
                new_car = Car(name=data["Name"], latitude="0", longitude="0", timestamp=str(datetime.datetime.now()),
                              email=data["Email"], bluetooth_MAC=data["Bluetooth_MAC"],
                              bluetooth_name=data["Bluetooth_name"], brand=data["Brand"])
            else:
                new_car = Car(name=data["Name"], latitude="0", longitude="0", timestamp=str(datetime.datetime.now()),
                              email=data["Email"], brand=data["Brand"])

            new_car.put()

            right = StatusReturn(4, "createCar", new_car.key.id())
            self.response.write(right.print_result())
Example #20
0
    def post(self):
        if User_tool.check_before_start("createCar", self) >= 0:
            dati = json.loads(self.request.body)
            car_data = dati["Car"]
            user_data = dati["User"]
            bluetooth_MAC = ""
            bluetooth_name = ""
            register = ""
            uuid = ""
            bmaj = ""
            bmin = ""
            marker_color = None

            if "Bluetooth_MAC" in car_data:
                bluetooth_MAC = car_data["Bluetooth_MAC"]
            if "Bluetooth_Name" in car_data:
                bluetooth_name = car_data["Bluetooth_Name"]
            if "Register" in car_data:
                register = car_data["Register"]
            if "Marker_Color" in car_data:
                marker_color = car_data["Marker_Color"]

            new_car = Car(name=car_data["Name"], latitude="0", longitude="0", timestamp=str(datetime.datetime.now()),
                          email=user_data["Email"], bluetooth_MAC=bluetooth_MAC, bluetooth_name=bluetooth_name,
                          brand=car_data["Brand"], register=register, isParked=False, lastdriver=user_data["Email"],
                          uuid=uuid, marker_color=marker_color)

            new_car = new_car.put()
            list_user = car_data["Users"]
            searchuser = User.static_querySearch_email(user_data["Email"])
            for user in searchuser:

                if static_variable.DEBUG:
                    logging.debug(user.key.id())
                new_contact_car = User_car(id_user=user.key.id(), id_car=(new_car.id()))
                new_contact_car.put()
            for user in list_user:
                userEmail = user["Email"]
                user_key = User.is_user_check(userEmail)
                if user_key == 0:
                    new_user = User(id_android=None, code=0, temp_code=0, email=userEmail, nickname=None, is_user=0)
                    temp_user_key = new_user.put()
                    user_key = temp_user_key.id()
                if User_car.check_user_exist(user_key, new_car.id()) > 0:
                    new_contact_car = User_car(id_user=user_key, id_car=new_car.id())
                    new_contact_car.put()
            right = StatusReturn(4, "createCar", new_car.id())
            self.response.write(right.print_result())
Example #21
0
    def post(self):
        if User_tool.check_before_start("updatePosition", self) >= 0:
            dati = json.loads(self.request.body)
            user_data = dati["User"]
            temp_user = User.static_querySearch_email(user_data["Email"])

            car_data = dati["Car"]

            timestamp = str(datetime.datetime.utcnow() +
                            datetime.timedelta(hours=1))
            if "Timestamp" in car_data:
                timestamp = car_data["Timestamp"]

            Car.update_position_ID(car_data["ID_car"], car_data["Latitude"],
                                   car_data["Longitude"], user_data["Email"])

            list_user = User_car.getUserFromCar(car_data["ID_car"])

            # Send notification to all user register with this car
            for user in list_user:

                # If the user is not registered inside the application send him an email
                if User.is_registered_check(user.id_user) == 0:
                    if User.get_email_user(user.id_user) != user_data["Email"]:
                        # Send_email.send_position(User.get_email_user(user.id_user), car_data["Latitude"],
                        #                      car_data["Longitude"], user_data["Name"],car_data["Name"])
                        logging.debug("Update position")
                else:
                    if User.get_email_user(user.id_user) != user_data["Email"]:
                        Push_notification.send_push_park(
                            User.get_id_android(user.id_user),
                            car_data["Name"], user_data["Name"],
                            car_data["ID_car"])

            if static_variable.DEBUG:
                logging.debug("Date if car: " + car_data["Name"])

            id_user = temp_user.get().key.id()

            if static_variable.DEBUG:
                logging.debug(timestamp)

            History_park.update_history(id_user, car_data["Latitude"],
                                        car_data["Longitude"], timestamp)

            right = StatusReturn(5, "updatePosition")
            self.response.write(right.print_result())
Example #22
0
    def post(self):
        if User_tool.check_before_start("deleteGroup", self) >= 0:
            data = json.loads(self.request.body)
            id_group = long(data["ID_group"])
            temp_user = User.static_querySearch_email(data["Email"])
            User_group.delete_contact_group(temp_user.get().key.id(), id_group)

            logging.debug(User_group.getUserFromGroup(id_group).count())

            if User_group.getUserFromGroup(id_group).count() == 0:
                Group.delete_group_ID(id_group)
                list_car = Car_group.getCarFromGroup(id_group)
                for cars in list_car:
                    Car_group.delete_car_ID(cars.id_car, id_group)

            right = StatusReturn(8, "deleteGroup", "Removed From: " + str(id_group))
            self.response.write(right.print_result())
Example #23
0
 def post(self):
     if User_tool.check_before_start("editCar", self) >= 0:
         data = json.loads(self.request.body)
         id = data["ID_car"]
         email = data["Email"]
         bluetooth_MAC = data["Bluetooth_MAC"]
         bluetooth_name = data["Bluetooth_name"]
         brand = data["Brand"]
         name = data["Name"]
         try:
             Car.update_car(id, bluetooth_MAC, bluetooth_name, brand, email, name)
             right = StatusReturn(16, "editCar")
             self.response.write(right.print_result())
         except:
             self.error(500)
             error = StatusReturn(8, "editCar", str(sys.exc_info()))
             self.response.write(error.print_general_error())
Example #24
0
    def post(self):
        if User_tool.check_before_start("insertContactGroup", self) >= 0:
            data = json.loads(self.request.body)
            list_user = data["List_email"]
            logging.debug(list_user)
            for user in list_user:
                user_key = User.is_user_check(user)
                if user_key == 0:
                    new_user = User(id_android=None, code=0, temp_code=0, email=user, nickname=None, is_user=0)
                    temp_user_key = new_user.put()
                    # logging.debug(temp_user_key)
                    user_key = temp_user_key.id()

                if User_group.check_user_exist(user_key, long(data["ID_group"])) > 0:
                    new_contact_group = User_group(id_user=user_key, id_group=long(data["ID_group"]))
                    new_contact_group.put()

            right = StatusReturn(10, "insertContactGroup")
            self.response.write(right.print_result())
Example #25
0
    def post(self):
        if User_tool.check_before_start("getAllCars_groupID", self) >= 0:
            data = json.loads(self.request.body)
            try:
                # id_groups = User_tool.return_groups(data["Email"])
                result = []
                # if(id_groups>0):
                # for key in id_groups:
                id_car_by_group = Car_group.getCarFromGroup(data["ID_group"])

                for carTemp in id_car_by_group:
                    result.append((Car.getCarbyID(carTemp.id_car)).to_string_json_car())

                result_json = StatusReturn(2, "getAllCars_groupID", result)
                self.response.write(result_json.print_result())
            except:
                self.error(500)
                error = StatusReturn(6, "getAllCars_groupID")
                self.response.write(error.print_general_error())
Example #26
0
    def post(self):
        if User_tool.check_before_start("updatePosition", self) >= 0:
            dati = json.loads(self.request.body)
            user_data = dati["User"]
            temp_user = User.static_querySearch_email(user_data["Email"])

            car_data = dati["Car"]

            timestamp = str(datetime.datetime.utcnow() + datetime.timedelta(hours=1))
            if "Timestamp" in car_data:
                timestamp = car_data["Timestamp"]

            Car.update_position_ID(car_data["ID_car"], car_data["Latitude"], car_data["Longitude"], user_data["Email"])

            list_user = User_car.getUserFromCar(car_data["ID_car"])

            # Send notification to all user register with this car
            for user in list_user:

                # If the user is not registered inside the application send him an email
                if User.is_registered_check(user.id_user) == 0:
                    if User.get_email_user(user.id_user) != user_data["Email"]:
                       # Send_email.send_position(User.get_email_user(user.id_user), car_data["Latitude"],
                       #                      car_data["Longitude"], user_data["Name"],car_data["Name"])
                        logging.debug("Update position")
                else:
                    if User.get_email_user(user.id_user) != user_data["Email"]:
                        Push_notification.send_push_park(User.get_id_android(user.id_user), car_data["Name"], user_data["Name"], car_data["ID_car"])

            if static_variable.DEBUG:
                logging.debug("Date if car: "+car_data["Name"])

            id_user = temp_user.get().key.id()



            if static_variable.DEBUG:
                logging.debug(timestamp)

            History_park.update_history(id_user,car_data["Latitude"],car_data["Longitude"], timestamp)

            right = StatusReturn(5, "updatePosition")
            self.response.write(right.print_result())
Example #27
0
    def post(self):
        if User_tool.check_before_start("removeContactCar", self) >= 0:
            dati = json.loads(self.request.body)
            user_data = dati["User"]
            car_data = dati["Car"]
            for userClass in car_data["Users"]:
                user = userClass["Email"]
                if static_variable.DEBUG:
                    logging.debug("Email: " + str(user))

                tempUser = User.static_querySearch_email(user)

                for id_user in tempUser:
                    user_key = id_user.key.id()

                User_car.deleteCarUser(user_key, car_data["ID_car"])
            # user_car = User_car.getUserFromCar(car_data["ID_car"])
            # if (user_car.count() == 0):
            # Car.delete_car_ID(car_data["ID_car"])
            right = StatusReturn(18, "removeContactCar")
            self.response.write(right.print_result())
Example #28
0
    def post(self):
        if User_tool.check_before_start("removeContactCar", self) >= 0:
            dati = json.loads(self.request.body)
            user_data = dati["User"]
            car_data = dati["Car"]
            for userClass in car_data["Users"]:
                user = userClass["Email"]
                if static_variable.DEBUG:
                    logging.debug("Email: "+str(user))

                tempUser = User.static_querySearch_email(user)

                for id_user in tempUser:
                    user_key = id_user.key.id()

                User_car.deleteCarUser(user_key, car_data["ID_car"])
            # user_car = User_car.getUserFromCar(car_data["ID_car"])
            # if (user_car.count() == 0):
            # Car.delete_car_ID(car_data["ID_car"])
            right = StatusReturn(18, "removeContactCar")
            self.response.write(right.print_result())
Example #29
0
    def post(self):
        if User_tool.check_before_start("deleteCar", self) >= 0:

            dati = json.loads(self.request.body)
            user_data = dati["User"]
            car_data = dati["Car"]

            temp_user = User.static_querySearch_email(user_data["Email"])
            user = temp_user.get()
            id_user = user.key.id()

            User_car.deleteCarUser(id_user, car_data["ID_car"])
            user_car = User_car.getUserFromCar(car_data["ID_car"])

            if static_variable.DEBUG:
                logging.debug("Number of car with this user: "******"ID_car"])

            right = StatusReturn(7, "deleteCar")
            self.response.write(right.print_result())
Example #30
0
    def post(self):
        if User_tool.check_before_start("deleteCar", self) >= 0:

            dati = json.loads(self.request.body)
            user_data = dati["User"]
            car_data = dati["Car"]

            temp_user = User.static_querySearch_email(user_data["Email"])
            user = temp_user.get()
            id_user = user.key.id()

            User_car.deleteCarUser(id_user, car_data["ID_car"])
            user_car = User_car.getUserFromCar(car_data["ID_car"])

            if static_variable.DEBUG:
                logging.debug("Number of car with this user: "******"ID_car"])

            right = StatusReturn(7, "deleteCar")
            self.response.write(right.print_result())
Example #31
0
 def post(self):
     if User_tool.check_before_start("getIDGroups", self) >= 0:
         data = json.loads(self.request.body)
         try:
             id_groups = User_tool.return_groups(data["Email"])
             if (id_groups > 0):
                 all_id_group = "["
                 for key in id_groups:
                     if all_id_group != "[":
                         all_id_group = all_id_group + ",\"" + str(key.id_group) + "\""
                     else:
                         all_id_group = all_id_group + "\"" + str(key.id_group) + "\""
                 all_id_group += "]"
                 result_json = StatusReturn(1, "getIDGroups", all_id_group)
                 self.response.write(result_json.print_result())
             else:
                 self.error(500)
                 error = StatusReturn(5, "getIDGroups")
                 self.response.write(error.print_general_error())
         except:
             self.error(500)
             error = StatusReturn(6, "getIDGroups")
             self.response.write(error.print_general_error())
Example #32
0
    def post(self):
        if User_tool.check_before_start("insertContactCar", self) >= 0:
            dati = json.loads(self.request.body)
            user_data = dati["User"]
            car_data = dati["Car"]
            for userClass in car_data["Users"]:
                user = userClass["Email"]
                user_key = User.is_user_check(user)
                if user_key == 0:
                    new_user = User(id_android=None, code=0, temp_code=0, email=user, nickname=user, is_user=0)
                    temp_user_key = new_user.put()
                    user_key = temp_user_key.id()

                if User_car.check_user_exist(user_key, int(car_data["ID_car"])) > 0:
                    new_contact_car = User_car(id_user=user_key, id_car=int(car_data["ID_car"]))
                    new_contact_car.put()

                if User.is_registered_check(user_key) == 0:
                    Send_email.send_adding_group(user, user_data["Name"], car_data["Name"])
                else:
                    Push_notification.send_push_add_group(User.get_id_android(user_key), user_data["Name"],car_data["Name"])

            right = StatusReturn(10, "insertContactCar")
            self.response.write(right.print_result())
Example #33
0
    def post(self):
        if User_tool.check_before_start("editCar", self) >= 0:

            dati = json.loads(self.request.body)

            car_data = dati["Car"]
            bluetooth_MAC = ""
            bluetooth_name = ""
            register = ""
            maker_color = None
            if "Bluetooth_MAC" in car_data:
                bluetooth_MAC = car_data["Bluetooth_MAC"]
            if "Bluetooth_Name" in car_data:
                bluetooth_name = car_data["Bluetooth_Name"]
            if "Register" in car_data:
                register = car_data["Register"]
            if "Marker_Color" in car_data:
                maker_color = car_data["Marker_Color"]

            Car.update_car(car_data["ID_car"], bluetooth_MAC, bluetooth_name, car_data["Brand"], car_data["Name"],
                           register, maker_color)

            right = StatusReturn(19, "editCar")
            self.response.write(right.print_result())
Example #34
0
 def post(self):
     if User_tool.check_before_start("removeCarGroup", self) >= 0:
         data = json.loads(self.request.body)
         Car_group.delete_car_ID(data["ID_car"], data["ID_group"])
         right = StatusReturn(14, "removeCarGroup", "Delete " + str(data["ID"]))
         self.response.write(right.print_result())
Example #35
0
 def post(self):
     if User_tool.check_before_start("sendAcceptableUUID", self) >= 0:
         uuid = ["B9407F30-F5F8-466E-AFF9-25556B57FE6D"]
         right = StatusReturn(3, "sendAcceptableUUID", uuid)
         self.response.write(right.print_result())
Example #36
0
 def post(self):
     if User_tool.check_before_start("updateGoogleCode", self) >= 0:
         data = json.loads(self.request.body)
         User.update_google_code(data["Email"], data["ID"])
         right = StatusReturn(14, "updateGoogleCode")
         self.response.write(right.print_result())
Example #37
0
 def post(self):
     if User_tool.check_before_start("confirmCode", self) >= 0:
         right = StatusReturn(11, "confirmCode")
         self.response.write(right.print_result())
Example #38
0
 def post(self):
     if User_tool.check_before_start("sendAcceptableUUID", self) >= 0:
         uuid = ["B9407F30-F5F8-466E-AFF9-25556B57FE6D"]
         right = StatusReturn(3, "sendAcceptableUUID", uuid)
         self.response.write(right.print_result())
Example #39
0
 def post(self):
     if User_tool.check_before_start("confirmCode", self) >= 0:
         right = StatusReturn(11, "confirmCode")
         self.response.write(right.print_result())
Example #40
0
    def post(self):
        if User_tool.check_before_start("createCar", self) >= 0:
            dati = json.loads(self.request.body)
            car_data = dati["Car"]
            user_data = dati["User"]
            bluetooth_MAC = ""
            bluetooth_name = ""
            register = ""
            uuid = ""
            bmaj = ""
            bmin = ""
            marker_color = None

            if "Bluetooth_MAC" in car_data:
                bluetooth_MAC = car_data["Bluetooth_MAC"]
            if "Bluetooth_Name" in car_data:
                bluetooth_name = car_data["Bluetooth_Name"]
            if "Register" in car_data:
                register = car_data["Register"]
            if "Marker_Color" in car_data:
                marker_color = car_data["Marker_Color"]

            new_car = Car(name=car_data["Name"],
                          latitude="0",
                          longitude="0",
                          timestamp=str(datetime.datetime.now()),
                          email=user_data["Email"],
                          bluetooth_MAC=bluetooth_MAC,
                          bluetooth_name=bluetooth_name,
                          brand=car_data["Brand"],
                          register=register,
                          isParked=False,
                          lastdriver=user_data["Email"],
                          uuid=uuid,
                          marker_color=marker_color)

            new_car = new_car.put()
            list_user = car_data["Users"]
            searchuser = User.static_querySearch_email(user_data["Email"])
            for user in searchuser:

                if static_variable.DEBUG:
                    logging.debug(user.key.id())
                new_contact_car = User_car(id_user=user.key.id(),
                                           id_car=(new_car.id()))
                new_contact_car.put()
            for user in list_user:
                userEmail = user["Email"]
                user_key = User.is_user_check(userEmail)
                if user_key == 0:
                    new_user = User(id_android=None,
                                    code=0,
                                    temp_code=0,
                                    email=userEmail,
                                    nickname=None,
                                    is_user=0)
                    temp_user_key = new_user.put()
                    user_key = temp_user_key.id()
                if User_car.check_user_exist(user_key, new_car.id()) > 0:
                    new_contact_car = User_car(id_user=user_key,
                                               id_car=new_car.id())
                    new_contact_car.put()
            right = StatusReturn(4, "createCar", new_car.id())
            self.response.write(right.print_result())