-
Notifications
You must be signed in to change notification settings - Fork 22
/
FirstTimeApiAuthorisationChecker.cpp
53 lines (46 loc) · 2.56 KB
/
FirstTimeApiAuthorisationChecker.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
#include "FirstTimeApiAuthorisationChecker.h"
#include "api/ApiRequestFactory.h"
#include "api/ApiRequestException.h"
#include "api/ApiSettingsProviderInterface.h"
#include "windows/WinApiInterface.h"
using UKControllerPluginUtils::Api::ApiRequestException;
namespace UKControllerPlugin::Api {
void FirstTimeApiAuthorisationCheck(
UKControllerPluginUtils::Api::ApiSettingsProviderInterface& settingsProviderInterface,
Windows::WinApiInterface& windows)
{
ApiRequest()
.Get("authorise")
.Then([]() { LogInfo("Api authorisation check was successful."); })
.Catch([&windows, &settingsProviderInterface](const ApiRequestException& exception) {
LogWarning(
"Api authorisation check failed, status code was " +
std::to_string(static_cast<uint64_t>(exception.StatusCode())));
if (UKControllerPluginUtils::Http::IsServerError(exception.StatusCode())) {
windows.OpenMessageBox(
L"Server error whilst checking API authentication, some functionality may not work as "
"expected. If your configuration is otherwise correct, functionality will resume when the "
"service is online again.",
L"UKCP API Server Error",
MB_OK | MB_ICONWARNING);
return;
}
auto messageResponse = windows.OpenMessageBox(
L"API authentication failed. Please re-download your credentails from the VATSIM UK website "
"and click OK to try again. If this problem persists, please contact the Web Services Department.",
L"UKCP API Config Invalid",
MB_OKCANCEL | MB_ICONWARNING);
if (messageResponse == IDCANCEL || !settingsProviderInterface.Reload()) {
LogInfo("User elected not to set API key after authentication failure");
windows.OpenMessageBox(
L"You have elected not to complete API setup at this time. Some functionality of the plugin "
"may not work as expected.",
L"UKCP API Config Not Updated",
MB_OK | MB_ICONWARNING);
return;
}
FirstTimeApiAuthorisationCheck(settingsProviderInterface, windows);
})
.Await();
}
} // namespace UKControllerPlugin::Api