@@ -17,6 +17,8 @@ use Bugzilla::Constants;
1717use Bugzilla::Error;
1818use Bugzilla::Token;
1919
20+ use Authen::Captcha;
21+
2022# Just in case someone already has an account, let them get the correct footer
2123# on an error message. The user is logged out just after the account is
2224# actually created.
@@ -33,13 +35,32 @@ my $login = $cgi->param('login');
3335my $uid = $cgi -> param(' uid' );
3436
3537# Modified for Mer to send uid to account creation and to put uid into
36- # the $vars for the templates
38+ # the $vars for the templates. And added captcha for the robots
39+
40+ my $captcha_data = bz_locations()-> {' datadir' } . " /captcha" ;
41+ my $captcha_output = bz_locations()-> {' assetsdir' };
42+ my $captcha = Authen::Captcha-> new(
43+ data_folder => $captcha_data ,
44+ output_folder => $captcha_output ,
45+ );
46+
3747if (defined ($login )) {
3848 # Check the hash token to make sure this user actually submitted
3949 # the create account form.
4050 my $token = $cgi -> param(' token' );
4151 check_hash_token($token , [' create_account' ]);
4252
53+ my $captcha_token = $cgi -> param(' captcha_token' );
54+ my $captcha_code = $cgi -> param(' captcha_code' );
55+ my $result = $captcha -> check_code($captcha_code , $captcha_token );
56+ if ($result == 0) {
57+ ThrowCodeError(' captcha_check_error' );
58+ } elsif ($result == -1) {
59+ ThrowUserError(' captcha_expired' );
60+ } elsif ($result < -1 ) {
61+ ThrowUserError(' captcha_invalid' );
62+ }
63+
4364 $user -> check_and_send_account_creation_confirmation($login , $uid );
4465 $vars -> {' login' } = $login ;
4566 $vars -> {' uid' } = $uid ;
@@ -49,6 +70,8 @@ if (defined($login)) {
4970 exit ;
5071}
5172
73+ $vars -> {' captcha_token' } = $captcha -> generate_code(10);
74+
5275# Show the standard "would you like to create an account?" form.
5376$template -> process(" account/create.html.tmpl" , $vars )
5477 || ThrowTemplateError($template -> error());
0 commit comments