mirror of
https://gitlab.com/comunic/comunicterm
synced 2024-11-16 10:31:06 +00:00
57 lines
1.2 KiB
C++
57 lines
1.2 KiB
C++
#include "accounthelper.h"
|
|
|
|
#include "../api_request.h"
|
|
|
|
using namespace std;
|
|
|
|
int AccountHelper::mUserID = -1;
|
|
string AccountHelper::mToken1;
|
|
string AccountHelper::mToken2;
|
|
|
|
|
|
AccountHelper::AccountHelper()
|
|
{
|
|
|
|
}
|
|
|
|
LoginResult AccountHelper::Login(const std::string &email, const std::string &pass)
|
|
{
|
|
auto request = ApiRequest("user/connectUSER", false);
|
|
request.addArg("userMail", email);
|
|
request.addArg("userPassword", pass);
|
|
|
|
const auto result = request.exec();
|
|
|
|
// Check for error
|
|
switch (result.code()) {
|
|
case 401:
|
|
return LoginResult::BAD_PASSWORD;
|
|
case 429:
|
|
return LoginResult::TOO_MANY_ATTEMPTS;
|
|
case 200:
|
|
break;
|
|
default:
|
|
return LoginResult::ERROR;
|
|
}
|
|
|
|
// Save the tokens
|
|
const auto tokens = result.object().at("tokens").as_object();
|
|
AccountHelper::mToken1 = tokens.at("token1").as_string();
|
|
AccountHelper::mToken2 = tokens.at("token2").as_string();
|
|
|
|
return SUCCESS;
|
|
}
|
|
|
|
int AccountHelper::userID()
|
|
{
|
|
return mUserID;
|
|
}
|
|
|
|
vector<string> AccountHelper::loginTokens()
|
|
{
|
|
auto tokens = vector<string>();
|
|
tokens.push_back(AccountHelper::mToken1);
|
|
tokens.push_back(AccountHelper::mToken2);
|
|
return tokens;
|
|
}
|