mirror of
https://github.com/kaaninchen/Laterna.git
synced 2026-09-17 19:12:48 +00:00
rethought the auth system and realized that it was bullshit
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/siestaw/laterna/server/cmd/internal/db"
|
||||
"github.com/siestaw/laterna/server/cmd/utils"
|
||||
)
|
||||
|
||||
func RegisterAdminRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("POST /api/v1/admin/controllers", createController)
|
||||
}
|
||||
|
||||
func createController(w http.ResponseWriter, r *http.Request) {
|
||||
auth := r.Header.Get("Authorization")
|
||||
if !db.IsAdmin(auth) {
|
||||
utils.HTTPErrorHandling(w, r, http.StatusUnauthorized, "Invalid token")
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,12 +12,22 @@ import (
|
||||
"github.com/siestaw/laterna/server/cmd/utils"
|
||||
)
|
||||
|
||||
func RegisterUserRoutes(mux *http.ServeMux) {
|
||||
func RegisterRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /api/v1/id/{ID}", getCurrent)
|
||||
mux.HandleFunc("PUT /api/v1/id/{ID}", setCurrent)
|
||||
|
||||
mux.HandleFunc("GET /api/v1/controllers", getControllers)
|
||||
mux.HandleFunc("PUT /api/v1/controllers", setControllers)
|
||||
mux.HandleFunc("DELETE /api/v1/controllers/{id}", deleteController)
|
||||
}
|
||||
|
||||
func getCurrent(w http.ResponseWriter, r *http.Request) {
|
||||
token := r.Header.Get("Authorization")
|
||||
if !db.IsAdmin(token) {
|
||||
utils.HTTPErrorHandling(w, r, http.StatusUnauthorized, "Invalid token")
|
||||
return
|
||||
}
|
||||
|
||||
idStr := r.PathValue("ID")
|
||||
id, err := utils.IDtoInt(idStr)
|
||||
if err != nil {
|
||||
@@ -37,6 +47,12 @@ func getCurrent(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func setCurrent(w http.ResponseWriter, r *http.Request) {
|
||||
token := r.Header.Get("Authorization")
|
||||
if !db.IsAdmin(token) {
|
||||
utils.HTTPErrorHandling(w, r, http.StatusUnauthorized, "Invalid token")
|
||||
return
|
||||
}
|
||||
|
||||
idStr := r.PathValue("ID")
|
||||
id, err := utils.IDtoInt(idStr)
|
||||
if err != nil {
|
||||
@@ -76,3 +92,15 @@ func setCurrent(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(updatedState)
|
||||
defer r.Body.Close()
|
||||
}
|
||||
|
||||
func getControllers(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
func setControllers(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
func deleteController(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user