1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include "master.hpp"
#include "strusCms.hpp"
#include <cppcms/service.h>
#include <cppcms/url_dispatcher.h>
#include <fstream>
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 );
}
}
|