if (path.contains("/api/flight")) {
// adds a new flight to the flights controller
JSONObject flightObj = new JSONObject(request.getInputStream());
FlightController fc = FlightController.getInstance();
String flightId = (String) flightObj.get("flightId");
String state = (String) flightObj.get("state");
fc.addFlight(flightId, state);
res.put("result", "added");
} else if (path.contains("/api/flights")) {
// adds a flight status
Flights fs = Flights.getInstance();
JSONObject o = new JSONObject(request.getInputStream());
String flight = (String) o.get("flight");
String depart = (String) o.get("depart");
String arrive = (String) o.get("arrive");
String time = (String) o.get("time");
String flightTime = (String) o.get("flighttime");
fs.add(flight, depart, arrive, time, flightTime);
res.put("result", "added");
} else if (path.contains("/api/addmyflight")) {
} else if (path.contains("/api/login")) {
// Manages the Login without the ugly basic popup window
JSONObject loginObj = new JSONObject(request.getInputStream());
String user = (String) loginObj.get("username");
String pass = (String) loginObj.get("password");
// Logs in the user
// request.login(user, pass);
if (request.getUserPrincipal().getName().compareTo(user) == 0) {
res.put("status", "loggedin");
} else {
res.put("status", "error in login");
}
} else if (path.contains("/api/fc/")) {
// Creates a new flight status
JSONObject o = new JSONObject(request.getInputStream());
String flightId = o.getString("flightId");
String state = o.getString("state");
FlightController fc = FlightController.getInstance();
fc.addFlight(flightId, state);
res.put("result", "added");
} else if (path.contains("/api/myflights/")) {
// Adds a flight
Principal prin = request.getUserPrincipal();
if (prin != null) {