mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
Optional license expiry for trial purposes.
This commit is contained in:
parent
b1c6401dfd
commit
3733585ae3
@ -159,5 +159,10 @@ func licenseKeyDecode(content string) (LicenseKey, error) {
|
||||
|
||||
ret.CreatedAt = time.Unix(ret.CreatedAtInt, 0)
|
||||
|
||||
if ret.ExpiresAtInt > 0 {
|
||||
expiresAt := time.Unix(ret.ExpiresAtInt, 0)
|
||||
ret.ExpiresAt = &expiresAt
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
@ -23,18 +23,22 @@ const (
|
||||
var testTime = time.Date(2010, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||
|
||||
type LicenseKey struct {
|
||||
LicenseId string `json:"license_id"`
|
||||
CustomerId string `json:"customer_id"`
|
||||
CustomerName string `json:"customer_name"`
|
||||
Tier string `json:"tier"`
|
||||
CreatedAt time.Time `json:"-"`
|
||||
CreatedAtInt int64 `json:"created_at"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
CreatorName string `json:"creator_name"`
|
||||
CreatorEmail string `json:"creator_email"`
|
||||
LicenseId string `json:"license_id"`
|
||||
CustomerId string `json:"customer_id"`
|
||||
CustomerName string `json:"customer_name"`
|
||||
Tier string `json:"tier"`
|
||||
CreatedAt time.Time `json:"-"`
|
||||
CreatedAtInt int64 `json:"created_at"`
|
||||
ExpiresAt *time.Time `json:"-"`
|
||||
ExpiresAtInt int64 `json:"expires_at"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
CreatorName string `json:"creator_name"`
|
||||
CreatorEmail string `json:"creator_email"`
|
||||
}
|
||||
|
||||
func (this *LicenseKey) Validate() error {
|
||||
utcNow := time.Now().UTC()
|
||||
|
||||
if len(this.LicenseId) < 10 {
|
||||
return fmt.Errorf("Invalid license: License Id")
|
||||
}
|
||||
@ -51,6 +55,16 @@ func (this *LicenseKey) Validate() error {
|
||||
return fmt.Errorf("Invalid license: Created At is invalid")
|
||||
}
|
||||
|
||||
if this.ExpiresAt != nil {
|
||||
if this.CreatedAt.After(*this.ExpiresAt) {
|
||||
return fmt.Errorf("Invalid license: Created At cannot be Greater than Expires At")
|
||||
}
|
||||
|
||||
if utcNow.After(*this.ExpiresAt) {
|
||||
return fmt.Errorf("Invalid license: The license has already expired")
|
||||
}
|
||||
}
|
||||
|
||||
if len(this.CreatorName) < 1 {
|
||||
return fmt.Errorf("Invalid license: Creator name")
|
||||
}
|
||||
@ -84,6 +98,13 @@ func (this *LicenseKey) ToString() string {
|
||||
str += fmt.Sprintf("Customer Name: %s\n", this.CustomerName)
|
||||
str += fmt.Sprintf("Tier: %s\n", this.Tier)
|
||||
str += fmt.Sprintf("Created At: %s\n", common.UtcTimeFormat(this.CreatedAt))
|
||||
|
||||
if this.ExpiresAt == nil {
|
||||
str += fmt.Sprintf("Expires At: Never\n")
|
||||
} else {
|
||||
str += fmt.Sprintf("Expires At: %s\n", common.UtcTimeFormat(*this.ExpiresAt))
|
||||
}
|
||||
|
||||
str += fmt.Sprintf("Creator: %s <%s>\n", this.CreatorName, this.CreatorEmail)
|
||||
return str
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user