This commit is contained in:
2023-04-03 10:38:53 +10:00
parent 97598fe01b
commit c0c10c21a9
3 changed files with 36 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ import (
type RegisterInput struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
RoleId int `json:"roleid"`
}
type LoginInput struct {
@@ -32,10 +33,18 @@ func Register(c *gin.Context) {
}
u := models.User{}
u.RoleId = 1
//u.RoleId = 1
u.UserName = input.Username
u.Password = input.Password
// Default to regular user role if not specified
if input.RoleId == 0 {
fmt.Printf("Register no role specified, defaulting to RoleId of 2.\n")
u.RoleId = 2
} else {
u.RoleId = input.RoleId
}
//remove spaces in username
u.UserName = html.EscapeString(strings.TrimSpace(u.UserName))