diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2015-04-19 13:29:08 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2015-04-19 13:29:08 +0200 |
commit | 7fd19157644534d004a5ef4ca450fa7a3d3eb4b0 (patch) | |
tree | c9c0189d72380cdf942fb7e4a24dab43b943d8a5 | |
parent | 1543cd3d0c0e6b54440c6a895f2f283dc3688913 (diff) | |
download | aCms-7fd19157644534d004a5ef4ca450fa7a3d3eb4b0.tar.gz aCms-7fd19157644534d004a5ef4ca450fa7a3d3eb4b0.tar.bz2 |
completed login/logout
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | FINDINGS | 4 | ||||
-rw-r--r-- | media/basic-profile.css | 2 | ||||
-rw-r--r-- | src/intro.cpp | 2 | ||||
-rw-r--r-- | src/master.cpp | 10 | ||||
-rw-r--r-- | src/master.hpp | 3 | ||||
-rw-r--r-- | src/master_content.hpp | 9 | ||||
-rw-r--r-- | src/user.cpp | 16 | ||||
-rw-r--r-- | src/user.hpp | 3 | ||||
-rw-r--r-- | templates/intro.tmpl | 9 | ||||
-rw-r--r-- | templates/logout.tmpl | 24 | ||||
-rw-r--r-- | templates/master.tmpl (renamed from templates/main.tmpl) | 7 |
12 files changed, 83 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 858369a..3d07a8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,9 +24,10 @@ set( CMAKE_CXX_FLAGS "-std=c++98 -Wall -pedantic -g -Wfatal-errors -Werror -fPIC endif() set(TEMPLATES - ${CMAKE_CURRENT_SOURCE_DIR}/templates/main.tmpl + ${CMAKE_CURRENT_SOURCE_DIR}/templates/master.tmpl ${CMAKE_CURRENT_SOURCE_DIR}/templates/intro.tmpl ${CMAKE_CURRENT_SOURCE_DIR}/templates/login.tmpl + ${CMAKE_CURRENT_SOURCE_DIR}/templates/logout.tmpl ) set(SRC diff --git a/FINDINGS b/FINDINGS new file mode 100644 index 0000000..67d19b7 --- /dev/null +++ b/FINDINGS @@ -0,0 +1,4 @@ +- cmmcms: + - template parser: + - ugly: <%= session_username() %> works, <%= session_username( ) %> not, the same syntax quirk + doesn't exist for 'include' for example
\ No newline at end of file diff --git a/media/basic-profile.css b/media/basic-profile.css index 1a26de8..5ebcaf3 100644 --- a/media/basic-profile.css +++ b/media/basic-profile.css @@ -4,7 +4,7 @@ For more information, see http://andreasviklund.com/templates/basic-profile/ */
*{margin:0; padding:0;}
-body {background:#fff url(background.jpg) top center no-repeat; color:#303030; font:84% Arial,Helvetica,sans-serif; line-height:1.6em;}
+body {background:#fff top center no-repeat; color:#303030; font:84% Arial,Helvetica,sans-serif; line-height:1.6em;}
a {color:#0B0B61; text-decoration:none;}
a:hover {text-decoration:underline;}
p,ul,ol,dl {margin:0 0 30px 0;}
diff --git a/src/intro.cpp b/src/intro.cpp index bf0331d..6b91bff 100644 --- a/src/intro.cpp +++ b/src/intro.cpp @@ -17,7 +17,7 @@ intro::intro( strusCms &cms ) void intro::show( ) { content::intro c; - c.title = "strusCms"; + ini( c ); render( "intro", c ); } diff --git a/src/master.cpp b/src/master.cpp index 751bb73..95383d8 100644 --- a/src/master.cpp +++ b/src/master.cpp @@ -11,4 +11,14 @@ master::master( strusCms &cms ) { } +void master::ini( content::master &c ) +{ + c.title = "strusCms"; + if( session( ).is_set( "username" ) ) { + c.username = session( )["username" ]; + } else { + c.username = ""; + } +} + } diff --git a/src/master.hpp b/src/master.hpp index 7ef46e9..d29073e 100644 --- a/src/master.hpp +++ b/src/master.hpp @@ -1,6 +1,8 @@ #ifndef MASTER_HPP #define MASTER_HPP +#include "master_content.hpp" + #include <cppcms/application.h> namespace apps { @@ -13,6 +15,7 @@ class master : public cppcms::application { public: master( strusCms &cms ); + virtual void ini( content::master &c ); }; } diff --git a/src/master_content.hpp b/src/master_content.hpp index 7d61dcc..ff40b09 100644 --- a/src/master_content.hpp +++ b/src/master_content.hpp @@ -17,9 +17,16 @@ namespace content { struct master : public cppcms::base_content { std::string title; std::string login_link; - master( ) : cppcms::base_content( ) { + std::string logout_link; + std::string username; + + public: + master( ) : cppcms::base_content( ) + { + // TODO: ini //~ c.login_link=wi.users.login_url(); login_link = "/strusCms/login"; + logout_link = "/strusCms/logout"; } }; diff --git a/src/user.cpp b/src/user.cpp index 36ad821..c77381d 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -5,6 +5,7 @@ #include <cppcms/url_dispatcher.h> #include <cppcms/url_mapper.h> #include <cppdb/frontend.h> +#include <cppcms/session_interface.h> namespace apps { @@ -13,21 +14,34 @@ user::user( strusCms &cms ) { cms.dispatcher( ).assign( "/login", &user::login, this ); cms.mapper( ).assign( "login" ); + + cms.dispatcher( ).assign( "/logout", &user::logout, this ); + cms.mapper( ).assign( "logout" ); } void user::login( ) { content::user c( cms ); - c.title = "strusCms"; + ini( c ); if( request( ).request_method( ) == "POST" ) { c.login.load( context( ) ); if( c.login.validate( ) ) { response( ).set_redirect_header( cms.root( ) ); + session( )["username"] = c.login.username.value( ); + session( ).expose( "username" ); } } render( "login", c ); } +void user::logout( ) +{ + content::user c( cms ); + session( ).clear( ); + ini( c ); + render( "logout", c ); +} + // TODO: make this a salted hash bool user::check_login( std::string user, std::string password ) { diff --git a/src/user.hpp b/src/user.hpp index aecca71..9f35a0d 100644 --- a/src/user.hpp +++ b/src/user.hpp @@ -11,7 +11,8 @@ class user : public master { bool check_login( std::string user, std::string password ); private: - void login( ); + void login( ); + void logout( ); }; } diff --git a/templates/intro.tmpl b/templates/intro.tmpl index 99f5e92..0fd4c35 100644 --- a/templates/intro.tmpl +++ b/templates/intro.tmpl @@ -11,8 +11,13 @@ Welcome to <b>StrusCms</b>. </div> <div> - If you want to edit pages, please log in - <a href="<%= login_link %>">here</a>. + <% if not empty username %> + After oyou finished editing pages, please log out + <a href="<%= logout_link %>">here</a>. + <% else %> + If you want to edit pages, please log in + <a href="<%= login_link %>">here</a>. + <% end %> </div> <% end template %> diff --git a/templates/logout.tmpl b/templates/logout.tmpl new file mode 100644 index 0000000..2ce7816 --- /dev/null +++ b/templates/logout.tmpl @@ -0,0 +1,24 @@ +<% c++ #include "user_content.hpp" %> +<% skin view %> +<% view logout uses content::user extends master %> + +<% template title() %> + <% include master::title() %> :: Logout +<% end %> + +<% template page_content() %> + <div> + You have been logged out of the system. Thanks for using strus CMS. + </div> + + <div> + If you found bugs, report them in Github. + </div> + + <div> + Otherwise contacting the developers is possible via email directly. + </div> +<% end template %> + +<% end view %> +<% end skin %> diff --git a/templates/main.tmpl b/templates/master.tmpl index 48b6984..7330ef1 100644 --- a/templates/main.tmpl +++ b/templates/master.tmpl @@ -26,7 +26,12 @@ </div> <div id="content"> - <h2><% include title( ) %></h2> + <h2><% include title( ) %></h2> + <% if not empty username %> + <p>Logged in as <%= username %><p> + <% else %> + <p>Currently not logged in</p> + <% end %> <% include page_content( ) %> <p class="credits">© 2015 Patrick Frey<br /> |