comunicwatcher/accounthelper.cpp

43 lines
929 B
C++
Raw Normal View History

2020-06-13 07:49:24 +00:00
#include "accounthelper.h"
#include "apirequest.h"
AccountHelper::AccountHelper()
{
}
void AccountHelper::LoginUser(const QString &email, const QString &password, const vLoginCallback cb)
{
auto req = new APIRequest("account/login");
req->addString("userMail", email);
req->addString("userPassword", password);
req->exec();
QObject::connect(req, &APIRequest::done, [=] (APIResponse res) {
QString token;
switch(res.getCode()) {
case 200:
// Save login token
token = res.getObject().value("tokens").toObject().value("token1").toString();
cb(LoginResult::SUCCESS);
break;
case 401:
cb(LoginResult::BAD_PASSWORD);
break;
case 429:
cb(LoginResult::TOO_MANY_REQUEST);
break;
default:
cb(LoginResult::ERROR);
break;
}
});
}