2017-02-23 22:46:00 +01:00
|
|
|
package Lemonldap::NG::Portal::Password::REST;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2019-12-16 17:44:22 +01:00
|
|
|
use JSON;
|
2017-02-23 22:46:00 +01:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(
|
|
|
|
PE_ERROR
|
|
|
|
PE_PASSWORD_OK
|
|
|
|
);
|
|
|
|
|
|
|
|
extends 'Lemonldap::NG::Portal::Password::Base',
|
|
|
|
'Lemonldap::NG::Portal::Lib::REST';
|
|
|
|
|
2020-09-04 17:59:00 +02:00
|
|
|
our $VERSION = '2.0.9';
|
2017-02-23 22:46:00 +01:00
|
|
|
|
|
|
|
sub init {
|
|
|
|
my ($self) = @_;
|
|
|
|
unless ($self->conf->{restPwdConfirmUrl}
|
|
|
|
and $self->conf->{restPwdModifyUrl} )
|
|
|
|
{
|
|
|
|
$self->logger->error('Missing REST password URL');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return $self->SUPER::init;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub confirm {
|
|
|
|
my ( $self, $req, $pwd ) = @_;
|
|
|
|
my $res = eval {
|
2017-03-03 18:25:03 +01:00
|
|
|
$self->restCall(
|
|
|
|
$self->conf->{restPwdConfirmUrl},
|
|
|
|
{ user => $req->user, password => $pwd }
|
|
|
|
);
|
2017-02-23 22:46:00 +01:00
|
|
|
};
|
|
|
|
if ($@) {
|
|
|
|
$self->logger("Pwd confirm error: $@");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ( $res->{result} ? 1 : 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub modifyPassword {
|
2019-12-16 17:44:22 +01:00
|
|
|
my ( $self, $req, $pwd, $useMail ) = @_;
|
2017-02-23 22:46:00 +01:00
|
|
|
my $res = eval {
|
2017-03-03 18:25:03 +01:00
|
|
|
$self->restCall(
|
|
|
|
$self->conf->{restPwdModifyUrl},
|
2019-12-16 17:44:22 +01:00
|
|
|
{
|
|
|
|
( $useMail ? 'mail' : 'user' ) => $req->user,
|
2020-05-24 00:04:33 +02:00
|
|
|
useMail => ( $useMail ? JSON::true : JSON::false ),
|
2019-12-16 17:44:22 +01:00
|
|
|
password => $pwd,
|
|
|
|
}
|
2017-03-03 18:25:03 +01:00
|
|
|
);
|
2017-02-23 22:46:00 +01:00
|
|
|
};
|
|
|
|
if ($@) {
|
|
|
|
$self->logger("Pwd confirm error: $@");
|
|
|
|
return PE_ERROR;
|
|
|
|
}
|
|
|
|
return ( $res->{result} ? PE_PASSWORD_OK : PE_ERROR );
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|