Backend: handle registration
This commit is contained in:
parent
1d8f9b0785
commit
d30b4946b3
2 changed files with 43 additions and 2 deletions
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