diff options
| author | haturatu <taro@eyes4you.org> | 2026-04-22 04:46:24 +0900 |
|---|---|---|
| committer | haturatu <taro@eyes4you.org> | 2026-04-22 04:46:24 +0900 |
| commit | 4b0271272e983fdb85d4b816cbd91f34d91a7884 (patch) | |
| tree | ad92ba661f0f9e8b16d93f333ebf43ffd331a892 /handlers/admin.go | |
| parent | d18b4f9d615d8942ff604a53be92da2c8e853635 (diff) | |
Diffstat (limited to 'handlers/admin.go')
| -rw-r--r-- | handlers/admin.go | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/handlers/admin.go b/handlers/admin.go index 8413ac9..a568ac5 100644 --- a/handlers/admin.go +++ b/handlers/admin.go @@ -11,7 +11,6 @@ import ( "encoding/json" "fmt" "net/http" - "strconv" "sync" "time" ) @@ -43,8 +42,6 @@ func AdminPageHandler(w http.ResponseWriter, r *http.Request) { } } - - // GetUsersHandler returns a list of all users with enriched information. // It uses a worker pool to calculate extra information for each user in parallel. func GetUsersHandler(w http.ResponseWriter, r *http.Request) { @@ -71,8 +68,8 @@ func GetUsersHandler(w http.ResponseWriter, r *http.Request) { time.Sleep(5 * time.Millisecond) timeSinceLogin := "N/A" - if userCopy.LastLoginAt.Valid { - timeSinceLogin = fmt.Sprintf("%.0fm ago", time.Since(userCopy.LastLoginAt.Time).Minutes()) + if userCopy.LastLoginAt != nil { + timeSinceLogin = fmt.Sprintf("%.0fm ago", time.Since(*userCopy.LastLoginAt).Minutes()) } enrichedUsers[index] = types.EnrichedUser{ @@ -103,8 +100,8 @@ func UpdateUserRoleHandler(w http.ResponseWriter, r *http.Request) { } adminUsername := adminUser.Username - id, err := strconv.ParseInt(r.URL.Path[len(config.Paths.AdminUsersAPI+"/"):len(r.URL.Path)-len("/role")], 10, 64) - if err != nil { + id := r.URL.Path[len(config.Paths.AdminUsersAPI+"/") : len(r.URL.Path)-len("/role")] + if id == "" { logging.AppLog.Warn("Invalid user ID in request", "path", r.URL.Path, "ip", ip) http.Error(w, "Invalid user ID", http.StatusBadRequest) return @@ -148,8 +145,8 @@ func DeleteUserHandler(w http.ResponseWriter, r *http.Request) { } adminUsername := adminUser.Username - id, err := strconv.ParseInt(r.URL.Path[len(config.Paths.AdminUsersAPI+"/"):], 10, 64) - if err != nil { + id := r.URL.Path[len(config.Paths.AdminUsersAPI+"/"):] + if id == "" { logging.AppLog.Warn("Invalid user ID in request", "path", r.URL.Path, "ip", ip) http.Error(w, "Invalid user ID", http.StatusBadRequest) return @@ -177,8 +174,8 @@ func SetUserActiveStatusHandler(w http.ResponseWriter, r *http.Request) { } adminUsername := adminUser.Username - id, err := strconv.ParseInt(r.URL.Path[len(config.Paths.AdminUsersAPI+"/"):len(r.URL.Path)-len("/status")], 10, 64) - if err != nil { + id := r.URL.Path[len(config.Paths.AdminUsersAPI+"/") : len(r.URL.Path)-len("/status")] + if id == "" { logging.AppLog.Warn("Invalid user ID in request", "path", r.URL.Path, "ip", ip) http.Error(w, "Invalid user ID", http.StatusBadRequest) return |
