mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-05-31 06:21:04 +00:00
Wire up inja for html template processing
This commit is contained in:
parent
ce23a8dd32
commit
da74b9651c
@ -1701,16 +1701,25 @@ public:
|
|||||||
}
|
}
|
||||||
#if ZT_SSO_ENABLED
|
#if ZT_SSO_ENABLED
|
||||||
} else if (ps[0] == "sso") {
|
} else if (ps[0] == "sso") {
|
||||||
char resBuf[4096] = {0};
|
std::string htmlTemplatePath = _homePath + ZT_PATH_SEPARATOR + "sso-auth.template.html";
|
||||||
|
std::string htmlTemplate;
|
||||||
|
if (!OSUtils::readFile(htmlTemplatePath.c_str(), htmlTemplate)) {
|
||||||
|
fprintf(stderr, "ERROR: unable to read sso result template");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
responseContentType = "text/html";
|
||||||
|
json outData;
|
||||||
|
|
||||||
const char *error = zeroidc::zeroidc_get_url_param_value("error", path.c_str());
|
const char *error = zeroidc::zeroidc_get_url_param_value("error", path.c_str());
|
||||||
if (error != nullptr) {
|
if (error != nullptr) {
|
||||||
const char *desc = zeroidc::zeroidc_get_url_param_value("error_description", path.c_str());
|
const char *desc = zeroidc::zeroidc_get_url_param_value("error_description", path.c_str());
|
||||||
scode = 500;
|
scode = 500;
|
||||||
char errBuff[256] = {0};
|
|
||||||
sprintf(errBuff, "ERROR %s: %s", error, desc);
|
json data;
|
||||||
sprintf(resBuf, ssoResponseTemplate, errBuff);
|
outData["messageText"] = (std::string("ERROR ") + error + std::string(": ") + desc);
|
||||||
responseBody = std::string(resBuf);
|
responseBody = inja::render(htmlTemplate, outData);
|
||||||
responseContentType = "text/html";
|
|
||||||
return scode;
|
return scode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1731,26 +1740,24 @@ public:
|
|||||||
json ssoResult = json::parse(ret);
|
json ssoResult = json::parse(ret);
|
||||||
if (ssoResult.is_object()) {
|
if (ssoResult.is_object()) {
|
||||||
if (ssoResult.contains("errorMessage")) {
|
if (ssoResult.contains("errorMessage")) {
|
||||||
std::string errorMessage = ssoResult["errorMessage"];
|
outData["messageText"] = ssoResult["errorMessage"];
|
||||||
char errBuff[256] = {0};
|
responseBody = inja::render(htmlTemplate, outData);
|
||||||
sprintf(errBuff, "ERROR: %s", errorMessage.c_str());
|
|
||||||
sprintf(resBuf, ssoResponseTemplate, errBuff);
|
|
||||||
scode = 500;
|
scode = 500;
|
||||||
} else {
|
} else {
|
||||||
scode = 200;
|
scode = 200;
|
||||||
sprintf(resBuf, ssoResponseTemplate, "Authentication Successful. You may now access the network.");
|
outData["messageText"] = "Authentication Successful. You may now access the network.";
|
||||||
|
responseBody = inja::render(htmlTemplate, outData);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// not an object? We got a problem
|
// not an object? We got a problem
|
||||||
sprintf(resBuf, ssoResponseTemplate, "Error: Unknown SSO response.");
|
outData["messageText"] = "ERROR: Unkown SSO response. Please contact your administrator.";
|
||||||
|
responseBody = inja::render(htmlTemplate, outData);
|
||||||
scode= 500;
|
scode= 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
zeroidc::free_cstr(code);
|
zeroidc::free_cstr(code);
|
||||||
zeroidc::free_cstr(ret);
|
zeroidc::free_cstr(ret);
|
||||||
|
|
||||||
responseBody = std::string(resBuf);
|
|
||||||
responseContentType = "text/html";
|
|
||||||
return scode;
|
return scode;
|
||||||
} else {
|
} else {
|
||||||
scode = 404;
|
scode = 404;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user