From 518b8271eda7c974443f4a8203ab6db8ae8e74e5 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 18 Apr 2015 17:43:27 +0200 Subject: playing with a login form --- CMakeLists.txt | 1 + config.js | 13 +++++++++++++ media/basic-profile.css | 1 + src/intro_content.hpp | 2 ++ src/master.hpp | 2 +- src/master_content.hpp | 6 ++++++ src/user.cpp | 30 +++++++++++++++++++++++++++++- src/user_content.hpp | 14 +++++++++++++- templates/intro.tmpl | 4 ++++ templates/login.tmpl | 18 ++++++++++++++++++ 10 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 templates/login.tmpl diff --git a/CMakeLists.txt b/CMakeLists.txt index 659dfed..a2c0a2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ find_program(MSGMERGE msgmerge) set(TEMPLATES ${CMAKE_CURRENT_SOURCE_DIR}/templates/main.tmpl ${CMAKE_CURRENT_SOURCE_DIR}/templates/intro.tmpl + ${CMAKE_CURRENT_SOURCE_DIR}/templates/login.tmpl ) set(SRC diff --git a/config.js b/config.js index 412111b..7cb125b 100644 --- a/config.js +++ b/config.js @@ -15,5 +15,18 @@ "views" : { "paths" : [ "." ], "skins" : [ "view" ] + }, + "security" : { + "csrf" : { + "enable" : true + } + }, + "session" : { + "expire" : "browser", + "location" : "client", + "client" : { + "hmac" : "sha1", + "hmac_key" : "6fe0b96a8c5ddcb8af8c377f1d3981549d4bd5c3" + } } } diff --git a/media/basic-profile.css b/media/basic-profile.css index 961c63c..1a26de8 100644 --- a/media/basic-profile.css +++ b/media/basic-profile.css @@ -29,3 +29,4 @@ h1,h2,h3 {font-weight:700; line-height:1.4em;} .credits {display:block; clear:left; font-size:0.9em; color:#aaa; margin:20px 0;} .credits a {color:#888;} .clear {clear:both;} +.cppcms_form_error {color: red;} diff --git a/src/intro_content.hpp b/src/intro_content.hpp index 16bd601..c9e498c 100644 --- a/src/intro_content.hpp +++ b/src/intro_content.hpp @@ -6,6 +6,8 @@ namespace content { struct intro : public master { + public: + intro( ) : master( ) {} }; } diff --git a/src/master.hpp b/src/master.hpp index 9da1605..7ef46e9 100644 --- a/src/master.hpp +++ b/src/master.hpp @@ -2,7 +2,7 @@ #define MASTER_HPP #include - + namespace apps { class strusCms; diff --git a/src/master_content.hpp b/src/master_content.hpp index af331d0..f924c94 100644 --- a/src/master_content.hpp +++ b/src/master_content.hpp @@ -2,6 +2,7 @@ #define MASTER_CONTENT_HPP #include +#include #include @@ -9,6 +10,11 @@ namespace content { struct master : public cppcms::base_content { std::string title; + std::string login_link; + master( ) : cppcms::base_content( ) { + //~ c.login_link=wi.users.login_url(); + login_link = "/strusCms/login"; + } }; } diff --git a/src/user.cpp b/src/user.cpp index 746e123..cc2af65 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -11,11 +11,39 @@ user::user( strusCms &cms ) : master( cms ) { cms.dispatcher( ).assign( "/login", &user::login, this ); - cms.mapper( ).assign( "/login" ); + cms.mapper( ).assign( "login" ); } void user::login( ) { + content::user c; + c.title = "strusCms"; + if( request( ).request_method( ) == "POST" ) { + c.login.load( context( ) ); + if( c.login.validate( ) ) { + } + } + render( "login", c ); } } + +namespace content { + +login_form::login_form( ) : cppcms::form( ) +{ + username.message( "Your login" ); + username.error_message( "The login name can't be empty" ); + password.message( "Your password" ); + password.error_message( "Your password is illegal" ); + submit.value( "Log in" ); + + add( username ); + add( password ); + add( submit ); + + username.non_empty( ); + password.non_empty( ); +} + +} diff --git a/src/user_content.hpp b/src/user_content.hpp index cac0755..b52d2ea 100644 --- a/src/user_content.hpp +++ b/src/user_content.hpp @@ -1,11 +1,23 @@ #ifndef USER_CONTENT_HPP #define USER_CONTENT_HPP -#include "master.hpp" +#include "master_content.hpp" + +#include namespace content { +struct login_form : public cppcms::form { + cppcms::widgets::text username; + cppcms::widgets::password password; + cppcms::widgets::submit submit; + + public: + login_form( ); +}; + struct user : public master { + login_form login; }; } diff --git a/templates/intro.tmpl b/templates/intro.tmpl index eb7fa49..99f5e92 100644 --- a/templates/intro.tmpl +++ b/templates/intro.tmpl @@ -10,6 +10,10 @@
Welcome to StrusCms.
+
+ If you want to edit pages, please log in + here. +
<% end template %> <% end view %> diff --git a/templates/login.tmpl b/templates/login.tmpl new file mode 100644 index 0000000..0082e49 --- /dev/null +++ b/templates/login.tmpl @@ -0,0 +1,18 @@ +<% c++ #include "user_content.hpp" %> +<% skin view %> +<% view login uses content::user extends master %> + +<% template title() %> + <% include master::title() %> :: Login +<% end %> + +<% template page_content() %> +
+
<% csrf %> + <% form as_p login %> +
+
+<% end template %> + +<% end view %> +<% end skin %> -- cgit v1.2.3-54-g00ecf