Merge teachers and students into one table
Using the AccountType attribute to store the user type
This commit is contained in:
parent
1205572f1e
commit
e13e9e2019
|
@ -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
|
||||
}
|
||||
_, err := db.Exec(dynStmt, newuser.Name, newuser.Surname1, newuser.Surname2, newuser.Email, secret)
|
||||
c.String(http.StatusNotFound, "Invalid account type\n")
|
||||
return
|
||||
}
|
||||
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) {
|
||||
|
|
|
@ -7,5 +7,5 @@ type user struct {
|
|||
Surname2 string `json:"apellido2"`
|
||||
Email string `json:"email"`
|
||||
Password string `json:"password"`
|
||||
IsTeacher bool `json:"esprofesor"`
|
||||
AccountType string `json:"type"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue