本文整理汇总了C++中poco::net::HTTPServerResponse::redirect方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerResponse::redirect方法的具体用法?C++ HTTPServerResponse::redirect怎么用?C++ HTTPServerResponse::redirect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类poco::net::HTTPServerResponse
的用法示例。
在下文中一共展示了HTTPServerResponse::redirect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleRequest
void ControllerRequestHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
if (request.getURI() == "/favicon.ico")
{
return response.redirect("/images/favicon.ico", Poco::Net::HTTPResponse::HTTP_SEE_OTHER);
}
Poco::OSP::Web::WebSession::Ptr pSession = _pSessionManager->get(_sessionId, request, _sessionTimeout, context());
const std::string loginPage = "/macchina/login";
const std::string launcherPage = "/macchina/launcher";
std::string message;
std::string nextPage;
std::string username;
Poco::Net::HTMLForm form(request, request.stream());
std::string action(form.get("action", ""));
if (action == "login")
{
username = form.get("username", "");
std::string password = form.get("password", "");
if (_pAuthService->authenticate(username, password))
{
if (_logger.information())
{
_logger.information(format("User %s successfully logged in.", username));
}
nextPage = launcherPage;
pSession->set("username", username);
}
else
{
if (_logger.warning())
{
_logger.warning(format("User %s failed authentication.", username));
}
message = "The given username is not known, the password is wrong or the account has been disabled.";
}
}
else if (action == "logout")
{
username = pSession->getValue<std::string>("username", "");
if (!username.empty())
{
if (_logger.information())
{
_logger.information(format("User %s logged out.", username));
}
_pSessionManager->remove(pSession);
}
}
else
{
username = pSession->getValue<std::string>("username", "");
if (!username.empty())
{
nextPage = launcherPage;
}
}
if (!message.empty())
{
pSession->set("message", message);
}
else
{
pSession->erase("message");
}
if (nextPage.empty())
{
nextPage = loginPage;
}
response.setContentLength(0);
response.redirect(nextPage, Poco::Net::HTTPResponse::HTTP_SEE_OTHER);
response.set("Cache-Control", "no-cache");
}