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

@@ -50,3 +50,27 @@ ExecStart=/srv/ccsecrets/ccsecrets
WantedBy=multi-user.target
```
## API
### User Operations
#### Register
POST `/api/admin/register`
This operation can only be performed by a user with a role that is admin enabled.
#### Login
POST `/api/login`
Data
```
'{
"UserName": "",
"Password": ""
}
```
### Secrets Operations
#### Store
#### Retrieve
#### Update

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))

View File

@@ -109,11 +109,11 @@ func CreateTables() {
os.Exit(1)
}
if _, err = db.Exec("INSERT INTO roles VALUES(2, 'UserRole', false, false);"); err != nil {
fmt.Printf("Error adding initial admin role : '%s'", err)
fmt.Printf("Error adding initial user role : '%s'", err)
os.Exit(1)
}
if _, err = db.Exec("INSERT INTO roles VALUES(3, 'GuestRole', true, false);"); err != nil {
fmt.Printf("Error adding initial admin role : '%s'", err)
fmt.Printf("Error adding initial guest role : '%s'", err)
os.Exit(1)
}
}