mirror of
https://github.com/debauchee/barrier.git
synced 2026-11-29 15:25:56 +08:00
#5657 Make SubscriptionManager backward compatible
This commit is contained in:
@@ -21,10 +21,10 @@
|
||||
/* Do not reorder these! */
|
||||
|
||||
enum Edition {
|
||||
Basic,
|
||||
Pro,
|
||||
kBasic,
|
||||
kPro,
|
||||
Trial_DO_NOT_USE_OR_THERE_WILL_BE_PAIN,
|
||||
Unregistered
|
||||
kUnregistered
|
||||
};
|
||||
|
||||
#endif // EDITIONTYPE_H
|
||||
|
||||
@@ -21,13 +21,17 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <climits>
|
||||
|
||||
using namespace std;
|
||||
|
||||
SerialKey::SerialKey():
|
||||
m_warnTime(1),
|
||||
m_expireTime(1),
|
||||
m_trial(true)
|
||||
SerialKey::SerialKey(Edition edition):
|
||||
m_userLimit(1),
|
||||
m_warnTime(ULLONG_MAX),
|
||||
m_expireTime(ULLONG_MAX),
|
||||
m_edition(edition),
|
||||
m_trial(false),
|
||||
m_valid(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,13 +39,13 @@ SerialKey::SerialKey(std::string serial) :
|
||||
m_userLimit(1),
|
||||
m_warnTime(0),
|
||||
m_expireTime(0),
|
||||
m_edition(Edition::Basic),
|
||||
m_edition(Edition::kBasic),
|
||||
m_trial(true),
|
||||
m_valid(false)
|
||||
{
|
||||
string plainText = decode(serial);
|
||||
if (!plainText.empty()) {
|
||||
parse(serial);
|
||||
parse(plainText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +74,7 @@ SerialKey::isExpiring(time_t currentTime) const
|
||||
bool result = false;
|
||||
|
||||
if (m_valid) {
|
||||
if (m_warnTime < currentTime && currentTime < m_expireTime) {
|
||||
if (m_warnTime <= currentTime && currentTime < m_expireTime) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
@@ -84,7 +88,7 @@ SerialKey::isExpired(time_t currentTime) const
|
||||
bool result = false;
|
||||
|
||||
if (m_valid) {
|
||||
if (currentTime > m_expireTime) {
|
||||
if (m_expireTime <= currentTime) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
@@ -108,7 +112,7 @@ time_t
|
||||
SerialKey::daysLeft(time_t currentTime) const
|
||||
{
|
||||
unsigned long long timeLeft = 0;
|
||||
if (m_expireTime > currentTime) {
|
||||
if (currentTime < m_expireTime) {
|
||||
timeLeft = m_expireTime - currentTime;
|
||||
}
|
||||
|
||||
@@ -170,12 +174,13 @@ SerialKey::parse(std::string plainSerial)
|
||||
parts.push_back(plainSerial.substr(start, pos - start));
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
|
||||
if ((parts.size() == 8)
|
||||
&& (parts.at(0).find("v1") != string::npos)) {
|
||||
// e.g.: {v1;basic;Bob;1;email;company name;1398297600;1398384000}
|
||||
m_edition = getEdition(parts.at(1));
|
||||
m_name = parts.at(2);
|
||||
m_trial = false;
|
||||
sscanf(parts.at(3).c_str(), "%d", &m_userLimit);
|
||||
m_email = parts.at(4);
|
||||
m_company = parts.at(5);
|
||||
@@ -202,9 +207,9 @@ SerialKey::parse(std::string plainSerial)
|
||||
Edition
|
||||
SerialKey::getEdition(std::string editionStr)
|
||||
{
|
||||
Edition e = Edition::Basic;
|
||||
Edition e = Edition::kBasic;
|
||||
if (editionStr == "pro") {
|
||||
e = Edition::Pro;
|
||||
e = Edition::kPro;
|
||||
}
|
||||
|
||||
return e;
|
||||
|
||||
@@ -26,9 +26,10 @@
|
||||
#endif
|
||||
|
||||
class SerialKey {
|
||||
friend bool operator== (SerialKey const&, SerialKey const&);
|
||||
public:
|
||||
SerialKey();
|
||||
SerialKey(std::string serial);
|
||||
explicit SerialKey(Edition edition = Edition::kUnregistered);
|
||||
explicit SerialKey(std::string serial);
|
||||
|
||||
bool isValid(time_t currentTime) const;
|
||||
bool isExpiring(time_t currentTime) const;
|
||||
@@ -68,7 +69,15 @@ private:
|
||||
|
||||
inline bool
|
||||
operator== (SerialKey const& lhs, SerialKey const& rhs) {
|
||||
return (lhs.edition() == rhs.edition());
|
||||
return (lhs.m_name == rhs.m_name) &&
|
||||
(lhs.m_email == rhs.m_email) &&
|
||||
(lhs.m_company == rhs.m_company) &&
|
||||
(lhs.m_userLimit == rhs.m_userLimit) &&
|
||||
(lhs.m_warnTime == rhs.m_warnTime) &&
|
||||
(lhs.m_expireTime == rhs.m_expireTime) &&
|
||||
(lhs.m_edition == rhs.m_edition) &&
|
||||
(lhs.m_trial == rhs.m_trial) &&
|
||||
(lhs.m_valid == rhs.m_valid);
|
||||
}
|
||||
|
||||
inline bool
|
||||
|
||||
Reference in New Issue
Block a user