diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2015-04-27 17:48:18 +0200 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2015-04-27 17:48:18 +0200 |
commit | fa132310bf61c115907e5c237333207f308b1de4 (patch) | |
tree | c9ac79b0818369193e3564a9fbdadb79423c29e5 | |
parent | 8ba2c0def848f72c6c817fdeb0cc220d3da0d8ee (diff) | |
download | aCms-fa132310bf61c115907e5c237333207f308b1de4.tar.gz aCms-fa132310bf61c115907e5c237333207f308b1de4.tar.bz2 |
rough scetch of register user (work in progress)
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/user.cpp | 44 | ||||
-rw-r--r-- | src/user.hpp | 1 | ||||
-rw-r--r-- | templates/confirm_register.tmpl | 23 |
4 files changed, 64 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a8b8ef0..e6cc8f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,6 +36,7 @@ set(TEMPLATES ${CMAKE_CURRENT_SOURCE_DIR}/templates/login.tmpl ${CMAKE_CURRENT_SOURCE_DIR}/templates/logout.tmpl ${CMAKE_CURRENT_SOURCE_DIR}/templates/register.tmpl + ${CMAKE_CURRENT_SOURCE_DIR}/templates/confirm_register.tmpl ) set(SRC diff --git a/src/user.cpp b/src/user.cpp index 4fd2499..dddde30 100644 --- a/src/user.cpp +++ b/src/user.cpp @@ -76,7 +76,7 @@ void user::confirm_register( ) if( request( ).request_method( ) == "POST" ) { c.confirm_register.load( context( ) ); if( c.confirm_register.validate( ) ) { - response( ).set_redirect_header( cms.root( ) + "/intro" ); + response( ).set_redirect_header( cms.root( ) + "/login" ); } } render( "confirm_register", c ); @@ -116,6 +116,22 @@ bool user::check_login( std::string user, std::string password ) return true; } +bool user::user_exists( std::string user ) +{ + if( user.empty( ) ) { + return false; + } + + cppdb::session sql( cms.conn ); + cppdb::result r; + r = sql << "SELECT username FROM user WHERE username=?" << user << cppdb::row; + if( r.empty( ) ) { + return false; + } + + return true; +} + void user::ini( content::user &c ) { master::ini( c ); @@ -181,7 +197,7 @@ register_user_form::register_user_form( apps::strusCms &cms ) cms( cms ) { username.message( "Your login" ); - username.error_message( "The login is illegal" ); + username.error_message( "Your login is illegal" ); password.message( "Your password" ); password.error_message( "Your password is illegal" ); password2.message( "Your password (again)" ); @@ -208,12 +224,28 @@ bool register_user_form::validate( ) return false; } + if( cms.user.user_exists( username.value( ) ) ) { + username.valid( false ); + password.valid( false ); + username.error_message( "Username is taken" ); + booster::ptime::sleep( booster::ptime( 5, 0 ) ); + return false; + } + + if( password.value( ).compare( password2.value( ) ) != 0 ) { + password.valid( false ); + password2.valid( false ); + password2.error_message( "Passwords didn't match" ); + booster::ptime::sleep( booster::ptime( 5, 0 ) ); + return false; + } + if( captcha.value( ).compare( cms.user.last_captcha ) != 0 ) { captcha.valid( false ); captcha.clear( ); return false; } - + return true; } @@ -223,9 +255,8 @@ confirm_register_form::confirm_register_form( apps::strusCms &cms ) : cppcms::form( ), cms( cms ) { - code.message( "Enter the code you received by email" ); code.error_message( "The code you provided is not correct" ); - submit.value( "Log in" ); + submit.value( "Verify" ); add( code ); add( submit ); @@ -239,6 +270,9 @@ bool confirm_register_form::validate( ) return false; } + // TODO: check code supplied against code in the DB, this is a + // method in the user class + //~ if( !cms.user.check_code( code.value( ) ) ) { //~ code.valid( false ); //~ booster::ptime::sleep( booster::ptime( 5, 0 ) ); diff --git a/src/user.hpp b/src/user.hpp index 2f557a9..633af60 100644 --- a/src/user.hpp +++ b/src/user.hpp @@ -11,6 +11,7 @@ class user : public master { public: user( strusCms &cms ); bool check_login( std::string user, std::string password ); + bool user_exists( std::string user ); public: std::string last_captcha; diff --git a/templates/confirm_register.tmpl b/templates/confirm_register.tmpl new file mode 100644 index 0000000..8b41290 --- /dev/null +++ b/templates/confirm_register.tmpl @@ -0,0 +1,23 @@ +<% c++ #include "user_content.hpp" %> +<% skin view %> +<% view confirm_register uses content::user extends master %> + +<% template title() %> + <% include master::title() %> :: Registration code verification +<% end %> + +<% template page_content() %> + <div> + You should receive an email containing a code soon. Enter it below: + <form method="post" action=""><% csrf %> + <table> + <% form as_table confirm_register %> + </table> + </form> + + If you entered the correct code, you can try to log in. + </div> +<% end template %> + +<% end view %> +<% end skin %> |