Skip to main content

max / makenotwork

1.7 KB · 51 lines History Blame Raw
1 //! License key and activation models.
2
3 use chrono::{DateTime, Utc};
4 use serde::Serialize;
5 use sqlx::FromRow;
6
7 use super::super::id_types::*;
8 use super::super::validated_types::*;
9
10 /// A license key issued to a buyer for software activation.
11 #[derive(Debug, Clone, FromRow, Serialize)]
12 pub struct DbLicenseKey {
13 /// Database primary key.
14 pub id: LicenseKeyId,
15 /// Item this key grants access to.
16 pub item_id: ItemId,
17 /// User who owns this key.
18 pub owner_id: UserId,
19 /// Transaction that generated this key (if any).
20 pub transaction_id: Option<TransactionId>,
21 /// The key code (word-word-word-word-word format).
22 pub key_code: KeyCode,
23 /// Maximum allowed activations (NULL = unlimited).
24 pub max_activations: Option<i32>,
25 /// Current number of active activations.
26 pub activation_count: i32,
27 /// When the key was revoked (None = active).
28 pub revoked_at: Option<DateTime<Utc>>,
29 /// When the key was created.
30 pub created_at: DateTime<Utc>,
31 }
32
33 /// A machine activation for a license key.
34 #[derive(Debug, Clone, FromRow, Serialize)]
35 pub struct DbLicenseActivation {
36 /// Database primary key.
37 pub id: LicenseActivationId,
38 /// License key this activation belongs to.
39 pub license_key_id: LicenseKeyId,
40 /// Opaque machine identifier from calling software.
41 pub machine_id: String,
42 /// Optional friendly name for this machine.
43 pub label: Option<String>,
44 /// When this activation was created.
45 pub activated_at: DateTime<Utc>,
46 /// When this activation was last validated.
47 pub last_validated_at: DateTime<Utc>,
48 /// Whether this activation is currently active.
49 pub is_active: bool,
50 }
51