Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/issue5722-malformed-keys' into v…
Browse files Browse the repository at this point in the history
…1.8.6
  • Loading branch information
Jerry (Xinyu Hou) authored and Andrew Nelless committed Nov 11, 2016
2 parents 265cc5c + 24a5482 commit 7c12608
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/gui/src/ActivationDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ void ActivationDialog::accept()

std::pair<bool, QString> result;
try {
QString serialKey = ui->m_pTextEditSerialKey->toPlainText().trimmed();
SerialKey serialKey (ui->m_pTextEditSerialKey->toPlainText().
trimmed().toStdString());
result = m_LicenseManager->setSerialKey(serialKey);
}
catch (std::exception& e) {
Expand Down
2 changes: 1 addition & 1 deletion src/gui/src/AppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void AppConfig::loadSettings()
m_ActivateEmail = settings().value("activateEmail", "").toString();
m_CryptoEnabled = settings().value("cryptoEnabled", true).toBool();
m_AutoHide = settings().value("autoHide", false).toBool();
m_Serialkey = settings().value("serialKey", "").toString();
m_Serialkey = settings().value("serialKey", "").toString().trimmed();
m_lastVersion = settings().value("lastVersion", "Unknown").toString();
m_LastExpiringWarningTime = settings().value("lastExpiringWarningTime", 0).toInt();
m_ActivationHasRun = settings().value("activationHasRun", false).toBool();
Expand Down
14 changes: 10 additions & 4 deletions src/gui/src/LicenseManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ LicenseManager::LicenseManager(AppConfig* appConfig) :
}

std::pair<bool, QString>
LicenseManager::setSerialKey(QString serialKeyString, bool acceptExpired)
LicenseManager::setSerialKey(SerialKey serialKey, bool acceptExpired)
{
std::pair<bool, QString> ret (true, "");
time_t currentTime = ::time(0);
SerialKey serialKey (serialKeyString.toStdString());

if (!acceptExpired && serialKey.isExpired(currentTime)) {
ret.first = false;
Expand All @@ -44,7 +43,8 @@ LicenseManager::setSerialKey(QString serialKeyString, bool acceptExpired)
if (serialKey != m_serialKey) {
using std::swap;
swap (serialKey, m_serialKey);
m_AppConfig->setSerialKey(serialKeyString);
m_AppConfig->setSerialKey(QString::fromStdString
(serialKey.toString()));
emit serialKeyChanged(m_serialKey);

if (serialKey.isTrial()) {
Expand Down Expand Up @@ -114,7 +114,13 @@ LicenseManager::serialKey() const
void LicenseManager::refresh()
{
if (!m_AppConfig->serialKey().isEmpty()) {
setSerialKey(m_AppConfig->serialKey(), true);
try {
SerialKey serialKey (m_AppConfig->serialKey().toStdString());
setSerialKey(serialKey, true);
} catch (...) {
m_AppConfig->clearSerialKey();
m_AppConfig->saveSettings();
}
}
if (m_serialKey.isExpired(::time(0))) {
emit endTrial(true);
Expand Down
3 changes: 2 additions & 1 deletion src/gui/src/LicenseManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class LicenseManager: public QObject

public:
LicenseManager(AppConfig* appConfig);
std::pair<bool, QString> setSerialKey(QString serialKey, bool acceptExpired = false);
std::pair<bool, QString> setSerialKey(SerialKey serialKey,
bool acceptExpired = false);
void refresh();
Edition activeEdition() const;
QString activeEditionName() const;
Expand Down

0 comments on commit 7c12608

Please sign in to comment.