package server import ( "JISQueueing/db" "net/http" ) //Login handles api calls to /api/login func Login(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if err != nil { InvalidUserInput(w, r) return } user := r.Form.Get("user") pass := r.Form.Get("pass") if user == "" || pass == "" { InvalidUserInput(w, r) return } token, result := db.Login(user, pass) switch result { case db.InvalidUser: fallthrough case db.InvalidPassword: Unauthorized(w, r) case db.InvalidInternalPasswordHash: InternalServerError(w, r) case db.ReloginRequest: fallthrough case db.LoginSuccessful: writeJSONResponse(w, http.StatusOK, token) } } //Logout handles api calls to /api/logout func Logout(w http.ResponseWriter, r *http.Request) { if !handleToken(w, r) { return } db.Logout(r.Form.Get("token")) writeJSONResponse(w, http.StatusOK, nil) }