2008-12-26 20:18:23 +01:00
|
|
|
##@file
|
|
|
|
# Web form authentication backend file
|
|
|
|
|
|
|
|
##@class
|
|
|
|
# Web form authentication backend class
|
2008-11-24 15:06:54 +01:00
|
|
|
package Lemonldap::NG::Portal::_WebForm;
|
|
|
|
|
|
|
|
use Lemonldap::NG::Portal::Simple qw(:all);
|
|
|
|
use strict;
|
|
|
|
|
2014-06-10 18:21:33 +02:00
|
|
|
our $VERSION = '1.4.0';
|
2009-06-08 18:29:13 +02:00
|
|
|
|
2009-02-17 15:56:38 +01:00
|
|
|
## @apmethod int authInit()
|
2008-12-26 20:18:23 +01:00
|
|
|
# Does nothing.
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return Lemonldap::NG::Portal constant
|
2008-11-24 15:06:54 +01:00
|
|
|
sub authInit {
|
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-17 15:56:38 +01:00
|
|
|
## @apmethod int extractFormInfo()
|
2008-12-26 20:18:23 +01:00
|
|
|
# Read username and password from POST datas
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return Lemonldap::NG::Portal constant
|
2008-11-24 15:06:54 +01:00
|
|
|
sub extractFormInfo {
|
|
|
|
my $self = shift;
|
2011-11-07 15:54:22 +01:00
|
|
|
|
2013-11-06 16:56:52 +01:00
|
|
|
# Init captcha
|
|
|
|
if ( $self->{captcha_login_enabled} ) {
|
|
|
|
eval { $self->initCaptcha(); };
|
|
|
|
$self->lmLog( "Can't init captcha: $@", "error" ) if $@;
|
|
|
|
}
|
|
|
|
|
2011-11-07 15:54:22 +01:00
|
|
|
# Detect first access and empty forms
|
|
|
|
my $defUser = defined $self->param('user');
|
|
|
|
my $defPassword = defined $self->param('password');
|
|
|
|
my $defOldPassword = defined $self->param('oldpassword');
|
|
|
|
|
|
|
|
# 1. No user defined at all -> first access
|
|
|
|
return PE_FIRSTACCESS unless $defUser;
|
|
|
|
|
|
|
|
# 2. If user and password defined -> login form
|
|
|
|
if ( $defUser && $defPassword ) {
|
|
|
|
return PE_FORMEMPTY
|
|
|
|
unless ( ( $self->{user} = $self->param('user') )
|
|
|
|
&& ( $self->{password} = $self->param('password') ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
# 3. If user and oldpassword defined -> password form
|
|
|
|
if ( $defUser && $defOldPassword ) {
|
|
|
|
return PE_PASSWORDFORMEMPTY
|
|
|
|
unless ( ( $self->{user} = $self->param('user') )
|
|
|
|
&& ( $self->{oldpassword} = $self->param('oldpassword') )
|
|
|
|
&& ( $self->{newpassword} = $self->param('newpassword') )
|
|
|
|
&& ( $self->{confirmpassword} = $self->param('confirmpassword') ) );
|
|
|
|
}
|
|
|
|
|
2013-02-20 17:04:29 +01:00
|
|
|
# 4. Captcha for login form
|
|
|
|
if ( $self->{captcha_login_enabled} && $defUser && $defPassword ) {
|
|
|
|
$self->{captcha_user_code} = $self->param('captcha_user_code');
|
|
|
|
$self->{captcha_check_code} = $self->param('captcha_code');
|
|
|
|
|
|
|
|
unless ( $self->{captcha_user_code} && $self->{captcha_check_code} ) {
|
|
|
|
$self->lmLog( "Captcha not filled", 'warn' );
|
|
|
|
return PE_CAPTCHAEMPTY;
|
2012-07-26 04:47:27 +02:00
|
|
|
}
|
2013-02-20 17:04:29 +01:00
|
|
|
|
|
|
|
$self->lmLog(
|
|
|
|
"Captcha data received: "
|
|
|
|
. $self->{captcha_user_code} . " and "
|
|
|
|
. $self->{captcha_check_code},
|
|
|
|
'debug'
|
|
|
|
);
|
|
|
|
|
|
|
|
# Check captcha
|
|
|
|
my $captcha_result = $self->checkCaptcha( $self->{captcha_user_code},
|
|
|
|
$self->{captcha_check_code} );
|
|
|
|
|
|
|
|
if ( $captcha_result != 1 ) {
|
|
|
|
if ( $captcha_result == -3
|
|
|
|
or $captcha_result == -2 )
|
2012-07-26 04:47:27 +02:00
|
|
|
{
|
2013-02-20 17:04:29 +01:00
|
|
|
$self->lmLog( "Captcha failed: wrong code", 'warn' );
|
2012-07-26 04:47:27 +02:00
|
|
|
return PE_CAPTCHAERROR;
|
|
|
|
}
|
2013-02-20 17:04:29 +01:00
|
|
|
elsif ( $captcha_result == 0 ) {
|
2012-07-26 04:47:27 +02:00
|
|
|
$self->lmLog( "Captcha failed: code not checked (file error)",
|
2013-02-20 17:04:29 +01:00
|
|
|
'warn' );
|
2012-07-26 04:47:27 +02:00
|
|
|
return PE_CAPTCHAERROR;
|
|
|
|
}
|
2013-02-20 17:04:29 +01:00
|
|
|
elsif ( $captcha_result == -1 ) {
|
|
|
|
$self->lmLog( "Captcha failed: code has expired", 'warn' );
|
2012-07-26 04:47:27 +02:00
|
|
|
return PE_CAPTCHAERROR;
|
2012-07-19 10:23:28 +02:00
|
|
|
}
|
|
|
|
}
|
2013-02-20 17:04:29 +01:00
|
|
|
$self->lmLog( "Captcha code verified", 'debug' );
|
2012-07-04 14:33:03 +02:00
|
|
|
}
|
2012-07-26 04:47:27 +02:00
|
|
|
|
2011-11-07 15:54:22 +01:00
|
|
|
# Other parameters
|
|
|
|
$self->{timezone} = $self->param('timezone');
|
|
|
|
|
|
|
|
# Check user
|
2014-01-17 23:32:18 +01:00
|
|
|
return PE_MALFORMEDUSER unless $self->get_user;
|
2011-11-07 15:54:22 +01:00
|
|
|
|
2008-11-24 15:06:54 +01:00
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-17 15:56:38 +01:00
|
|
|
## @apmethod int setAuthSessionInfo()
|
2008-12-26 20:18:23 +01:00
|
|
|
# Set password in session datas if wanted.
|
2008-12-28 09:36:52 +01:00
|
|
|
# @return Lemonldap::NG::Portal constant
|
2008-11-24 15:06:54 +01:00
|
|
|
sub setAuthSessionInfo {
|
|
|
|
my $self = shift;
|
|
|
|
|
2010-04-14 17:37:57 +02:00
|
|
|
# authenticationLevel
|
2010-09-01 18:06:01 +02:00
|
|
|
# -1 if password can be remebered
|
|
|
|
# +1 for user/password with HTTPS
|
|
|
|
$self->{_authnLevel} ||= 0;
|
|
|
|
$self->{_authnLevel} += 1 if $self->https();
|
|
|
|
$self->{_authnLevel} -= 1 if $self->{portalAutocomplete};
|
|
|
|
|
|
|
|
$self->{sessionInfo}->{authenticationLevel} = $self->{_authnLevel};
|
2009-04-08 12:32:33 +02:00
|
|
|
|
2009-05-25 14:59:57 +02:00
|
|
|
# Store user submitted login for basic rules
|
|
|
|
$self->{sessionInfo}->{'_user'} = $self->{'user'};
|
|
|
|
|
2008-11-24 15:06:54 +01:00
|
|
|
# Store submitted password if set in configuration
|
|
|
|
# WARNING: it can be a security hole
|
|
|
|
if ( $self->{storePassword} ) {
|
2009-06-14 18:43:02 +02:00
|
|
|
$self->{sessionInfo}->{'_password'} = $self->{'newpassword'}
|
|
|
|
|| $self->{'password'};
|
2008-11-24 15:06:54 +01:00
|
|
|
}
|
2009-06-22 12:01:58 +02:00
|
|
|
|
|
|
|
# Store user timezone
|
|
|
|
$self->{sessionInfo}->{'_timezone'} = $self->{'timezone'};
|
2009-10-12 18:55:35 +02:00
|
|
|
|
2008-11-24 15:06:54 +01:00
|
|
|
PE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|