new schema initial commit
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -16,9 +16,11 @@ import (
|
||||
)
|
||||
|
||||
type RegisterInput struct {
|
||||
UserName string `json:"userName" binding:"required"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
RoleId int `json:"roleid"`
|
||||
UserName string `json:"userName" binding:"required"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
GroupId int `json:"groupId"`
|
||||
GroupName string `json:"groupName"`
|
||||
//RoleId int `json:"roleid"`
|
||||
}
|
||||
|
||||
type LoginInput struct {
|
||||
@@ -52,7 +54,7 @@ func DeleteUser(c *gin.Context) {
|
||||
u.UserName = html.EscapeString(strings.TrimSpace(u.UserName))
|
||||
|
||||
// Confirm user account exists
|
||||
testUser, _ := models.GetUserByName(u.UserName)
|
||||
testUser, _ := models.UserGetByName(u.UserName)
|
||||
log.Printf("DeleteUser confirming user '%s' account exists\n", u.UserName)
|
||||
if (models.User{} == testUser) {
|
||||
err := errors.New("attempt to delete non-existing username '" + u.UserName + "'")
|
||||
@@ -90,23 +92,51 @@ func RegisterUser(c *gin.Context) {
|
||||
}
|
||||
|
||||
u := models.User{}
|
||||
//u.RoleId = 1
|
||||
u.UserName = input.UserName
|
||||
u.Password = input.Password
|
||||
|
||||
// Default to regular user role if not specified
|
||||
if input.RoleId == 0 {
|
||||
log.Printf("Register no role specified, defaulting to builtin role UserRole with id 2.\n")
|
||||
u.RoleId = 2
|
||||
// Determine which GroupId to save
|
||||
// Can be specified either by GroupName or GroupId in the request
|
||||
if len(input.GroupName) > 0 {
|
||||
g, err := models.GroupGetByName(input.GroupName)
|
||||
if err != nil {
|
||||
errString := fmt.Sprintf("RegisterUser error looking up group by name : '%s'", err)
|
||||
log.Println(errString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errString})
|
||||
return
|
||||
}
|
||||
if g == (models.Group{}) {
|
||||
errString := fmt.Sprintf("RegisterUser specified group not found")
|
||||
log.Println(errString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errString})
|
||||
return
|
||||
} else {
|
||||
u.GroupId = g.GroupId
|
||||
}
|
||||
} else if input.GroupId > 0 {
|
||||
u.GroupId = input.GroupId
|
||||
} else {
|
||||
u.RoleId = input.RoleId
|
||||
errString := fmt.Sprintf("RegisterUser no group specified, must specify either GroupId or GroupName")
|
||||
log.Println(errString)
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": errString})
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
// Default to regular user role if not specified
|
||||
if input.RoleId == 0 {
|
||||
log.Printf("Register no role specified, defaulting to builtin role UserRole with id 2.\n")
|
||||
u.RoleId = 2
|
||||
} else {
|
||||
u.RoleId = input.RoleId
|
||||
}
|
||||
*/
|
||||
|
||||
//remove spaces in username
|
||||
u.UserName = html.EscapeString(strings.TrimSpace(u.UserName))
|
||||
|
||||
// Check if user already exists
|
||||
testUser, _ := models.GetUserByName(u.UserName)
|
||||
testUser, _ := models.UserGetByName(u.UserName)
|
||||
log.Printf("Register checking if user '%s' already exists\n", u.UserName)
|
||||
if (models.User{} == testUser) {
|
||||
log.Printf("Register confirmed no existing username\n")
|
||||
@@ -214,7 +244,7 @@ func CurrentUser(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
u, err := models.GetUserByID(user_id)
|
||||
u, err := models.UserGetByID(user_id)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
@@ -237,7 +267,7 @@ func GetRoles(c *gin.Context) {
|
||||
}
|
||||
|
||||
func GetUsers(c *gin.Context) {
|
||||
users, err := models.QueryUsers()
|
||||
users, err := models.UserList()
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
|
Reference in New Issue
Block a user