Backend: handle registration
This commit is contained in:
parent
1d8f9b0785
commit
d30b4946b3
2 changed files with 43 additions and 2 deletions
|
@ -105,8 +105,16 @@ func treat(raw_path string) {
|
||||||
// Extract
|
// Extract
|
||||||
spath := strings.Split(strings.TrimPrefix(raw_path, SubmissionDir), "/")
|
spath := strings.Split(strings.TrimPrefix(raw_path, SubmissionDir), "/")
|
||||||
|
|
||||||
if len(spath) > 2 {
|
if len(spath) == 3 {
|
||||||
treatSubmission(raw_path, spath[1], spath[2])
|
if spath[1] == "_registration" {
|
||||||
|
treatRegistration(raw_path)
|
||||||
|
} else if team, err := fic.GetTeamByInitialName(spath[1]); err != nil {
|
||||||
|
log.Println("[ERR]", err)
|
||||||
|
} else if spath[2] == "name" {
|
||||||
|
treatRename(raw_path, team)
|
||||||
|
} else {
|
||||||
|
treatSubmission(raw_path, team, spath[2])
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Println("Invalid new file:", raw_path)
|
log.Println("Invalid new file:", raw_path)
|
||||||
}
|
}
|
||||||
|
|
33
backend/registration.go
Normal file
33
backend/registration.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"srs.epita.fr/fic-server/libfic"
|
||||||
|
)
|
||||||
|
|
||||||
|
func treatRegistration(pathname string) {
|
||||||
|
var keys map[string]string
|
||||||
|
|
||||||
|
if cnt_raw, err := ioutil.ReadFile(pathname); err != nil {
|
||||||
|
log.Println("[ERR]", err)
|
||||||
|
} else if err := json.Unmarshal(cnt_raw, &keys); err != nil {
|
||||||
|
log.Println("[ERR]", err)
|
||||||
|
} else if validTeamName(keys["name"]) {
|
||||||
|
if team, err := fic.CreateTeam(keys["name"], rand.Uint32()); err != nil {
|
||||||
|
log.Printf("[ERR] Unable to register new team %s: %s\n", keys["name"], err)
|
||||||
|
} else {
|
||||||
|
os.MkdirAll(path.Join(SubmissionDir, team.InitialName), 0777)
|
||||||
|
os.MkdirAll(path.Join(TeamsDir, team.InitialName), 0777)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := os.Remove(pathname); err != nil {
|
||||||
|
log.Println("[ERR]", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue