2009-12-10 12:30:43 +01:00
|
|
|
|
##@file
|
|
|
|
|
# DBI password backend file
|
|
|
|
|
|
|
|
|
|
##@class
|
|
|
|
|
# DBI password backend class
|
|
|
|
|
package Lemonldap::NG::Portal::PasswordDBDBI;
|
|
|
|
|
|
2009-12-30 20:42:17 +01:00
|
|
|
|
use strict;
|
2009-12-10 12:30:43 +01:00
|
|
|
|
use Lemonldap::NG::Portal::Simple;
|
2009-12-11 22:17:06 +01:00
|
|
|
|
use Lemonldap::NG::Portal::AuthDBI; #inherits
|
2009-12-30 20:42:17 +01:00
|
|
|
|
use base qw(Lemonldap::NG::Portal::_DBI );
|
2010-01-21 18:38:55 +01:00
|
|
|
|
|
2010-10-02 17:45:10 +02:00
|
|
|
|
#inherits Lemonldap::NG::Portal::_SMTP
|
2009-12-10 12:30:43 +01:00
|
|
|
|
|
2011-11-07 12:18:42 +01:00
|
|
|
|
our $VERSION = '1.2.0';
|
2009-12-10 12:30:43 +01:00
|
|
|
|
|
2009-12-30 20:42:17 +01:00
|
|
|
|
## @apmethod int passwordDBInit()
|
|
|
|
|
# Load SMTP functions and call DBI authInit()
|
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
|
sub passwordDBInit {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
eval { use base qw(Lemonldap::NG::Portal::_SMTP) };
|
|
|
|
|
if ($@) {
|
|
|
|
|
$self->lmLog( "Unable to load SMTP functions ($@)", 'error' );
|
|
|
|
|
return PE_ERROR;
|
|
|
|
|
}
|
2010-01-21 18:38:55 +01:00
|
|
|
|
unless ( $self->{dbiPasswordMailCol} ) {
|
2009-12-30 20:42:17 +01:00
|
|
|
|
$self->lmLog( "Missing configuration parameters for DBI password reset",
|
|
|
|
|
'error' );
|
|
|
|
|
return PE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
return $self->Lemonldap::NG::Portal::AuthDBI::authInit();
|
|
|
|
|
}
|
2009-12-10 12:30:43 +01:00
|
|
|
|
|
|
|
|
|
## @apmethod int modifyPassword()
|
2009-12-21 23:28:38 +01:00
|
|
|
|
# Modify the password
|
2009-12-10 12:30:43 +01:00
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
|
|
|
|
sub modifyPassword {
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
|
|
# Exit if no password change requested
|
|
|
|
|
return PE_OK unless ( $self->{newpassword} );
|
|
|
|
|
|
2012-08-31 15:00:06 +02:00
|
|
|
|
# Check if portal require old password
|
2012-09-08 12:55:55 +02:00
|
|
|
|
if ( $self->{portalRequireOldPassword} ) {
|
2012-08-31 15:00:06 +02:00
|
|
|
|
unless ( $self->{oldpassword} ) {
|
|
|
|
|
$self->lmLog( "Portal require old password", 'error' );
|
|
|
|
|
return PE_PP_MUST_SUPPLY_OLD_PASSWORD;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-08 12:55:55 +02:00
|
|
|
|
|
2009-12-10 12:30:43 +01:00
|
|
|
|
# Verify confirmation password matching
|
2009-12-11 22:17:06 +01:00
|
|
|
|
return PE_PASSWORD_MISMATCH
|
|
|
|
|
unless ( $self->{newpassword} eq $self->{confirmpassword} );
|
2009-12-10 12:30:43 +01:00
|
|
|
|
|
|
|
|
|
# Connect
|
2009-12-11 22:17:06 +01:00
|
|
|
|
my $dbh =
|
|
|
|
|
$self->dbh( $self->{dbiAuthChain}, $self->{dbiAuthUser},
|
|
|
|
|
$self->{dbiAuthPassword} );
|
2009-12-10 12:30:43 +01:00
|
|
|
|
return PE_ERROR unless $dbh;
|
|
|
|
|
|
2010-03-01 21:32:28 +01:00
|
|
|
|
my $user = $self->{sessionInfo}->{_user};
|
2009-12-11 22:17:06 +01:00
|
|
|
|
|
2010-10-25 14:59:46 +02:00
|
|
|
|
# Check old password
|
2009-12-10 12:30:43 +01:00
|
|
|
|
if ( $self->{oldpassword} ) {
|
|
|
|
|
|
2010-10-25 14:59:46 +02:00
|
|
|
|
my $result = $self->check_password( $user, $self->{oldpassword} );
|
2009-12-10 12:30:43 +01:00
|
|
|
|
|
2010-01-21 18:38:55 +01:00
|
|
|
|
unless ($result) {
|
2009-12-10 12:30:43 +01:00
|
|
|
|
return PE_BADOLDPASSWORD;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Modify password
|
2010-10-25 14:59:46 +02:00
|
|
|
|
my $result = $self->modify_password( $user, $self->{newpassword} );
|
2009-12-10 12:30:43 +01:00
|
|
|
|
|
2010-01-21 18:38:55 +01:00
|
|
|
|
unless ($result) {
|
2009-12-10 12:30:43 +01:00
|
|
|
|
return PE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$self->lmLog( "Password changed for $user", 'debug' );
|
2010-01-22 22:54:58 +01:00
|
|
|
|
|
2009-12-10 12:30:43 +01:00
|
|
|
|
PE_PASSWORD_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
1;
|