本文整理汇总了C++中HTTPServerRequest::hasCredentials方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerRequest::hasCredentials方法的具体用法?C++ HTTPServerRequest::hasCredentials怎么用?C++ HTTPServerRequest::hasCredentials使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPServerRequest
的用法示例。
在下文中一共展示了HTTPServerRequest::hasCredentials方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isValidRequest
//------------------------------------------------------------------------------
bool ofxWebServerBaseRouteHandler::isValidRequest(const Settings& settings,
HTTPServerRequest& request,
HTTPServerResponse& response) {
string sessionId = "";
// extract cookie from request
NameValueCollection cookies;
request.getCookies(cookies);
NameValueCollection::ConstIterator it = cookies.find(settings.sessionCookieName);
if (it != cookies.end()) {
sessionId = it->second;
} else {
sessionId = ofxWebServerSessionManager::generateSessionKey(request);
HTTPCookie cookie(settings.sessionCookieName,sessionId);
cookie.setPath("/");
// set no age, so it expires @ end of session
response.addCookie(cookie);
}
// TODO: update session manager
URI uri(request.getURI());
const string path = uri.getPath(); // just get the path
if(settings.requireAuthentication) {
if(request.hasCredentials()) {
HTTPBasicCredentials credentials(request);
const string& user = credentials.getUsername();
const string& pwd = credentials.getPassword();
if(settings.username == credentials.getUsername() &&
settings.password == credentials.getPassword()) {
// add an authentication cookie?
return true;
} else {
response.setStatusAndReason(HTTPResponse::HTTP_UNAUTHORIZED);
sendErrorResponse(response);
return false;
}
} else {
response.requireAuthentication(settings.realm);
response.setContentLength(0);
response.send();
return false;
}
} else {
return true;
}
}