示例#1
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")
	}
}
示例#2
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")
	}
}