2024-05-16 17:59:21 +02:00
|
|
|
package handlers
|
2024-03-13 13:28:06 +01:00
|
|
|
|
2024-05-19 23:56:53 +02:00
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"portfolio/api/service/jwt"
|
|
|
|
|
"strconv"
|
|
|
|
|
)
|
2024-03-13 13:28:06 +01:00
|
|
|
|
|
|
|
|
func CatchAllHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
w.WriteHeader(http.StatusGone)
|
|
|
|
|
_, err := w.Write([]byte("Bad endpoint"))
|
|
|
|
|
if err != nil {
|
2024-05-19 17:49:20 +02:00
|
|
|
InternalServerErrorHandler(w, err)
|
2024-03-13 13:28:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-05-19 23:56:53 +02:00
|
|
|
|
|
|
|
|
func CheckRoleHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
jwtCookie, _ := r.Cookie("jwt")
|
|
|
|
|
|
|
|
|
|
if jwtCookie != nil {
|
|
|
|
|
uid, audience, err := jwt.VerifyJWT(jwtCookie.Value)
|
|
|
|
|
if err != nil {
|
|
|
|
|
InternalServerErrorHandler(w, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
w.WriteHeader(http.StatusOK)
|
|
|
|
|
w.Write([]byte("id: " + strconv.Itoa(uid) + "\naudience: " + audience))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
w.WriteHeader(http.StatusUnprocessableEntity)
|
|
|
|
|
w.Write([]byte("Cookie not found"))
|
|
|
|
|
}
|