refactor(auth): move authentication params to headers and simplify validation

- Move token and timestamp validation to HTTP headers
- Simplify ValidateTimeStamp to return boolean
- Update AddUser to use default "visitor" type
- Remove redundant timestamp and token fields from request structs
- Update API documentation to reflect header-based authentication
This commit is contained in:
2026-02-28 15:32:32 +08:00
parent 1f426f98e5
commit ff62e3e755
6 changed files with 113 additions and 134 deletions
+2 -2
View File
@@ -42,7 +42,7 @@ func isValidInput(input string) bool {
return true
}
func AddUser(username, passwd, userType string) (int, error) {
func AddUser(username, passwd string) (int, error) { // New user registration with default type "visitor"
if !isValidInput(username) || !isValidInput(passwd) {
return 0, errors.New("invalid input: contains illegal characters")
}
@@ -57,7 +57,7 @@ func AddUser(username, passwd, userType string) (int, error) {
}
result, err := db.Exec("INSERT INTO userLogin (username, passwd, type) VALUES (?, ?, ?)",
username, hashedPasswd, userType)
username, hashedPasswd, "visitor")
if err != nil {
if strings.Contains(err.Error(), "UNIQUE constraint failed") {
return 0, errors.New("username already exists")