AuthService.cpp
/*
Once a user is authenticated, they may be allowed to delete an 
authorization token.
*/
Once a user is authenticated, they may be allowed to delete an
authorization token.
Once a user is authenticated they may be allowed to delete an authorization token .
void AuthService::del(HTTPRequest *request, HTTPResponse *response) {
    if (!request->isDelete()) throw ClientError::methodNotAllowed();
    int START_INDEX_ENDPOINT = 13;
    bool authKeyTokenFound   = false;
    bool authKeyBelongsUser  = false;
    User* user               = getAuthenticatedUser(request);
    string universal_resource_locator = request->getUrl();
    string auth_to_destroy            = universal_resource_locator.
                                        substr(START_INDEX_ENDPOINT);
    authKeyTokenFound = m_db->auth_tokens.count(auth_to_destroy);
    if (authKeyTokenFound) {
        authKeyBelongsUser = user == m_db->auth_tokens.find(auth_to_destroy)->second; 
        if (authKeyBelongsUser) m_db->auth_tokens.erase(auth_to_destroy);
        else throw ClientError::unauthorized(); 
    } 
    else throw ClientError::notFound();
}
void AuthService :: del ( HTTPRequest * request , HTTPResponse * response ) { if ( ! request -> isDelete ( ) ) throw ClientError :: methodNotAllowed ( ) ; int START_INDEX_ENDPOINT = 13 ; bool authKeyTokenFound = false ; bool authKeyBelongsUser = false ; User * user = getAuthenticatedUser ( request ) ; string universal_resource_locator = request -> getUrl ( ) ; string auth_to_destroy = universal_resource_locator . substr ( START_INDEX_ENDPOINT ) ; authKeyTokenFound = m_db -> auth_tokens . count ( auth_to_destroy ) ; if ( authKeyTokenFound ) { authKeyBelongsUser = user == m_db -> auth_tokens . find ( auth_to_destroy ) -> second ; if ( authKeyBelongsUser ) m_db -> auth_tokens . erase ( auth_to_destroy ) ; else throw ClientError :: unauthorized ( ) ; } else throw ClientError :: notFound ( ) ; }
Once a user is authenticated, they may be allowed to delete an
authorization token.
Once a user is authenticated they may be allowed to delete an authorization token .