diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index ef832d5..9aa19ef 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -124,19 +124,23 @@ func createUser(c *gin.Context) { } secret := hashPW(newuser.Password) var dynStmt string - if newuser.IsTeacher == true { - dynStmt = `INSERT INTO profesores(nombre, apellido1, apellido2, email, password) values($1, $2, $3, $4, $5)` - } else { - dynStmt = `INSERT INTO alumnos(nombre, apellido1, apellido2, email, password) values($1, $2, $3, $4, $5)` + if newuser.AccountType != "estudiante" && newuser.AccountType != "profesor" { + if newuser.AccountType == "admin" { + c.String(http.StatusTeapot, "https://xkcd.com/327/\n") + return + } + c.String(http.StatusNotFound, "Invalid account type\n") + return } - _, err := db.Exec(dynStmt, newuser.Name, newuser.Surname1, newuser.Surname2, newuser.Email, secret) + dynStmt = `INSERT INTO usuarios(nombre, apellido1, apellido2, email, password, rol) values($1, $2, $3, $4, $5, $6)` + _, err := db.Exec(dynStmt, newuser.Name, newuser.Surname1, newuser.Surname2, newuser.Email, secret, newuser.AccountType) if err != nil { e := fmt.Sprintf("Something went wrong trying to create the user: %v\n", err) log.Print(e) c.String(http.StatusInternalServerError, e) return } - c.String(http.StatusOK, "Success!") + c.String(http.StatusOK, "Success!\n") } func getUser(c *gin.Context) { diff --git a/cmd/structs.go b/cmd/structs.go index 98d7f79..9856252 100644 --- a/cmd/structs.go +++ b/cmd/structs.go @@ -1,11 +1,11 @@ package cmd type user struct { - Id int `json:"id"` - Name string `json:"nombre"` - Surname1 string `json:"apellido1"` - Surname2 string `json:"apellido2"` - Email string `json:"email"` - Password string `json:"password"` - IsTeacher bool `json:"esprofesor"` + Id int `json:"id"` + Name string `json:"nombre"` + Surname1 string `json:"apellido1"` + Surname2 string `json:"apellido2"` + Email string `json:"email"` + Password string `json:"password"` + AccountType string `json:"type"` }