mirror of
https://github.com/Dvorinka/PPve.git
synced 2026-06-03 20:12:59 +00:00
Add files via upload
This commit is contained in:
@@ -97,7 +97,7 @@ func verifyToken(tokenString string) (*Claims, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AuthMiddleware verifies the JWT token in the Authorization header
|
// AuthMiddleware verifies the JWT token in the Authorization header
|
||||||
func authMiddleware(next http.Handler) http.Handler {
|
func AuthMiddleware(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Get token from Authorization header
|
// Get token from Authorization header
|
||||||
authHeader := r.Header.Get("Authorization")
|
authHeader := r.Header.Get("Authorization")
|
||||||
@@ -126,7 +126,7 @@ func authMiddleware(next http.Handler) http.Handler {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func loginHandler(w http.ResponseWriter, r *http.Request) {
|
func LoginHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
http.Error(w, `{"error":"Method not allowed"}`, http.StatusMethodNotAllowed)
|
http.Error(w, `{"error":"Method not allowed"}`, http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -54,11 +54,11 @@ func main() {
|
|||||||
}).Methods("GET", "OPTIONS")
|
}).Methods("GET", "OPTIONS")
|
||||||
|
|
||||||
// Authentication routes
|
// Authentication routes
|
||||||
r.HandleFunc("/api/login", loginHandler).Methods("POST", "OPTIONS")
|
r.HandleFunc("/api/login", LoginHandler).Methods("POST", "OPTIONS")
|
||||||
|
|
||||||
// Protected API routes
|
// Protected API routes
|
||||||
api := r.PathPrefix("/api").Subrouter()
|
api := r.PathPrefix("/api").Subrouter()
|
||||||
api.Use(authMiddleware)
|
api.Use(AuthMiddleware)
|
||||||
api.HandleFunc("/submit", handleSubmit).Methods("POST")
|
api.HandleFunc("/submit", handleSubmit).Methods("POST")
|
||||||
|
|
||||||
// Admin routes
|
// Admin routes
|
||||||
|
|||||||
Reference in New Issue
Block a user