summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2015-04-18 17:43:27 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2015-04-18 17:43:27 +0200
commit518b8271eda7c974443f4a8203ab6db8ae8e74e5 (patch)
treec36baead930924d400b3486e6e0527b0c91ddb5b
parent84a3e2f6bcb4da4ab156e39d79f0f8a36c2a0e90 (diff)
downloadaCms-518b8271eda7c974443f4a8203ab6db8ae8e74e5.tar.gz
aCms-518b8271eda7c974443f4a8203ab6db8ae8e74e5.tar.bz2
playing with a login form
-rw-r--r--CMakeLists.txt1
-rw-r--r--config.js13
-rw-r--r--media/basic-profile.css1
-rw-r--r--src/intro_content.hpp2
-rw-r--r--src/master.hpp2
-rw-r--r--src/master_content.hpp6
-rw-r--r--src/user.cpp30
-rw-r--r--src/user_content.hpp14
-rw-r--r--templates/intro.tmpl4
-rw-r--r--templates/login.tmpl18
10 files changed, 88 insertions, 3 deletions
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 <cppcms/application.h>
-
+
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 <cppcms/view.h>
+#include <cppcms/form.h>
#include <string>
@@ -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 <cppcms/form.h>
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 @@
<div>
Welcome to <b>StrusCms</b>.
</div>
+ <div>
+ If you want to edit pages, please log in
+ <a href="<%= login_link %>">here</a>.
+ </div>
<% 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() %>
+ <div>
+ <form method="post" action=""><% csrf %>
+ <% form as_p login %>
+ </form>
+ </div>
+<% end template %>
+
+<% end view %>
+<% end skin %>