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