mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-24 13:08:49 -05:00
Jenkins compile fix
This commit is contained in:
@@ -43,24 +43,22 @@ public:
|
||||
bool isDone();
|
||||
|
||||
/* https://httpstatuses.com/ */
|
||||
static const struct Statuses {
|
||||
enum StatusCode {
|
||||
OK = 200,
|
||||
Accepted = 202,
|
||||
enum class StatusCode : int {
|
||||
OK = 200,
|
||||
Accepted = 202,
|
||||
|
||||
BadRequest = 400,
|
||||
Unauthorized = 401,
|
||||
NotAcceptable = 406,
|
||||
BadRequest = 400,
|
||||
Unauthorized = 401,
|
||||
NotAcceptable = 406,
|
||||
|
||||
NotImplemented = 501
|
||||
};
|
||||
NotImplemented = 501
|
||||
};
|
||||
private:
|
||||
bool _isAuthenticated;
|
||||
|
||||
const std::string getKey() const;
|
||||
bool authorize(const std::string key);
|
||||
nlohmann::json message(const std::string &message, const int &statusCode = Statuses::NotImplemented);
|
||||
nlohmann::json message(const std::string &message, StatusCode statusCode = StatusCode::NotImplemented);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -40,21 +40,21 @@ bool AuthorizationTopic::isDone() {
|
||||
|
||||
void AuthorizationTopic::handleJson(nlohmann::json json) {
|
||||
if (isDone()) {
|
||||
_connection->sendJson(message("Already authorized.", Statuses::OK));
|
||||
_connection->sendJson(message("Already authorized.", StatusCode::OK));
|
||||
} else {
|
||||
try {
|
||||
auto providedKey = json.at("key").get<std::string>();
|
||||
if (authorize(providedKey)) {
|
||||
_connection->sendJson(message("Authorization OK.", Statuses::Accepted));
|
||||
_connection->sendJson(message("Authorization OK.", StatusCode::Accepted));
|
||||
_connection->setAuthorized(true);
|
||||
LINFO("Client successfully authorized.");
|
||||
} else {
|
||||
_connection->sendJson(message("Invalid key", Statuses::NotAcceptable));
|
||||
_connection->sendJson(message("Invalid key", StatusCode::NotAcceptable));
|
||||
}
|
||||
} catch (const std::out_of_range& e) {
|
||||
_connection->sendJson(message("Invalid request, key must be provided.", Statuses::BadRequest));
|
||||
_connection->sendJson(message("Invalid request, key must be provided.", StatusCode::BadRequest));
|
||||
} catch (const std::domain_error& e) {
|
||||
_connection->sendJson(message("Invalid request, invalid key format.", Statuses::BadRequest));
|
||||
_connection->sendJson(message("Invalid request, invalid key format.", StatusCode::BadRequest));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -75,8 +75,8 @@ const std::string AuthorizationTopic::getKey() const {
|
||||
return "17308";
|
||||
}
|
||||
|
||||
nlohmann::json AuthorizationTopic::message(const std::string &message, const int &statusCode) {
|
||||
nlohmann::json error = {{"message", message}, {"code", statusCode}};
|
||||
nlohmann::json AuthorizationTopic::message(const std::string &message, StatusCode statusCode) {
|
||||
nlohmann::json error = {{"message", message}, {"code", static_cast<int>(statusCode)}};
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user