Notify activation when skipping or using serial #4932

This commit is contained in:
Xinyu Hou 2015-10-27 16:31:09 -07:00
parent 4d20a3ce91
commit a4c799c285
9 changed files with 56 additions and 5 deletions

View File

@ -71,6 +71,12 @@ QString CoreInterface::checkSubscription()
return run(args);
}
QString CoreInterface::notifyActivation(const QString& input)
{
QStringList args("--notify-activation");
return run(args, input);
}
QString CoreInterface::run(const QStringList& args, const QString& input)
{
QString program(

View File

@ -31,5 +31,6 @@ public:
QString getSubscriptionFilename();
QString activateSerial(const QString& serial);
QString checkSubscription();
QString notifyActivation(const QString& input);
QString run(const QStringList& args, const QString& input = "");
};

View File

@ -216,6 +216,17 @@ void SetupWizard::accept()
if (m_pRadioButtonSubscription->isChecked())
{
appConfig.setSerialKey(m_pLineEditSerialKey->text());
QString info("serial:" + hash(getFirstMacAddress()) + "\n");
CoreInterface coreInterface;
coreInterface.notifyActivation(info);
}
if (m_pRadioButtonSkip->isChecked())
{
QString info("skip:" + hash(getFirstMacAddress()) + "\n");
CoreInterface coreInterface;
coreInterface.notifyActivation(info);
}
m_MainWindow.setEdition(m_Edition);

View File

@ -94,6 +94,6 @@ QString WebClient::request(
{
QStringList args("--login-auth");
// hash password in case it contains interesting chars.
QString credentials(email + ":" + hash(password) + "\n");
QString credentials(email + ":" + hash(password) + ":" + hash(getFirstMacAddress()) + "\n");
return m_CoreInterface.run(args, credentials);
}

View File

@ -211,6 +211,10 @@ ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv)
args.m_checkSubscription = true;
return true;
}
else if (isArg(i, argc, argv, NULL, "--notify-activation", 0)) {
args.m_notifyActivation = true;
return true;
}
else {
return false;
}

View File

@ -117,6 +117,9 @@ ToolApp::run(int argc, char** argv)
return kExitSubscription;
}
}
else if (m_args.m_notifyActivation) {
notifyActivation();
}
else {
throw XSynergy("Nothing to do");
}
@ -149,14 +152,17 @@ ToolApp::loginAuth()
String credentials;
std::cin >> credentials;
size_t separator = credentials.find(':');
String email = credentials.substr(0, separator);
String password = credentials.substr(separator + 1, credentials.length());
size_t separator1 = credentials.find(':');
size_t separator2 = credentials.find(':', separator1 + 1);
String email = credentials.substr(0, separator1);
String password = credentials.substr(separator1 + 1, separator2 - separator1 - 1);
String macHash = credentials.substr(separator2 + 1, credentials.length() - separator2 - 1);
std::stringstream ss;
ss << JSON_URL << "auth/";
ss << "?email=" << ARCH->internet().urlEncode(email);
ss << "&password=" << password;
ss << "&mac=" << macHash;
ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName());
ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName());
@ -180,3 +186,23 @@ ToolApp::getPluginList()
std::cout << ARCH->internet().get(ss.str()) << std::endl;
}
void
ToolApp::notifyActivation()
{
String info;
std::cin >> info;
size_t separator = info.find(':');
String action = info.substr(0, separator);
String macHash = info.substr(separator + 1, info.length());
std::stringstream ss;
ss << JSON_URL << "notify/";
ss << "?action=" << action;
ss << "&mac=" << macHash;
ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName());
ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName());
std::cout << ARCH->internet().get(ss.str()) << std::endl;
}

View File

@ -30,6 +30,7 @@ public:
private:
void loginAuth();
void getPluginList();
void notifyActivation();
private:
ToolArgs m_args;

View File

@ -27,6 +27,7 @@ ToolArgs::ToolArgs() :
m_getArch(false),
m_getSubscriptionFilename(false),
m_checkSubscription(false),
m_notifyActivation(false),
m_subscriptionSerial()
{
}

View File

@ -33,5 +33,6 @@ public:
bool m_getArch;
bool m_getSubscriptionFilename;
bool m_checkSubscription;
bool m_notifyActivation;
String m_subscriptionSerial;
};