2016-12-09 08:36:18 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"path"
|
|
|
|
)
|
|
|
|
|
2016-12-30 11:45:14 +00:00
|
|
|
var allowRegistration bool = false
|
|
|
|
|
2017-11-22 00:52:08 +00:00
|
|
|
func RegistrationHandler(w http.ResponseWriter, r *http.Request, sURL []string) {
|
2016-12-30 11:45:14 +00:00
|
|
|
if !allowRegistration {
|
|
|
|
log.Printf("UNHANDLED %s registration request from %s: %s [%s]\n", r.Method, r.RemoteAddr, r.URL.Path, r.UserAgent())
|
|
|
|
http.Error(w, "{\"errmsg\":\"L'enregistrement d'équipe n'est pas permis.\"}", http.StatusForbidden)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-02-05 15:57:23 +00:00
|
|
|
teamInitialName := "-"
|
|
|
|
if t := r.Header.Get("X-FIC-Team"); t != "" {
|
|
|
|
teamInitialName = t
|
|
|
|
} else {
|
|
|
|
http.Error(w, "{\"errmsg\":\"Votre jeton d'authentification semble invalide. Contactez l'équipe serveur.\"}", http.StatusInternalServerError)
|
2017-12-21 21:18:18 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-12-09 08:36:18 +00:00
|
|
|
// Check request type and size
|
|
|
|
if r.Method != "POST" {
|
|
|
|
http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest)
|
|
|
|
return
|
2017-12-21 21:18:18 +00:00
|
|
|
} else if r.ContentLength < 0 || r.ContentLength > 4095 {
|
2016-12-09 08:36:18 +00:00
|
|
|
http.Error(w, "{\"errmsg\":\"Requête trop longue ou de taille inconnue\"}", http.StatusRequestEntityTooLarge)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-12-21 21:18:18 +00:00
|
|
|
if err := saveFile(path.Join(SubmissionDir, "_registration", teamInitialName), r); err != nil {
|
|
|
|
log.Println("Unable to open registration file:", err)
|
2016-12-09 08:36:18 +00:00
|
|
|
http.Error(w, "{\"errmsg\":\"Internal server error. Please retry in few seconds.\"}", http.StatusInternalServerError)
|
2017-11-22 00:52:08 +00:00
|
|
|
} else {
|
2017-12-21 21:18:18 +00:00
|
|
|
// File enqueued for backend treatment
|
|
|
|
http.Error(w, "{\"errmsg\":\"Demande d'enregistrement acceptée\"}", http.StatusAccepted)
|
2016-12-09 08:36:18 +00:00
|
|
|
}
|
|
|
|
}
|