This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
/
AuthenticationCallbacks.cpp
61 lines (50 loc) · 1.93 KB
/
AuthenticationCallbacks.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "c/methods/callbacks/AuthenticationCallbacks.h"
std::map<u32, GenericRequestParams *> email_request_params;
std::map<u32, GenericRequestParams *> email_exchange_params;
void modioOnEmailRequested(u32 call_number, u32 response_code, nlohmann::json response_json)
{
ModioResponse response;
modioInitResponse(&response, response_json);
response.code = response_code;
email_request_params[call_number]->callback(email_request_params[call_number]->object, response);
delete email_request_params[call_number];
email_request_params.erase(call_number);
modioFreeResponse(&response);
}
void modioOnEmailExchanged(u32 call_number, u32 response_code, nlohmann::json response_json)
{
ModioResponse response;
modioInitResponse(&response, response_json);
response.code = response_code;
if (response.code == 200)
{
std::string access_token = "";
if (modio::hasKey(response_json, "access_token"))
{
access_token = response_json["access_token"];
modio::ACCESS_TOKEN = access_token;
nlohmann::json authentication_json;
authentication_json["access_token"] = access_token;
modio::writeJson(modio::getModIODirectory() + "authentication.json", authentication_json);
modioGetAuthenticatedUser(NULL, &modio::onUpdateCurrentUser);
}
else
{
modio::writeLogLine("Could not retreive access token from server.", MODIO_DEBUGLEVEL_ERROR);
response.code = 0;
}
}
email_exchange_params[call_number]->callback(email_exchange_params[call_number]->object, response);
delete email_exchange_params[call_number];
email_exchange_params.erase(call_number);
modioFreeResponse(&response);
}
void clearAuthenticationCallbackParams()
{
for (auto email_request_param : email_request_params)
delete email_request_param.second;
email_request_params.clear();
for (auto email_exchange_param : email_exchange_params)
delete email_exchange_param.second;
email_exchange_params.clear();
}