Commit 5d0e6007 authored by Xavier Guimard's avatar Xavier Guimard

Register/Demo in progress (#595)

parent f7cc7b2b
......@@ -102,6 +102,7 @@ lib/Lemonldap/NG/Portal/Plugins/Register.pm
lib/Lemonldap/NG/Portal/Plugins/RESTServer.pm
lib/Lemonldap/NG/Portal/Plugins/SOAPServer.pm
lib/Lemonldap/NG/Portal/Register.pm
lib/Lemonldap/NG/Portal/Register/Demo.pm
lib/Lemonldap/NG/Portal/RegisterDBAD.pm
lib/Lemonldap/NG/Portal/RegisterDBDemo.pm
lib/Lemonldap/NG/Portal/RegisterDBLDAP.pm
......@@ -375,6 +376,7 @@ t/33-Auth-and-issuer-OpenID2.t
t/34-Auth-Proxy-and-REST-Server.t
t/34-Auth-Proxy-and-SOAP-Server.t
t/40-Notifications-DBI.t
t/41-Register-Demo.t
t/50-IssuerGet.t
t/90-translations.t
t/99-pod.t
......
......@@ -35,6 +35,10 @@ sub enabledPlugins {
# }
#}
# Check if register is enabled
push @res, '::Plugins::Register'
if ( $self->conf->{registerDB} and $self->conf->{registerDB} ne 'Null' );
# Check if SOAP is enabled
push @res, '::Plugins::SOAPServer'
if ( $self->conf->{soapSessionServer}
......
......@@ -7,6 +7,10 @@ use Lemonldap::NG::Portal::Main::Constants qw(
PE_CAPTCHAEMPTY
PE_CAPTCHAERROR
PE_MALFORMEDUSER
PE_MAILCONFIRMATION_ALREADY_SENT
PE_MAILCONFIRMOK
PE_MAILERROR
PE_MAILOK
PE_OK
PE_REGISTERALREADYEXISTS
PE_REGISTERFIRSTACCESS
......@@ -22,13 +26,17 @@ extends 'Lemonldap::NG::Portal::Main::Plugin',
sub init {
my ($self) = @_;
$self->addUnauthRoute( register => 'register' );
$self->addUnauthRoute( register => 'register', [ 'POST', 'GET' ] );
if ( $self->conf->{captcha_register_enabled} ) {
# TODO: load captcha plugin
}
$self->registerModule(
$self->p->loadPlugin( '::Register::' . $self->conf->{registerDB} ) )
or return 0;
# TODO: load module if != $self->p->authentication
return 1;
}
......@@ -39,6 +47,15 @@ has captchaModule => ( is => 'rw' );
# TODO
has registerModule => ( is => 'rw' );
has registerUrl => (
is => 'rw',
default => sub {
my $p = $_[0]->conf->{portal};
$p =~ s#/*$##;
return "$p/register";
}
);
# RUNNIG METHODS
sub register {
......@@ -251,7 +268,7 @@ sub _register {
}
# Build confirmation url
my $url = $self->conf->{registerUrl} . "?register_token=" . $req->{id};
my $url = $self->registerUrl . "?register_token=" . $req->{id};
$url .= '&skin=' . $self->p->getSkin();
$url .= '&'
. $self->conf->{authChoiceParam} . '='
......@@ -285,7 +302,7 @@ sub _register {
unless $self->send_mail( $req->datas->{registerInfo}->{mail},
$subject, $body, $html );
PE_MAILCONFIRMOK;
return PE_MAILCONFIRMOK;
}
# Generate a complex password
......@@ -297,7 +314,7 @@ sub _register {
$req->datas->{forceReset} = 1;
# Find a login
$result = $self->registerModule->computeLogin($req);
my $result = $self->registerModule->computeLogin($req);
unless ( $result == PE_OK ) {
$self->lmLog(
"Could not compute login for "
......@@ -417,9 +434,9 @@ sub display {
if ( $self->conf->{captcha_register_enabled} ) {
%templateParams = (
%templateParams,
CAPTCHA_IMG => $elf->captcha_img,
CAPTCHA_CODE => $elf->captcha_code,
CAPTCHA_SIZE => $elf->captcha_size
CAPTCHA_IMG => $self->captcha_img,
CAPTCHA_CODE => $self->captcha_code,
CAPTCHA_SIZE => $self->captcha_size
);
}
......
package Lemonldap::NG::Portal::Register::Demo;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK);
our $VERSION = '2.0.0';
sub init {
1;
}
# Compute a login from register infos
# @result Lemonldap::NG::Portal constant
sub computeLogin {
my ($self) = @_;
# Get first letter of firstname and lastname
my $login =
substr( lc $self->{registerInfo}->{firstname}, 0, 1 )
. lc $self->{registerInfo}->{lastname};
$self->{registerInfo}->{login} = $login;
return PE_OK;
}
## @method int createUser
# Do nothing
# @result Lemonldap::NG::Portal constant
sub createUser {
my ($self) = @_;
return PE_OK;
}
## @method int registerDBFinish
# Do nothing
# @result Lemonldap::NG::Portal constant
sub registerDBFinish {
my ($self) = @_;
return PE_OK;
}
1;
use Test::More;
use strict;
use IO::String;
require 't/test-lib.pm';
my $res;
my $client = LLNG::Manager::Test->new(
{
ini => {
logLevel => 'debug',
useSafeJail => 1,
portalDisplayRegister => 1,
registerDB => 'Demo',
}
}
);
# Test normal first access
# ------------------------
ok( $res = $client->_get('/'), 'Unauth JSON request' );
count(1);
expectReject($res);
clean_sessions();
done_testing( count() );
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment