summaryrefslogtreecommitdiff
path: root/src/user.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/user.cpp')
-rw-r--r--src/user.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/user.cpp b/src/user.cpp
index 8f18706..d94cd6f 100644
--- a/src/user.cpp
+++ b/src/user.cpp
@@ -7,6 +7,8 @@
#include <cppdb/frontend.h>
#include <cppcms/session_interface.h>
#include <booster/posix_time.h>
+#include <b64/encode.h>
+#include <sstream>
namespace apps {
@@ -81,10 +83,40 @@ bool user::check_login( std::string user, std::string password )
return true;
}
+#define GIFSIZE 17646
+extern "C" {
+ const int gifsize = GIFSIZE;
+ void captcha( unsigned char im[70*200], unsigned char l[6]);
+ void makegif(unsigned char im[70*200], unsigned char gif[gifsize]);
+}
+
void user::ini( content::user &c )
{
master::ini( c );
- c.captcha = ">> CAPTCHA <<";
+ unsigned char l[6];
+ unsigned char *im = new unsigned char[70*200];
+ unsigned char *gif = new unsigned char[gifsize];
+
+ captcha( im, l );
+ c.captcha_text = std::string( (char *)l );
+
+ std::ostringstream raws( std::stringstream::out | std::stringstream::binary );
+ makegif( im, gif );
+ raws.write( (char *)gif, gifsize );
+ std::string raw = raws.str( );
+
+ std::istringstream in( std::ios_base::in | std::ios_base::binary );
+ in.str( raw );
+
+ base64::encoder E;
+ std::string base_s;
+ base_s.reserve( 3 * gifsize );
+ std::ostringstream base( base_s, std::stringstream::out | std::stringstream::binary );
+ E.encode( in, base );
+ c.captcha_base64 = base.str( );
+
+ delete gif;
+ delete im;
}
} // namespace apps