feat: добавить веб-интерфейс админ-панели для управления модпаками
This commit is contained in:
@@ -50,6 +50,7 @@ func (h *Handler) RegisterRoutes(mux *http.ServeMux) {
|
||||
// Website endpoints.
|
||||
mux.HandleFunc("POST /api/web/register", h.register)
|
||||
mux.HandleFunc("POST /api/web/login", h.webLogin)
|
||||
mux.HandleFunc("GET /api/web/me", h.webMe)
|
||||
mux.HandleFunc("POST /api/web/profile/skin", h.uploadSkin)
|
||||
mux.HandleFunc("POST /api/web/profile/cape", h.uploadCape)
|
||||
mux.HandleFunc("DELETE /api/web/profile/skin", h.deleteSkin)
|
||||
@@ -429,6 +430,29 @@ func (h *Handler) authenticateRequest(w http.ResponseWriter, r *http.Request) in
|
||||
return userID
|
||||
}
|
||||
|
||||
// webMe returns the current authenticated user's info (for checking admin status in UI).
|
||||
func (h *Handler) webMe(w http.ResponseWriter, r *http.Request) {
|
||||
userID := h.authenticateRequest(w, r)
|
||||
if userID == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var username, uuid, role string
|
||||
err := h.db.Pool().QueryRow(r.Context(),
|
||||
`SELECT username, uuid, role FROM users WHERE id = $1`, userID,
|
||||
).Scan(&username, &uuid, &role)
|
||||
if err != nil {
|
||||
utils.WriteError(w, http.StatusInternalServerError, "Database error")
|
||||
return
|
||||
}
|
||||
|
||||
utils.WriteJSON(w, http.StatusOK, map[string]string{
|
||||
"username": username,
|
||||
"uuid": uuid,
|
||||
"role": role,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) launcherLatest(w http.ResponseWriter, r *http.Request) {
|
||||
osParam := r.URL.Query().Get("os")
|
||||
archParam := r.URL.Query().Get("arch")
|
||||
|
||||
Reference in New Issue
Block a user