From 5ade3bf9b2bb76c79a41e27194cac00d612e7454 Mon Sep 17 00:00:00 2001 From: Sandro Cazzaniga Date: Wed, 25 Jul 2012 08:57:53 +0000 Subject: [PATCH] - Better indentation for _Webform - Better doc for initCaptcha() --- .../lib/Lemonldap/NG/Portal/Simple.pm | 18 ++++++----- .../lib/Lemonldap/NG/Portal/_WebForm.pm | 31 ++++++++++--------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Simple.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Simple.pm index c65d9dc52..1872ff48f 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Simple.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Simple.pm @@ -466,8 +466,8 @@ sub new { # init the captcha feature if it's enabled if ( $self->{captcha_enabled} ) { eval $self->initCaptcha(); - $self->{captcha_initialized} = 1 unless $@ ; - } + $self->lmLog("Can't init captcha: $@", "error"); + } return $self; } @@ -647,10 +647,10 @@ sub setDefaultValues { $self->{mailOnPasswordChange} ||= 0; # Captcha parameters - $self->{captcha_enabled} = 0; - $self->{captcha_size} = 6; + $self->{captcha_enabled} = 0; + $self->{captcha_size} = 6; $self->{captcha_output} = '/usr/local/lemonldap-ng/htdocs/portal/captcha_output/'; - $self->{captcha_data} = '/usr/local/lemonldap-ng/data/captcha/data/'; + $self->{captcha_data} = '/usr/local/lemonldap-ng/data/captcha/data/'; # Notification $self->{notificationWildcard} ||= "allusers"; @@ -760,8 +760,9 @@ sub buildHiddenForm { return $val; } -## @method void initCaptcha() +## @method void initCaptcha(void) # init captcha module and generate captcha +# @return nothing sub initCaptcha { my $self = shift; opendir(OUTPUT, $self->{captcha_output}) or $self->lmLog("Can't open captcha output dir", "error"); @@ -1474,15 +1475,16 @@ sub convertSec { # Calculate the hours if ( $min > 60 ) { $hrs = $min / 60, $min %= 60; - $hrs = int($hrs); + $hrs = int($hrs); } # Calculate the days if ( $hrs > 24 ) { $day = $hrs / 24, $hrs %= 24; - $day = int($day); + $day = int($day); } + # Return the date return ( $day, $hrs, $min, $sec ); } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/_WebForm.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/_WebForm.pm index a284f7316..e4b1a585b 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/_WebForm.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/_WebForm.pm @@ -50,26 +50,27 @@ sub extractFormInfo { # 4. If the captcha feature is enabled, captcha form if ( $self->{captcha_enabled} ) { my $captcha_user_code; - if ( $self->param('captcha_user_code') && $self->param('captcha_code') ) { - $captcha_user_code = $self->param('captcha_user_code'); - $self->{captcha_code} = $self->param('captcha_code'); - } - $self->{captcha_result} = $self->checkCaptcha($captcha_user_code, $self->{captcha_code}); + if ( $self->param('captcha_user_code') && $self->param('captcha_code') ) { + $captcha_user_code = $self->param('captcha_user_code'); + $self->{captcha_code} = $self->param('captcha_code'); + } + $self->{captcha_result} = $self->checkCaptcha($captcha_user_code, $self->{captcha_code}); if ( $self->{captcha_result} != 1 ) { if ( $self->{captcha_result} == -3 or $self->{captcha_result} == -2 ) { - $self->lmLog("Captcha failed: wrong code", "error"); - return PE_CAPTCHAERROR; - } - elsif ( $self->{captcha_result} == 0 ) { - $self->lmLog("Captcha failed: code not checked (file error)", "error"); - return PE_CAPTCHAERROR; + $self->lmLog("Captcha failed: wrong code", 'error'); + return PE_CAPTCHAERROR; + } + elsif ( $self->{captcha_result} == 0 ) { + $self->lmLog("Captcha failed: code not checked (file error)", 'error'); + return PE_CAPTCHAERROR; } - elsif ( $self->{captcha_result} == -1 ) { - $self->lmLog("Captcha failed: code has expired", "error"); - return PE_CAPTCHAERROR; - } + elsif ( $self->{captcha_result} == -1 ) { + $self->lmLog("Captcha failed: code has expired", 'error'); + return PE_CAPTCHAERROR; + } } } + # Other parameters $self->{timezone} = $self->param('timezone'); $self->{userControl} ||= '^[\w\.\-@]+$';