diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2015-05-03 13:46:02 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2015-05-03 13:46:02 +0200 |
commit | 9b58f57b0cd9893a44c9d4381de4c82626242e94 (patch) | |
tree | 125034cf70cd371bb52b4db53f082def7830717b | |
parent | 399cea0f02b46d2253e5d8aa2a67e8f30271c23b (diff) | |
download | aCms-9b58f57b0cd9893a44c9d4381de4c82626242e94.tar.gz aCms-9b58f57b0cd9893a44c9d4381de4c82626242e94.tar.bz2 |
added handling for 404 cases (catch all)
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/master.cpp | 14 | ||||
-rw-r--r-- | src/master.hpp | 2 | ||||
-rw-r--r-- | src/master_content.hpp | 1 | ||||
-rw-r--r-- | src/strusCms.cpp | 8 | ||||
-rw-r--r-- | src/strusCms.hpp | 3 | ||||
-rw-r--r-- | templates/not_found_404.tmpl | 17 |
7 files changed, 43 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6626941..c1903c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ endif() set(TEMPLATES ${CMAKE_CURRENT_SOURCE_DIR}/templates/master.tmpl + ${CMAKE_CURRENT_SOURCE_DIR}/templates/not_found_404.tmpl ${CMAKE_CURRENT_SOURCE_DIR}/templates/intro.tmpl ${CMAKE_CURRENT_SOURCE_DIR}/templates/login.tmpl ${CMAKE_CURRENT_SOURCE_DIR}/templates/logout.tmpl diff --git a/src/master.cpp b/src/master.cpp index 0699051..086ebe3 100644 --- a/src/master.cpp +++ b/src/master.cpp @@ -2,6 +2,7 @@ #include "strusCms.hpp" #include <cppcms/service.h> +#include <cppcms/url_dispatcher.h> namespace apps { @@ -25,4 +26,17 @@ void master::ini( content::master &c ) c._root = cms.root( ); } +void master::register_common_pages( ) +{ + cms.dispatcher( ).assign( ".*", &master::not_found_404, this ); +} + +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 ); +} + } diff --git a/src/master.hpp b/src/master.hpp index 90bd985..520f258 100644 --- a/src/master.hpp +++ b/src/master.hpp @@ -16,6 +16,8 @@ class master : public cppcms::application { public: master( strusCms &cms ); void ini( content::master &c ); + void register_common_pages( ); + void not_found_404( ); }; } diff --git a/src/master_content.hpp b/src/master_content.hpp index 451ee7d..11eabd5 100644 --- a/src/master_content.hpp +++ b/src/master_content.hpp @@ -21,6 +21,7 @@ struct master : public cppcms::base_content { std::string register_link; std::string username; std::string _root; + std::string url; public: master( ) : cppcms::base_content( ) diff --git a/src/strusCms.cpp b/src/strusCms.cpp index 3858b32..b5e6b7b 100644 --- a/src/strusCms.cpp +++ b/src/strusCms.cpp @@ -22,8 +22,9 @@ namespace apps { strusCms::strusCms( cppcms::service &srv ) : cppcms::application( srv ), - intro( *this ), user( *this ), + intro( *this ), + master( *this ), conn( settings( ).get<std::string>( "strusCms.db_connection" ) ), mail( settings( ).get<std::string>( "strusCms.mail.server" ), settings( ).get<unsigned short>( "strusCms.mail.port" ), @@ -38,8 +39,11 @@ strusCms::strusCms( cppcms::service &srv ) cppdb::session sql( conn ); sql.once( setup_dbconnection ); - add( intro ); add( user ); + add( intro ); + add( master ); + + master.register_common_pages( ); mapper( ).root( root( ) ); } diff --git a/src/strusCms.hpp b/src/strusCms.hpp index 579b2d7..9f2bba4 100644 --- a/src/strusCms.hpp +++ b/src/strusCms.hpp @@ -15,8 +15,9 @@ class strusCms : public cppcms::application { std::string root( std::string locale_name = "" ); public: - apps::intro intro; apps::user user; + apps::intro intro; + apps::master master; std::string conn; mailer mail; diff --git a/templates/not_found_404.tmpl b/templates/not_found_404.tmpl new file mode 100644 index 0000000..4d7f4e0 --- /dev/null +++ b/templates/not_found_404.tmpl @@ -0,0 +1,17 @@ +<% c++ #include "master.hpp" %> +<% skin view %> +<% view not_found_404 uses content::master extends master %> + +<% template title() %> + <% include master::title() %> :: Not Found +<% end %> + +<% template page_content() %> + <div> + We are sorry to inform you that somebody run away with + your page at URL <%= url %>. + </div> +<% end template %> + +<% end view %> +<% end skin %> |