#include "master.hpp" #include "strusCms.hpp" #include #include #include namespace apps { master::master( strusCms &cms ) : application( cms.service( ) ), cms( cms ) { } void master::ini( content::master &c ) { c.title = "strusCms"; if( session( ).is_set( "username" ) ) { c.username = session( )["username" ]; } else { c.username = ""; } if( session( ).is_set( "printName" ) ) { c.printName = session( )["printName" ]; } else { c.printName = ""; } c.login_link = cms.root( ) + "/login"; c.logout_link = cms.root( ) + "/logout"; c.register_link = cms.root( ) + "/register"; c._root = cms.root( ); } void master::register_common_pages( ) { // only deliver static content here matching the static files only! cms.dispatcher( ).assign( "(" + cms.media_root( ) + "/basic-profile.css)", &master::serve_file, this, 1 ); cms.dispatcher( ).assign( "(" + cms.media_root( ) + "/images/strus_big.jpg)", &master::serve_file, this, 1 ); // some catch all redirects pointing to the main page cms.dispatcher( ).assign( "/", &master::redirect_to_master, this ); cms.dispatcher( ).assign( "", &master::redirect_to_master, this ); // everything else in an error cms.dispatcher( ).assign( ".*", &master::not_found_404, this ); } void master::serve_file( std::string file_name ) { std::ifstream f( ( "./" + file_name ).c_str( ) ); if( !f ) { not_found_404( ); return; } response( ).content_type( "application/octet-stream" ); response( ).out( ) << f.rdbuf( ); } void master::redirect_to_master( ) { response( ).set_redirect_header( cms.root( ) ); } void master::not_found_404( ) { content::master c; ini( c ); c.url = cms.request( ).script_name( ) + cms.request( ).path_info( ); render( "not_found_404", c ); } }