feat: Tích hợp Bản quyền License AES-256 (OTH.Adapter), Biên bản giao ban A4, Biểu đồ tròn và Tài liệu triển khai demo
This commit is contained in:
@@ -2,12 +2,14 @@ package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"web-giao-ban-go/config"
|
||||
"web-giao-ban-go/db"
|
||||
"web-giao-ban-go/license"
|
||||
"web-giao-ban-go/logger"
|
||||
"web-giao-ban-go/updater"
|
||||
)
|
||||
@@ -28,6 +30,9 @@ func HandleGetAdminConfig(w http.ResponseWriter, r *http.Request) {
|
||||
if respCfg.Updater.Token != "" {
|
||||
respCfg.Updater.Token = "••••••••"
|
||||
}
|
||||
if respCfg.License.CryptoKey != "" {
|
||||
respCfg.License.CryptoKey = "••••••••"
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"success": true,
|
||||
@@ -78,6 +83,19 @@ func HandleSaveAdminConfig(w http.ResponseWriter, r *http.Request) {
|
||||
input.Updater.Token = enc
|
||||
}
|
||||
|
||||
// Handle License Crypto Key
|
||||
if input.License.CryptoKey == "" || input.License.CryptoKey == "••••••••" {
|
||||
input.License.CryptoKey = current.License.CryptoKey
|
||||
input.DecryptedCryptoKey = current.DecryptedCryptoKey
|
||||
} else {
|
||||
input.DecryptedCryptoKey = input.License.CryptoKey
|
||||
enc, _ := config.Encrypt(input.License.CryptoKey)
|
||||
input.License.CryptoKey = enc
|
||||
}
|
||||
if input.License.Key == "" {
|
||||
input.License.Key = current.License.Key
|
||||
}
|
||||
|
||||
if err := config.SaveConfig(&input); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
_ = json.NewEncoder(w).Encode(map[string]interface{}{"success": false, "message": "Lưu file thất bại: " + err.Error()})
|
||||
@@ -216,3 +234,55 @@ func HandleApplyUpdate(w http.ResponseWriter, r *http.Request) {
|
||||
"message": "Đã cập nhật phiên bản mới thành công! Vui lòng khởi động lại phần mềm để áp dụng.",
|
||||
})
|
||||
}
|
||||
|
||||
// GET /api/license/status
|
||||
func HandleGetLicenseStatus(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
status := license.GetStatus()
|
||||
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"success": true,
|
||||
"data": status,
|
||||
})
|
||||
}
|
||||
|
||||
// POST /api/license/activate
|
||||
func HandleActivateLicense(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
var body struct {
|
||||
Key string `json:"key"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"success": false,
|
||||
"message": "Dữ liệu JSON không hợp lệ: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
key := strings.TrimSpace(body.Key)
|
||||
if key == "" {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"success": false,
|
||||
"message": "Vui lòng nhập chuỗi key bản quyền (chỉ nhập chuỗi mã hóa DECODE)",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
info, err := license.Activate(key)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"success": false,
|
||||
"message": "Kích hoạt thất bại: " + err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"success": true,
|
||||
"message": fmt.Sprintf("Kích hoạt bản quyền thành công cho đơn vị '%s' (Mã BV: %s)!", info.TenBV, info.Mabvbh),
|
||||
"data": info,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user