updates
This commit is contained in:
24
README.md
24
README.md
@@ -50,3 +50,27 @@ ExecStart=/srv/ccsecrets/ccsecrets
|
|||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
```
|
```
|
||||||
## API
|
## 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
|
@@ -16,6 +16,7 @@ import (
|
|||||||
type RegisterInput struct {
|
type RegisterInput struct {
|
||||||
Username string `json:"username" binding:"required"`
|
Username string `json:"username" binding:"required"`
|
||||||
Password string `json:"password" binding:"required"`
|
Password string `json:"password" binding:"required"`
|
||||||
|
RoleId int `json:"roleid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoginInput struct {
|
type LoginInput struct {
|
||||||
@@ -32,10 +33,18 @@ func Register(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
u := models.User{}
|
u := models.User{}
|
||||||
u.RoleId = 1
|
//u.RoleId = 1
|
||||||
u.UserName = input.Username
|
u.UserName = input.Username
|
||||||
u.Password = input.Password
|
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
|
//remove spaces in username
|
||||||
u.UserName = html.EscapeString(strings.TrimSpace(u.UserName))
|
u.UserName = html.EscapeString(strings.TrimSpace(u.UserName))
|
||||||
|
|
||||||
|
@@ -109,11 +109,11 @@ func CreateTables() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if _, err = db.Exec("INSERT INTO roles VALUES(2, 'UserRole', false, false);"); err != nil {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if _, err = db.Exec("INSERT INTO roles VALUES(3, 'GuestRole', true, false);"); err != nil {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user