frontend: team registration
This commit is contained in:
parent
bc135d00c5
commit
184714aeeb
10 changed files with 208 additions and 28 deletions
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"path"
|
||||
|
|
@ -16,28 +15,26 @@ func RegistrationHandler(w http.ResponseWriter, r *http.Request, sURL []string)
|
|||
return
|
||||
}
|
||||
|
||||
if len(sURL) < 1 || len(sURL[0]) == 0 {
|
||||
http.Error(w, "{\"errmsg\":\"Arguments manquants.\"}", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
teamInitialName := sURL[0]
|
||||
|
||||
// Check request type and size
|
||||
if r.Method != "POST" {
|
||||
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
|
||||
return
|
||||
} else if r.ContentLength < 0 || r.ContentLength > 1023 {
|
||||
} else if r.ContentLength < 0 || r.ContentLength > 4095 {
|
||||
http.Error(w, "{\"errmsg\":\"Requête trop longue ou de taille inconnue\"}", http.StatusRequestEntityTooLarge)
|
||||
return
|
||||
}
|
||||
|
||||
if tmpfile, err := ioutil.TempFile(path.Join(SubmissionDir, "_registration"), ""); err != nil {
|
||||
log.Println("Unable to generate registration file:", err)
|
||||
if err := saveFile(path.Join(SubmissionDir, "_registration", teamInitialName), r); err != nil {
|
||||
log.Println("Unable to open registration file:", err)
|
||||
http.Error(w, "{\"errmsg\":\"Internal server error. Please retry in few seconds.\"}", http.StatusInternalServerError)
|
||||
} else {
|
||||
// The file will be reopened by saveFile
|
||||
tmpfile.Close()
|
||||
|
||||
if err := saveFile(tmpfile.Name(), r); err != nil {
|
||||
log.Println("Unable to open registration file:", err)
|
||||
http.Error(w, "{\"errmsg\":\"Internal server error. Please retry in few seconds.\"}", http.StatusInternalServerError)
|
||||
} else {
|
||||
// File enqueued for backend treatment
|
||||
http.Error(w, "{\"errmsg\":\"Demande d'enregistrement acceptée\"}", http.StatusAccepted)
|
||||
}
|
||||
// File enqueued for backend treatment
|
||||
http.Error(w, "{\"errmsg\":\"Demande d'enregistrement acceptée\"}", http.StatusAccepted)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue