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())
def post(self): try: data = json.loads(self.request.body) if Send_email.check_mail(data["Email"]): if static_variable.DEBUG: logging.debug("Valid email") try: code = random.randint(100000, 999999) new_user = User(code=code, temp_code=code, email=data["Email"], nickname=data["Name"], is_user=0) try: contact_key = new_user.querySearch_email() if contact_key.count() == 0: new_user.put() else: temp_user = contact_key.get() temp_user.update_contact(code, data["Name"]) try: Send_email.send_code(code, data["Email"]) right = StatusReturn(0, 0) self.response.write(right.error_registration()) except: self.error(200) error = StatusReturn(3, 0) self.response.write(error.error_registration()) except: self.error(200) error = StatusReturn(4, 0) self.response.write(error.error_registration()) except: self.error(200) error = StatusReturn(2, 0) self.response.write(error.error_registration()) else: if static_variable.DEBUG: logging.debug("Email not valid") self.error(200) error = StatusReturn(5, 0) self.response.write(error.error_registration()) except: self.error(200) error = StatusReturn(1, 0) self.response.write(error.error_registration())
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())
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())
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())
def check_code(email, code): temp_user_key = User.static_querySearch_email(email) if temp_user_key.count() == 0: return -2 else: temp_user = temp_user_key.get() return temp_user.check_code(code)
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())
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())
def return_id_from_email(email): temp_key_user = User.static_querySearch_email(email) try: temp_id_user = temp_key_user.get().key.id() return temp_id_user except: return -1
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())
def return_groups(email): temp_key_user = User.static_querySearch_email(email) try: temp_id_user = temp_key_user.get().key.id() id_groups = User_group.getGroupFromUser(temp_id_user) return id_groups except: return -1
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())
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())
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())
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())
def post(self): try: data = json.loads(self.request.body) try: code = random.randint(100000, 999999) new_user = User(id_android=data["ID"], code=code, temp_code=code, email=data["Email"], nickname=data["Nickname"], is_user=1) try: contact_key = new_user.querySearch_email() if contact_key.count() == 0: new_user.put() else: temp_user = contact_key.get() temp_user.update_contact(code) try: Send_email.send_code(code, data["Email"]) right = StatusReturn(0, 0) self.response.write(right.error_registration()) except: self.error(500) error = StatusReturn(3, 0) self.response.write(error.error_registration()) except: self.error(500) error = StatusReturn(4, 0) self.response.write(error.error_registration()) except: self.error(500) error = StatusReturn(2, 0) self.response.write(error.error_registration()) except: self.error(500) error = StatusReturn(1, 0) self.response.write(error.error_registration())
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())
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())
def to_string_json_car(self): car_users = [] id_users = User_car.getUserFromCar(self.key.id()) for id_user in id_users: user = User.get_user_by_id(id_user.id_user) car_users.append(user.toString_JSON()) return { "ID_car": str(self.key.id()), "Brand": str(self.brand), "Name": str(self.name), "Latitude": str(self.latitude), "Longitude": str(self.longitude), "Users": car_users, "Timestamp": str(self.timestamp), "Register": str(self.register), "Last_driver": str(self.lastdriver), "isParked": self.isParked, "Bluetooth_MAC": str(self.bluetooth_MAC), "Bluetooth_Name": str(self.bluetooth_name), "UUID": str(self.uuid), "Bmin": str(self.bmin), "Bmaj": str(self.bmaj), "Marker_Color": self.marker_color }
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())
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())
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())
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())
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())
def getUser(self): user = User.static_querySearch_email(self.id_user) return user
def get(self): all_users = User.all_user() for user in all_users: Summary.user_house(user.key.id())