This commit is contained in:
parent
fcb6c480eb
commit
e0286c29b8
|
|
@ -3,9 +3,10 @@ package license
|
|||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"license-server/storage"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func GenerateLicenseHandler(db storage.Database) fiber.Handler {
|
||||
|
|
@ -47,7 +48,9 @@ func ActivateLicenseHandler(db storage.Database) fiber.Handler {
|
|||
return fiber.NewError(401, "Invalid license signature")
|
||||
}
|
||||
|
||||
db.SaveActivation(req.MachineID, lf)
|
||||
licenseText := lf.Payload + "." + lf.Signature
|
||||
db.SaveActivation(req.MachineID, licenseText)
|
||||
|
||||
return c.SendString("License activated successfully.")
|
||||
}
|
||||
}
|
||||
|
|
@ -75,4 +78,3 @@ func ValidateLicenseHandler(db storage.Database) fiber.Handler {
|
|||
return c.JSON(fiber.Map{"valid": true, "features": req.Features})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package storage
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"license-server/license"
|
||||
)
|
||||
|
||||
type Database struct {
|
||||
|
|
@ -28,8 +28,7 @@ func (d Database) HasActivated(machineID string) bool {
|
|||
return err == nil && activated == 1
|
||||
}
|
||||
|
||||
func (d Database) SaveActivation(machineID string, lf license.LicenseFile) {
|
||||
func (d Database) SaveActivation(machineID string, licenseText string) {
|
||||
d.db.Exec("INSERT OR REPLACE INTO activations(machine_id, license, activated) VALUES (?, ?, 1)",
|
||||
machineID, lf.Payload+"."+lf.Signature)
|
||||
machineID, licenseText)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue