summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2015-04-29 18:58:07 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2015-04-29 18:58:07 +0200
commitcb69299b9d59db0888e942025ae4915c6f32d066 (patch)
treefcb85301442a9eda1ed9d60a8ba52d8c60f11114 /src
parentfa132310bf61c115907e5c237333207f308b1de4 (diff)
downloadaCms-cb69299b9d59db0888e942025ae4915c6f32d066.tar.gz
aCms-cb69299b9d59db0888e942025ae4915c6f32d066.tar.bz2
added libquickmail and email registration
Diffstat (limited to 'src')
-rw-r--r--src/mail.cpp39
-rw-r--r--src/mail.hpp29
-rw-r--r--src/strusCms.cpp8
-rw-r--r--src/strusCms.hpp3
-rw-r--r--src/user.cpp10
-rw-r--r--src/user_content.hpp1
6 files changed, 88 insertions, 2 deletions
diff --git a/src/mail.cpp b/src/mail.cpp
new file mode 100644
index 0000000..84e1210
--- /dev/null
+++ b/src/mail.cpp
@@ -0,0 +1,39 @@
+#include "mail.hpp"
+
+#include <iostream>
+
+mailer::mailer( std::string server, unsigned short port, std::string username, std::string password, std::string from )
+ : server( server ), port( port ), username( username ), password( password ), from( from )
+{
+ quickmail_initialize( );
+ mailobj = quickmail_create( NULL, NULL );
+}
+
+mailer::~mailer( )
+{
+ quickmail_destroy( mailobj );
+}
+
+void mailer::send( )
+{
+ if( !from.empty( ) ) {
+ quickmail_set_from( mailobj, from.c_str( ) );
+ }
+
+ if( !to.empty( ) ) {
+ quickmail_add_to( mailobj, to.c_str( ) );
+ }
+
+ if( !subject.empty( ) ) {
+ quickmail_set_subject( mailobj, subject.c_str( ) );
+ }
+
+ if( !body.empty( ) ) {
+ quickmail_add_body_memory( mailobj, "plain/text", const_cast<char *>( body.c_str( ) ), body.size( ), 0 );
+ }
+
+ const char *errmsg;
+ errmsg = quickmail_send( mailobj, server.c_str( ), port, username.c_str( ), password.c_str( ) );
+ std::cerr << "ERROR: " << errmsg << std::endl;
+}
+
diff --git a/src/mail.hpp b/src/mail.hpp
new file mode 100644
index 0000000..c9bd8ef
--- /dev/null
+++ b/src/mail.hpp
@@ -0,0 +1,29 @@
+#ifndef MAIL_HPP
+#define MAIL_HPP
+
+#include <string>
+
+#include "quickmail.h"
+
+class mailer {
+ private:
+ std::string server;
+ unsigned short port;
+ std::string username;
+ std::string password;
+ std::string from;
+ quickmail mailobj;
+
+ public:
+ std::string to;
+ std::string subject;
+ std::string body;
+
+ public:
+ mailer( std::string server, unsigned short port, std::string username, std::string password, std::string from );
+ ~mailer( );
+ void send( );
+};
+
+
+#endif
diff --git a/src/strusCms.cpp b/src/strusCms.cpp
index e5792ec..137a209 100644
--- a/src/strusCms.cpp
+++ b/src/strusCms.cpp
@@ -10,7 +10,13 @@ strusCms::strusCms( cppcms::service &srv )
: cppcms::application( srv ),
intro( *this ),
user( *this ),
- conn( settings( ).get<std::string>( "strusCms.db_connection" ) )
+ conn( settings( ).get<std::string>( "strusCms.db_connection" ) ),
+ mail( settings( ).get<std::string>( "strusCms.mail.server" ),
+ settings( ).get<unsigned short>( "strusCms.mail.port" ),
+ settings( ).get<std::string>( "strusCms.mail.username" ),
+ settings( ).get<std::string>( "strusCms.mail.password" ),
+ settings( ).get<std::string>( "strusCms.mail.from" )
+ )
{
locale_name = "en";
script = settings( ).get<std::string>( "strusCms.script" );
diff --git a/src/strusCms.hpp b/src/strusCms.hpp
index 9a93e99..579b2d7 100644
--- a/src/strusCms.hpp
+++ b/src/strusCms.hpp
@@ -5,6 +5,7 @@
#include "intro.hpp"
#include "user.hpp"
+#include "mail.hpp"
namespace apps {
@@ -17,11 +18,11 @@ class strusCms : public cppcms::application {
apps::intro intro;
apps::user user;
std::string conn;
+ mailer mail;
private:
std::string script;
std::string locale_name;
-
};
}
diff --git a/src/user.cpp b/src/user.cpp
index dddde30..3a21504 100644
--- a/src/user.cpp
+++ b/src/user.cpp
@@ -63,9 +63,14 @@ void user::register_user( )
if( request( ).request_method( ) == "POST" ) {
c.register_user.load( context( ) );
if( c.register_user.validate( ) ) {
+ cms.mail.subject = "Registration request";
+ cms.mail.body = "Your registration code is: CODE";
+ cms.mail.to = c.register_user.email.value( );
+ cms.mail.send( );
response( ).set_redirect_header( cms.root( ) + "/confirm_register" );
}
}
+
render( "register_user", c );
}
@@ -202,6 +207,8 @@ register_user_form::register_user_form( apps::strusCms &cms )
password.error_message( "Your password is illegal" );
password2.message( "Your password (again)" );
password2.error_message( "Your password doesn't match" );
+ email.message( "Email" );
+ email.error_message( "Your email address is not valid" );
captcha.message( "Enter the correct captcha" );
captcha.error_message( "Captcha didn't match" );
submit.value( "Register user" );
@@ -209,12 +216,14 @@ register_user_form::register_user_form( apps::strusCms &cms )
add( username );
add( password );
add( password2 );
+ add( email );
add( captcha );
add( submit );
username.non_empty( );
password.non_empty( );
password2.non_empty( );
+ email.non_empty( );
captcha.non_empty( );
}
@@ -243,6 +252,7 @@ bool register_user_form::validate( )
if( captcha.value( ).compare( cms.user.last_captcha ) != 0 ) {
captcha.valid( false );
captcha.clear( );
+ booster::ptime::sleep( booster::ptime( 5, 0 ) );
return false;
}
diff --git a/src/user_content.hpp b/src/user_content.hpp
index e86e2fd..756f314 100644
--- a/src/user_content.hpp
+++ b/src/user_content.hpp
@@ -24,6 +24,7 @@ struct register_user_form : public cppcms::form {
cppcms::widgets::text username;
cppcms::widgets::password password;
cppcms::widgets::password password2;
+ cppcms::widgets::text email;
cppcms::widgets::text captcha;
cppcms::widgets::submit submit;