From c9adfbb656157401e3f08f5b0a69be970afef386 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Fri, 26 Aug 2022 23:01:19 +0000 Subject: [PATCH] More subscription stuff --- Controllers/RvrController.cs | 10 ++++- util/RavenKeyFactory.cs | 86 ++++++++++++++++++++++++++---------- wwwroot/js/app.ravLicense.js | 2 +- 3 files changed, 71 insertions(+), 27 deletions(-) diff --git a/Controllers/RvrController.cs b/Controllers/RvrController.cs index d5de643..24fa691 100644 --- a/Controllers/RvrController.cs +++ b/Controllers/RvrController.cs @@ -74,7 +74,13 @@ namespace rockfishCore.Controllers //if there is an active trial for this db then can't do this they must request we re-release it or completely zap the database instead - var MustBeOlderThan = DateUtil.DateToEpoch(DateTime.Now.AddDays((RavenKeyFactory.TRIAL_PERIOD_DAYS * -1))); + long MustBeOlderThan = 0; + if (r.Perpetual) + MustBeOlderThan = DateUtil.DateToEpoch(DateTime.Now.AddDays((RavenKeyFactory.PERPETUAL_TRIAL_PERIOD_DAYS * -1))); + else + MustBeOlderThan = DateUtil.DateToEpoch(DateTime.Now.AddHours((RavenKeyFactory.SUBSCRIPTION_TRIAL_PERIOD_HOURS * -1))); + + if (await ct.TrialRequest.Where(z => z.DbId == r.DbId && z.DtProcessed != null && z.DtProcessed > MustBeOlderThan).AnyAsync()) { return BadRequest("E1000 - Can't trial; there is already an active trial license issued for this database Id"); @@ -86,7 +92,7 @@ namespace rockfishCore.Controllers NewRequest.DbId = r.DbId; NewRequest.CompanyName = r.Company; NewRequest.ContactName = r.Contact; - NewRequest.Perpetual=r.Perpetual; + NewRequest.Perpetual = r.Perpetual; await ct.TrialRequest.AddAsync(NewRequest); await ct.SaveChangesAsync(); NewRequest.EmailConfirmCode = NewRequest.Id.ToString() + FetchKeyCode.generate(); diff --git a/util/RavenKeyFactory.cs b/util/RavenKeyFactory.cs index 25a86b8..d79359f 100644 --- a/util/RavenKeyFactory.cs +++ b/util/RavenKeyFactory.cs @@ -38,7 +38,9 @@ namespace rockfishCore.Util //Key generator controller public static class RavenKeyFactory { - public const int TRIAL_PERIOD_DAYS = 5; + public const int PERPETUAL_TRIAL_PERIOD_DAYS = 5; + public const int SUBSCRIPTION_TRIAL_PERIOD_HOURS = 48; + //Unlicensed token private const string UNLICENSED_TOKEN = "UNLICENSED"; @@ -46,9 +48,16 @@ namespace rockfishCore.Util //REVOKED token public const string REVOKED_TOKEN = "REVOKED"; - //FEATURE NAMES - //Scheduleable users - private const string SERVICE_TECHS_FEATURE_NAME = "ServiceTechs"; + //LICENSE USER COUNT FEATURES + + //PERPETUAL Scheduleable users + private const string ACTIVE_SERVICE_TECHS_FEATURE_NAME = "ServiceTechs"; + + //SUBSCRIPTION + private const string ACTIVE_INTERNAL_USERS_FEATURE_NAME = "ActiveInternalUsers"; + private const string ACTIVE_CUSTOMER_USERS_FEATURE_NAME = "ActiveCustomerUsers"; + + //Add-on's / integrations //This feature name means it's a trial key @@ -104,7 +113,7 @@ namespace rockfishCore.Util continue; } - if (f.Feature == SERVICE_TECHS_FEATURE_NAME) + if (f.Feature == ACTIVE_SERVICE_TECHS_FEATURE_NAME) { sb.AppendLine($"Scheduleable resources: {f.Count}"); continue; @@ -237,17 +246,61 @@ namespace rockfishCore.Util k.RegisteredTo = CompanyName; k.DbId = dbid; k.Perpetual = Perpetual; - //trial period time limit - k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddDays(TRIAL_PERIOD_DAYS); + //flag as trial key not regular key k.Features.Add(new LicenseFeature() { Feature = TRIAL_FEATURE_NAME, Count = 0 }); - //add every possible feature - k.Features.Add(new LicenseFeature() { Feature = SERVICE_TECHS_FEATURE_NAME, Count = 100 }); + if (Perpetual) + { + //trial period time limit + k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddDays(PERPETUAL_TRIAL_PERIOD_DAYS); + //enough techs to easily cover huge amounts of seeding (it's actually only 15 at the moment but you never know this is some buffer) + k.Features.Add(new LicenseFeature() { Feature = ACTIVE_SERVICE_TECHS_FEATURE_NAME, Count = 250 }); + } + else + { + //SUBSCRIPTION + //trial period time limit + k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddHours(SUBSCRIPTION_TRIAL_PERIOD_HOURS); + + //20k customer contacts will cover huge seeding level easily + //5k inside staff users will cover huge seeding level easily + k.Features.Add(new LicenseFeature() { Feature = ACTIVE_INTERNAL_USERS_FEATURE_NAME, Count = 5000 }); + k.Features.Add(new LicenseFeature() { Feature = ACTIVE_CUSTOMER_USERS_FEATURE_NAME, Count = 20000 }); + } return GenerateRavenKey(k); } + //TESTING ONLY this is for development purposes only + //No external usage + public static string GetRavenTestKey(string dbid, bool Perpetual) + { + //Build a sample test key, sign it and return it + AyaNovaLicenseKey k = new AyaNovaLicenseKey(); + k.LicenseFormat = "8"; + k.RegisteredTo = "GZ TestCo Inc."; + k.DbId = dbid; + k.Perpetual = Perpetual; + if (Perpetual) + { + k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddDays(PERPETUAL_TRIAL_PERIOD_DAYS); + k.Features.Add(new LicenseFeature() { Feature = ACTIVE_SERVICE_TECHS_FEATURE_NAME, Count = 250 }); + } + else + { + //SUBSCRIPTION + k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddHours(SUBSCRIPTION_TRIAL_PERIOD_HOURS); + //20k customer contacts will cover huge seeding level easily + //5k inside staff users will cover huge seeding level easily + k.Features.Add(new LicenseFeature() { Feature = ACTIVE_INTERNAL_USERS_FEATURE_NAME, Count = 5000 }); + k.Features.Add(new LicenseFeature() { Feature = ACTIVE_CUSTOMER_USERS_FEATURE_NAME, Count = 20000 }); + + } + + k.Features.Add(new LicenseFeature() { Feature = TRIAL_FEATURE_NAME, Count = 0 }); + return GenerateRavenKey(k); + } /// @@ -414,22 +467,7 @@ oArP0E2Vbow3JMxq/oeXmHbrLMLQfYyXwFmciLFigOtkd45bfHdrbA== - //this is for development purposes only - //No external usage - public static string GetRavenTestKey(string dbid, bool Perpetual) - { - //Build a sample test key, sign it and return it - AyaNovaLicenseKey k = new AyaNovaLicenseKey(); - k.LicenseFormat = "8"; - k.RegisteredTo = "GZ TestCo Inc."; - k.DbId = dbid; - k.Perpetual = Perpetual; - k.Features.Add(new LicenseFeature() { Feature = SERVICE_TECHS_FEATURE_NAME, Count = 100 }); - k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddDays(TRIAL_PERIOD_DAYS); - k.Features.Add(new LicenseFeature() { Feature = TRIAL_FEATURE_NAME, Count = 0 }); - return GenerateRavenKey(k); - } //eoc } diff --git a/wwwroot/js/app.ravLicense.js b/wwwroot/js/app.ravLicense.js index 17918ad..aa0139b 100644 --- a/wwwroot/js/app.ravLicense.js +++ b/wwwroot/js/app.ravLicense.js @@ -81,7 +81,7 @@ app.ravLicense = (function () { } else { if (!$("#licenseExpires").prop("checked")) { alert( - "Subscriptin licenses MUST have a license expiry, can not process" + "Subscription licenses MUST have a license expiry, can not process" ); return false; }