feat(user): add user creation endpoint for superusers

- Add new `/userMgr/create` endpoint for superusers to create users with specified types
- Update AddUser function to accept user type parameter
- Add documentation for the new endpoint in api.md
- Remove debug log comment in auth.go
This commit is contained in:
2026-03-04 11:07:37 +08:00
parent d9c8695f78
commit d7260e0cf6
6 changed files with 142 additions and 11 deletions
+3 -3
View File
@@ -43,8 +43,8 @@ func isValidInput(input string) bool {
return true
}
func AddUser(username, passwd string) (int, error) { // New user registration with default type "visitor"
if !isValidInput(username) || !isValidInput(passwd) {
func AddUser(username, passwd, userType string) (int, error) { // New user registration with specified type
if !isValidInput(username) || !isValidInput(passwd) || !isValidInput(userType) {
return 0, errors.New("invalid input: contains illegal characters")
}
@@ -58,7 +58,7 @@ func AddUser(username, passwd string) (int, error) { // New user registration wi
}
result, err := db.Exec("INSERT INTO userLogin (username, passwd, type) VALUES (?, ?, ?)",
username, hashedPasswd, "visitor")
username, hashedPasswd, userType)
if err != nil {
if strings.Contains(err.Error(), "UNIQUE constraint failed") {
return 0, errors.New("username already exists")