update verify endpoint

pull/14/head
Up 6 months ago
parent e2efcd550c
commit 174b962f19
No known key found for this signature in database
GPG Key ID: 3B75CD7439FEB388

@ -56,7 +56,7 @@ func Init(mux *http.ServeMux) error {
// new session
mux.HandleFunc("POST /savedata/updateall", handleUpdateAll)
mux.HandleFunc("POST /savedata/verify", handleSessionVerify)
mux.HandleFunc("POST /savedata/system/verify", handleSystemVerify)
mux.HandleFunc("GET /savedata/system", handleGetSystemData)
mux.HandleFunc("GET /savedata/session", handleGetSessionData)

@ -627,7 +627,7 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) {
return
}
} else {
if err := db.UpdateTrainerIds(trainerId, secretId, uuid); err != nil {
if err = db.UpdateTrainerIds(trainerId, secretId, uuid); err != nil {
httpError(w, r, err, http.StatusInternalServerError)
return
}
@ -646,24 +646,23 @@ func handleUpdateAll(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}
type SessionVerifyResponse struct {
type SystemVerifyResponse struct {
Valid bool `json:"valid"`
SessionData *defs.SessionSaveData `json:"sessionData"`
SystemData *defs.SystemSaveData `json:"systemData"`
}
type SessionVerifyRequest struct {
type SystemVerifyRequest struct {
ClientSessionId string `json:"clientSessionId"`
Slot int `json:"slot"`
}
func handleSessionVerify(w http.ResponseWriter, r *http.Request) {
func handleSystemVerify(w http.ResponseWriter, r *http.Request) {
uuid, err := uuidFromRequest(r)
if err != nil {
httpError(w, r, err, http.StatusBadRequest)
return
}
var input SessionVerifyRequest
var input SystemVerifyRequest
err = json.NewDecoder(r.Body).Decode(&input)
if err != nil {
httpError(w, r, fmt.Errorf("failed to decode request body: %s", err), http.StatusBadRequest)
@ -677,7 +676,7 @@ func handleSessionVerify(w http.ResponseWriter, r *http.Request) {
return
}
response := SessionVerifyResponse{
response := SystemVerifyResponse{
Valid: active,
}
@ -689,14 +688,14 @@ func handleSessionVerify(w http.ResponseWriter, r *http.Request) {
return
}
var storedSaveData defs.SessionSaveData
storedSaveData, err = db.ReadSessionSaveData(uuid, input.Slot)
var storedSaveData defs.SystemSaveData
storedSaveData, err = db.ReadSystemSaveData(uuid)
if err != nil {
httpError(w, r, fmt.Errorf("failed to read session save data: %s", err), http.StatusInternalServerError)
return
}
response.SessionData = &storedSaveData
response.SystemData = &storedSaveData
}
jsonResponse(w, r, response)
@ -733,6 +732,7 @@ func handleGetSystemData(w http.ResponseWriter, r *http.Request) {
return
}
//TODO apply vouchers
jsonResponse(w, r, save)
}

Loading…
Cancel
Save