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:
+3
-3
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user