$return_value["reason"] = "Must enter a last name"; } else { if ($over_21 != 0 && $over_21 != 1) { // Make sure they've chosen whether or not they're 21 $return_value["status"] = false; $return_value["reason"] = "Must choose over or under 21"; } else { if (!validate_food_choice($food_pref, $db_conn)) { // Make sure they've chosen a valid food choice $return_value["status"] = false; $return_value["reason"] = "Must choose a food preference"; } else { if (authorize_request($party_id, $auth_token, $db_conn, $return_value)) { // Make sure this party can add more plus ones $party_max_plus_ones = get_max_plus_ones($party_id, $db_conn); $party_current_plus_ones = get_current_plus_ones($party_id, $db_conn); if ($party_current_plus_ones >= $party_max_plus_ones) { $return_value["status"] = false; $return_value["reason"] = "Max number of plus ones reached"; } else { $new_person_id = add_plus_one($first_name, $last_name, $food_pref, $over_21, $is_attending, $party_id, $db_conn); if ($new_person_id < 0) { $return_value["status"] = false; $return_value["reason"] = "Error adding person"; } else { $return_value["status"] = true; $return_value["person_id"] = $new_person_id; $return_value["first_name"] = $first_name; $return_value["last_name"] = $last_name; $return_value["food_pref"] = $food_pref; $return_value["over_21"] = $over_21;
$login_code = strtoupper(trim($_POST["login_code"])); $login_hash = md5($login_code); $login_query = $db_conn->prepare("CALL lookup_party_id(:login_hash)"); $login_query->bindParam(":login_hash", $login_hash); $login_query->execute(); $results = $login_query->fetchAll(PDO::FETCH_ASSOC); if (count($results) > 0) { $login_query->closeCursor(); $party_id = $results[0]["party_id"]; $return_value["login_successful"] = true; // Generate the login token $return_value["auth_token"] = generate_login_token($party_id, $db_conn); $return_value["party_id"] = $party_id; // Get party data $return_value["party_info"] = get_party_data($party_id, $db_conn); $return_value["party_info"]["current_plus_ones"] = get_current_plus_ones($party_id, $db_conn); // Get people in party $return_value["party_people"] = get_party_people($party_id, $db_conn); // Get music suggestions $return_value["music_suggestions"] = get_music_suggestions($party_id, $db_conn); // Get the food choices $return_value["food_choices"] = get_food_choices($db_conn); } else { $return_value["login_successful"] = false; $return_value["reason"] = "Invalid login code"; } } } } header("Content-type: application/json"); header("Cache-Control: no-cache, no-store, must-revalidate");