Remove subscription levels; license valid = subscribed

This commit is contained in:
NeilClack
2026-08-15 00:54:24 -05:00
parent 8ca60de647
commit f14bf3e29a
19 changed files with 136 additions and 1534 deletions
+4 -47
View File
@@ -2,9 +2,8 @@
#include "db/db_keys.h"
#include "network/api_client.h"
#include <cctype>
#include <cstdlib>
#include <chrono>
#include <cstdlib>
namespace radiantwave::license {
@@ -19,9 +18,7 @@ long long nowEpochSeconds() {
Result validateStoredLicense(radiantwave::db::DatabaseManager& db,
const std::string& apiKey,
std::string* outLevelName,
std::string* outErrorMessage) {
if (outLevelName) outLevelName->clear();
if (outErrorMessage) outErrorMessage->clear();
const std::string email = db.getKV(radiantwave::db::KV_EMAIL_ADDRESS);
@@ -42,21 +39,10 @@ Result validateStoredLicense(radiantwave::db::DatabaseManager& db,
return Result::Invalid;
}
const auto& level = result.info.subscription_level;
int levelId = level.id;
if (levelId <= 0) {
// The portal may only report the level name (e.g. "Elite"). Derive the
// numeric id from the name so the Home footer and proclamation gating
// can rank the level even when the response omits the id.
levelId = subscriptionLevelIdForName(level.name);
}
db.setKV(radiantwave::db::KV_SUBSCRIPTION_LEVEL_ID,
levelId > 0 ? std::to_string(levelId) : std::string());
db.setKV(radiantwave::db::KV_SUBSCRIPTION_LEVEL_NAME, level.name);
db.setKV(radiantwave::db::KV_SUBSCRIPTION_LEVEL_DESCRIPTION, level.description);
// A successful validation is the "subscribed" flag: the license is valid
// and the subscription is active. Only the "last verified" stamp is stored
// (it drives the offline grace window).
markLicenseVerified(db);
if (outLevelName) *outLevelName = level.name;
return Result::Ok;
}
@@ -76,33 +62,4 @@ bool isLicenseWithinGracePeriod(const radiantwave::db::DatabaseManager& db) {
return nowEpochSeconds() - stamp < GRACE_PERIOD_SECONDS;
}
int subscriptionLevelIdForName(const std::string& name) {
std::string lower;
lower.reserve(name.size());
for (char c : name) {
lower.push_back(static_cast<char>(std::tolower(static_cast<unsigned char>(c))));
}
if (lower == "basic") return 1;
if (lower == "advanced") return 2;
if (lower == "elite") return 3;
return 0;
}
int getStoredSubscriptionLevelId(const radiantwave::db::DatabaseManager& db) {
const std::string raw = db.getKV(radiantwave::db::KV_SUBSCRIPTION_LEVEL_ID);
if (raw.empty()) return 0;
char* end = nullptr;
const long id = std::strtol(raw.c_str(), &end, 10);
return (end && *end == '\0' && id > 0) ? static_cast<int>(id) : 0;
}
std::string subscriptionLevelName(int levelId) {
switch (levelId) {
case 1: return "Basic";
case 2: return "Advanced";
case 3: return "Elite";
default: return "Subscription Level " + std::to_string(levelId);
}
}
} // namespace radiantwave::license