mirror of
https://gitlab.com/comunic/comunicwatcher
synced 2024-10-22 22:53:24 +00:00
43 lines
929 B
C++
43 lines
929 B
C++
|
#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;
|
||
|
}
|
||
|
|
||
|
});
|
||
|
}
|