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
|
|
|
|
|
|
|
|
|
our $VERSION = '0.1';
|
|
|
|
|
|
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} );
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
# Update password in session if needed
|
|
|
|
|
my $infos;
|
|
|
|
|
$infos->{_password} = $self->{newpassword};
|
|
|
|
|
$self->updateSession($infos) if ( $self->{storePassword} );
|
|
|
|
|
|
2009-12-10 12:30:43 +01:00
|
|
|
|
PE_PASSWORD_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-21 18:38:55 +01:00
|
|
|
|
## @apmethod int resetPassword()
|
|
|
|
|
# Reset the password
|
2009-12-10 12:30:43 +01:00
|
|
|
|
# @return Lemonldap::NG::Portal constant
|
2010-01-21 18:38:55 +01:00
|
|
|
|
sub resetPassword {
|
2009-12-10 12:30:43 +01:00
|
|
|
|
my $self = shift;
|
|
|
|
|
|
2010-01-21 18:38:55 +01:00
|
|
|
|
# Exit method if no mail and mail_token
|
|
|
|
|
return PE_OK unless ( $self->{mail} && $self->{mail_token} );
|
2009-12-30 20:42:17 +01:00
|
|
|
|
|
|
|
|
|
$self->lmLog( "Reset password request for " . $self->{mail}, 'debug' );
|
2010-03-01 21:32:28 +01:00
|
|
|
|
|
2009-12-30 20:42:17 +01:00
|
|
|
|
# Generate a complex password
|
|
|
|
|
my $password = $self->gen_password( $self->{randomPasswordRegexp} );
|
|
|
|
|
|
|
|
|
|
$self->lmLog( "Generated password: " . $password, 'debug' );
|
|
|
|
|
|
|
|
|
|
# Modify password
|
2010-01-21 18:38:55 +01:00
|
|
|
|
my $result =
|
2010-10-25 14:59:46 +02:00
|
|
|
|
$self->modify_password( $self->{mail}, $password,
|
2010-01-21 18:38:55 +01:00
|
|
|
|
$self->{dbiPasswordMailCol} );
|
2009-12-30 20:42:17 +01:00
|
|
|
|
|
|
|
|
|
return PE_ERROR unless $result;
|
|
|
|
|
|
2010-01-22 12:25:37 +01:00
|
|
|
|
# Store password to forward it to the user
|
2010-01-21 18:38:55 +01:00
|
|
|
|
$self->{reset_password} = $password;
|
2009-12-30 20:42:17 +01:00
|
|
|
|
|
2010-01-22 12:25:37 +01:00
|
|
|
|
PE_OK;
|
2009-12-10 12:30:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
1;
|