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';
|
|
|
|
|
|
|
|
our $VERSION = '2.0.0';
|
|
|
|
|
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 {
|
|
|
|
my ( $self, $req ) = @_;
|
|
|
|
|
|
|
|
# Exit if no password change requested
|
|
|
|
return PE_OK
|
|
|
|
unless ( $req->datas->{newpassword} = $req->param('newpassword') );
|
|
|
|
|
|
|
|
# Check if portal require old password
|
|
|
|
if ( $self->conf->{portalRequireOldPassword} ) {
|
|
|
|
|
|
|
|
# TODO: verify oldpassword
|
|
|
|
unless ( $req->datas->{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 that old password is good
|
|
|
|
return PE_PASSWORD_MISMATCH
|
|
|
|
unless (
|
|
|
|
$req->datas->{newpassword} eq $req->param('confirmpassword') );
|
|
|
|
|
|
|
|
# Verify old password
|
2016-07-11 23:02:32 +02:00
|
|
|
return PE_BADOLDPASSWORD
|
2016-07-20 22:47:43 +02:00
|
|
|
unless ( $self->confirm( $req, $req->datas->{oldpassword} ) );
|
2016-07-07 23:55:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Call password package
|
2016-07-20 22:47:43 +02:00
|
|
|
my $res = $self->modifyPassword( $req, $req->datas->{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;
|