本文整理匯總了Golang中structs.AuthToken.Code方法的典型用法代碼示例。如果您正苦於以下問題:Golang AuthToken.Code方法的具體用法?Golang AuthToken.Code怎麽用?Golang AuthToken.Code使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類structs.AuthToken
的用法示例。
在下文中一共展示了AuthToken.Code方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetOccupancy
/*
* 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: Validate
//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: SetMaxOccupancy
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: GetMaxOccupancy
/*
* 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: Check
//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: List
//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: List
//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")
}
}