Пример #1
0
/*
 * Gets the current occupancy (people that have bought daypasses) for a given day.
 */
func GetOccupancy(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()

	var auth S.AuthToken
	var date string

	for k, v := range r.Form {
		if k == "user" {
			auth.User = strings.Join(v, "")
		} else if k == "date" {
			date = strings.Join(v, "")
		} else {
			auth.Code = strings.Join(v, "")
		}
	}

	if !db.Authenticate(auth) {
		fmt.Fprintf(w, "Please login")
		return
	}

	fmt.Fprintf(w, db.GetOccupancy(auth, date))

	//if db.HasHotel(auth) {
	//} else {
	//fmt.Fprintf(w, "You do not work for a hotel")
	//}
}
Пример #2
0
//Invoked by dispatch to authenticate a user
func Validate(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()

	var token S.Token
	var auth S.AuthToken

	for k, v := range r.Form {
		if k == "hotel" {
			token.Hotel = strings.Join(v, "")
		} else if k == "code" {
			token.Code = strings.Join(v, "")
		} else if k == "user" {
			auth.User = strings.Join(v, "")
		} else {
			auth.Code = strings.Join(v, "")
		}
	}

	if !db.Authenticate(auth) {
		fmt.Fprintf(w, "Please login")
		return
	}

	if db.ValidateToken(token) {
		fmt.Printf("[SUCCESS] %s checked into %s\n", auth.User, token.Hotel)
		fmt.Fprintf(w, "VALID DAYCATION")
	} else {
		fmt.Fprintf(w, "INVALID!")
	}
}
Пример #3
0
func SetMaxOccupancy(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")

	r.ParseForm()

	var auth S.AuthToken

	var maxOccupancy string
	var date string
	hotel := "none"

	for k, v := range r.Form {
        if k == "user" {
			auth.User = strings.Join(v, "")
		} else if k == "date" {
			date = strings.Join(v, "")
		} else if k == "maxOccupancy" {
			maxOccupancy = strings.Join(v, "")
		} else if k == "hotel" {
			hotel = strings.Join(v, "")
		} else if k == "code" {
			auth.Code = strings.Join(v, "")
		}
	}

	if !db.Authenticate(auth) || hotel == "none" {
		fmt.Fprintf(w, "{\"Please login\"}")
		return
	}


	maxOccupancyInt, err := strconv.Atoi(maxOccupancy)
	if err != nil {
		fmt.Fprintf(w, "{\"ERROR\":1}")
		return
	}

	fail := "0"

	if db.SetMaxOccupancy(date, hotel, maxOccupancyInt) {
		fail = "1"
	}
	fmt.Fprintf(w, "{" + fail + "}")

	// if db.HasHotel(auth) {
	// 	fmt.Fprintf(w, db.SetMaxOccupancy(auth, maxOccupancy, date))
	// } else {
	// 	fmt.Fprintf(w, "You do not work for a hotel")
	// }
}
Пример #4
0
/*
 * Gets the max occupancy for a given day.
 */
func GetMaxOccupancy(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")

	r.ParseForm()

	var auth S.AuthToken
	var date string

	hotel := "none"

	for k, v := range r.Form {
       	if k == "user" {
			auth.User = strings.Join(v, "")
		} else if k == "date" {
			date = strings.Join(v, "")
		} else if k == "code" {
			auth.Code = strings.Join(v, "")
		} else if k == "hotel" {
			hotel = strings.Join(v, "")
		}
	}

	if !db.Authenticate(auth) || hotel == "none" {
		fmt.Fprintf(w, "{\"Please login\"}")
		return
	}


	occupancyString := strconv.Itoa(db.GetMaxOccupancy(date, hotel))
	
	//fmt.Fprintf(w, "10")
	fmt.Fprintf(w, occupancyString)

	// real one here 
	//fmt.Fprintf(w, occupancyString)

	// if db.HasHotel(auth) {
	// 	fmt.Fprintf(w, db.GetMaxOccupancy(auth, date))
	// } else {
	// 	fmt.Fprintf(w, "You do not work for a hotel")
	// }
}
Пример #5
0
//Invoked by dispatch to Check In a guest
func Check(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")

	r.ParseForm()

	var customer string
	var callback string
	var hotel string
	var auth S.AuthToken
	var checkin string

	for k, v := range r.Form {
		if k == "guestId" {
			customer = strings.Join(v, "")
		} else if k == "user" {
			auth.User = strings.Join(v, "")
		} else if k == "code" {
			auth.Code = strings.Join(v, "")
		} else if k == "callback" {
			callback = strings.Join(v, "")
		} else if k == "checkedIn" {
			checkin = strings.Join(v, "")
		} else if k == "hotel" {
			hotel = strings.Join(v, "")
		}
	}

	if !db.Authenticate(auth) || customer == "" {
		fmt.Fprintf(w, "{\"Please login\"}")
		return
	}

	fmt.Println("Checked in " + customer)

	check, _ := strconv.ParseBool(checkin)
	fmt.Println(db.CheckIn(hotel, customer, check))

	fmt.Fprintf(w, callback+"(\"SUCCESS\")")
}
Пример #6
0
//Invoked by dispatch to authenticate a user
func List(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()

	var auth S.AuthToken
	for k, v := range r.Form {
		if k == "user" {
			auth.User = strings.Join(v, "")
		} else {
			auth.Code = strings.Join(v, "")
		}
	}

	if !db.Authenticate(auth) {
		fmt.Fprintf(w, "Please login")
		return
	}

	if db.HasHotel(auth) {
		fmt.Fprintf(w, db.GetPasses(auth))
	} else {
		fmt.Fprintf(w, "You do not work for a hotel")
	}
}
Пример #7
0
//Invoked by dispatch to authenticate a user
func List(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "*")
	w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept")

	r.ParseForm()

	var callback string
	var auth S.AuthToken
	hotel := "none"
	for k, v := range r.Form {
		if k == "user" {
			auth.User = strings.Join(v, "")
		} else if k == "code" {
			auth.Code = strings.Join(v, "")
		} else if k == "callback" {
			callback = strings.Join(v, "")
		} else if k == "hotel" {
			hotel = strings.Join(v, "")
		}
	}

	if !db.Authenticate(auth) || hotel == "none" {
		fmt.Println(auth.User + " attempted to access list")
		fmt.Fprintf(w, "{\"Please login\"}")
		return
	}

	///fmt.Fprintf(w, callback + "(" + db.GetPasses(hotel, auth) + ")")

	//hasHotel is causing problems for the metropolitan
	if db.HasHotel(auth) {
		fmt.Fprintf(w, callback+"("+db.GetPasses(hotel, auth)+")")
	} else {
		fmt.Fprintf(w, "You do not work for a hotel")
	}
}