2016-07-07 23:55:23 +02:00
|
|
|
# Base package for Password modules
|
|
|
|
package Lemonldap::NG::Portal::Password::Base;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(
|
|
|
|
PE_OK
|
2016-07-11 23:02:32 +02:00
|
|
|
PE_BADOLDPASSWORD
|
2016-07-07 23:55:23 +02:00
|
|
|
PE_PASSWORD_OK
|
|
|
|
PE_PASSWORD_MISMATCH
|
|
|
|
PE_PP_MUST_SUPPLY_OLD_PASSWORD
|
|
|
|
);
|
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Portal::Main::Plugin';
|
|
|
|
|
2019-02-12 18:21:38 +01:00
|
|
|
our $VERSION = '2.1.0';
|
2016-07-07 23:55:23 +02:00
|
|
|
|
2016-07-20 22:47:43 +02:00
|
|
|
# INITIALIZATION
|
|
|
|
|
|
|
|
sub init {
|
|
|
|
$_[0]->p->{_passwordDB} = $_[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
# INTERFACE
|
|
|
|
|
2016-07-08 06:22:04 +02:00
|
|
|
sub forAuthUser { '_modifyPassword' }
|
2016-07-07 23:55:23 +02:00
|
|
|
|
2016-07-20 22:47:43 +02:00
|
|
|
# RUNNING METHODS
|
|
|
|
|
2016-07-07 23:55:23 +02:00
|
|
|
sub _modifyPassword {
|
2019-02-11 15:40:27 +01:00
|
|
|
my ( $self, $req, $requireOldPwd ) = @_;
|
2016-07-07 23:55:23 +02:00
|
|
|
|
|
|
|
# Exit if no password change requested
|
|
|
|
return PE_OK
|
2018-07-05 22:56:16 +02:00
|
|
|
unless ( $req->data->{newpassword} = $req->param('newpassword') );
|
2016-07-07 23:55:23 +02:00
|
|
|
|
2018-11-19 18:50:35 +01:00
|
|
|
# Verify that old password is good
|
|
|
|
return PE_PASSWORD_MISMATCH
|
|
|
|
unless ( $req->data->{newpassword} eq $req->param('confirmpassword') );
|
|
|
|
|
2016-07-07 23:55:23 +02:00
|
|
|
# Check if portal require old password
|
2019-02-11 15:40:27 +01:00
|
|
|
if ( $self->conf->{portalRequireOldPassword} or $requireOldPwd ) {
|
2016-07-07 23:55:23 +02:00
|
|
|
|
|
|
|
# TODO: verify oldpassword
|
2018-07-05 22:56:16 +02:00
|
|
|
unless ( $req->data->{oldpassword} = $req->param('oldpassword') ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->warn("Portal require old password");
|
2016-07-07 23:55:23 +02:00
|
|
|
return PE_PP_MUST_SUPPLY_OLD_PASSWORD;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Verify old password
|
2016-07-11 23:02:32 +02:00
|
|
|
return PE_BADOLDPASSWORD
|
2018-07-05 22:56:16 +02:00
|
|
|
unless ( $self->confirm( $req, $req->data->{oldpassword} ) );
|
2016-07-07 23:55:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Call password package
|
2018-07-05 22:56:16 +02:00
|
|
|
my $res = $self->modifyPassword( $req, $req->data->{newpassword} );
|
2016-07-07 23:55:23 +02:00
|
|
|
if ( $res == PE_PASSWORD_OK ) {
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->debug( 'Update password in session for ' . $req->user );
|
2016-07-07 23:55:23 +02:00
|
|
|
my $infos;
|
|
|
|
|
2016-07-13 07:10:57 +02:00
|
|
|
# Store new password if asked
|
|
|
|
if ( $self->conf->{storePassword} ) {
|
|
|
|
$self->p->updateSession(
|
|
|
|
$req,
|
|
|
|
{
|
2016-07-20 22:47:43 +02:00
|
|
|
_passwordDB => $self->p->getModule( $req, 'password' ),
|
2016-07-13 07:10:57 +02:00
|
|
|
_password => $req->{newpassword}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$self->p->updateSession( $req,
|
2016-07-20 22:47:43 +02:00
|
|
|
{ _passwordDB => $self->p->getModule( $req, 'password' ) } );
|
2016-07-13 07:10:57 +02:00
|
|
|
}
|
2016-07-07 23:55:23 +02:00
|
|
|
|
|
|
|
# Set a flag to ignore password change in Menu
|
|
|
|
$req->{ignorePasswordChange} = 1;
|
|
|
|
|
|
|
|
# Set a flag to allow sending a mail
|
|
|
|
$req->{passwordWasChanged} = 1;
|
|
|
|
|
|
|
|
# Continue process if password change is ok
|
2017-09-19 22:59:29 +02:00
|
|
|
return PE_PASSWORD_OK;
|
2016-07-07 23:55:23 +02:00
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|