- Kompletna Go implementacija licencnog servera (19 Go fajlova) - Klijentski API: activate, deactivate, validate - Admin API: CRUD licence, stats, audit log - Admin dashboard: htmx + Go templates - RSA-2048 potpisivanje licencnih podataka - Rate limiting i API key autentifikacija - MySQL migracije i seed podaci (ESIR, ARV, LIGHT_TICKET) - Unit testovi: keygen, crypto, model, middleware (24 testa) - Dokumentacija: SPEC.md, ARCHITECTURE.md, SETUP.md, API.md, TESTING.md, README.md Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package handler
|
|
|
|
import (
|
|
"dal-license-server/internal/model"
|
|
"dal-license-server/internal/service"
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
type ClientHandler struct {
|
|
activation *service.ActivationService
|
|
}
|
|
|
|
func NewClientHandler(activation *service.ActivationService) *ClientHandler {
|
|
return &ClientHandler{activation: activation}
|
|
}
|
|
|
|
func (h *ClientHandler) Activate(w http.ResponseWriter, r *http.Request) {
|
|
var req model.ActivateRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
writeError(w, http.StatusBadRequest, "INVALID_REQUEST", "Neispravan zahtev")
|
|
return
|
|
}
|
|
|
|
if req.LicenseKey == "" || req.MachineFingerprint == "" {
|
|
writeError(w, http.StatusBadRequest, "INVALID_REQUEST", "license_key i machine_fingerprint su obavezni")
|
|
return
|
|
}
|
|
|
|
resp, err := h.activation.Activate(&req, clientIP(r))
|
|
if err != nil {
|
|
writeLicenseError(w, err)
|
|
return
|
|
}
|
|
|
|
writeJSON(w, http.StatusOK, resp)
|
|
}
|
|
|
|
func (h *ClientHandler) Deactivate(w http.ResponseWriter, r *http.Request) {
|
|
var req model.DeactivateRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
writeError(w, http.StatusBadRequest, "INVALID_REQUEST", "Neispravan zahtev")
|
|
return
|
|
}
|
|
|
|
resp, err := h.activation.Deactivate(&req, clientIP(r))
|
|
if err != nil {
|
|
writeLicenseError(w, err)
|
|
return
|
|
}
|
|
|
|
writeJSON(w, http.StatusOK, resp)
|
|
}
|
|
|
|
func (h *ClientHandler) Validate(w http.ResponseWriter, r *http.Request) {
|
|
var req model.ValidateRequest
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
writeError(w, http.StatusBadRequest, "INVALID_REQUEST", "Neispravan zahtev")
|
|
return
|
|
}
|
|
|
|
resp, err := h.activation.Validate(&req, clientIP(r))
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "INTERNAL_ERROR", "Greska pri validaciji")
|
|
return
|
|
}
|
|
|
|
writeJSON(w, http.StatusOK, resp)
|
|
}
|