Commit 9e932b52 authored by Xavier Guimard's avatar Xavier Guimard

Merge branch 'issue1794-accentregister' into 'v2.0'

Register: better handling of special chars (#1794)

See merge request !78
parents 0d5903ea f195db2a
Pipeline #5507 passed with stage
in 11 minutes and 42 seconds
......@@ -42,6 +42,7 @@ Build-Depends-Indep: libapache-session-perl,
libstring-random-perl,
libtest-mockobject-perl,
libtest-pod-perl,
libtext-unidecode-perl,
libunicode-string-perl,
liburi-perl,
libwww-perl,
......@@ -266,6 +267,7 @@ Depends: ${misc:Depends},
lemonldap-ng-fastcgi-server (= ${binary:Version}) | lemonldap-ng-uwsgi-app (= ${binary:Version}) | apache2 | httpd-cgi,
libclone-perl,
liblemonldap-ng-handler-perl (= ${binary:Version}),
libtext-unidecode-perl,
libregexp-assemble-perl
Recommends: libcrypt-openssl-bignum-perl,
libconvert-base32-perl,
......
......@@ -117,6 +117,7 @@ lib/Lemonldap/NG/Portal/Plugins/Status.pm
lib/Lemonldap/NG/Portal/Plugins/StayConnected.pm
lib/Lemonldap/NG/Portal/Plugins/Upgrade.pm
lib/Lemonldap/NG/Portal/Register/AD.pm
lib/Lemonldap/NG/Portal/Register/Base.pm
lib/Lemonldap/NG/Portal/Register/Custom.pm
lib/Lemonldap/NG/Portal/Register/Demo.pm
lib/Lemonldap/NG/Portal/Register/LDAP.pm
......
# Base package for Register modules
package Lemonldap::NG::Portal::Register::Base;
use strict;
use Mouse;
use Text::Unidecode;
extends 'Lemonldap::NG::Portal::Main::Plugin';
our $VERSION = '2.0.0';
sub _stripaccents {
my ( $self, $str ) = @_;
# UTF8 really shouldn't be decoded here, but in PSGI layer instead
utf8::decode($str);
# This method replaces all non-ascii characters by the
# closest ascii lookalike
my $res = unidecode($str);
return $res;
}
sub applyLoginRule {
my ( $self, $req ) = @_;
my $firstname =
lc $self->_stripaccents( $req->data->{registerInfo}->{firstname} );
my $lastname =
lc $self->_stripaccents( $req->data->{registerInfo}->{lastname} );
# For now, get first letter of firstname and lastname
return substr( $firstname, 0, 1 ) . $lastname;
}
1;
......@@ -2,6 +2,8 @@ package Lemonldap::NG::Portal::Register::Custom;
use strict;
extends 'Lemonldap::NG::Portal::Register::Base';
sub new {
my ( $class, $self ) = @_;
unless ( $self->{conf}->{customRegister} ) {
......
......@@ -2,9 +2,9 @@ package Lemonldap::NG::Portal::Register::Demo;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK);
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_MALFORMEDUSER);
extends 'Lemonldap::NG::Portal::Main::Plugin';
extends 'Lemonldap::NG::Portal::Register::Base';
our $VERSION = '2.0.0';
......@@ -18,13 +18,15 @@ sub computeLogin {
my ( $self, $req ) = @_;
# Get first letter of firstname and lastname
my $login =
substr( lc $req->data->{registerInfo}->{firstname}, 0, 1 )
. lc $req->data->{registerInfo}->{lastname};
$req->data->{registerInfo}->{login} = $login;
return PE_OK;
my $login = $self->applyLoginRule($req);
if ($login) {
$req->data->{registerInfo}->{login} = $login;
return PE_OK;
}
else {
return PE_MALFORMEDUSER;
}
}
## @method int createUser
......
......@@ -6,9 +6,11 @@ use Lemonldap::NG::Portal::Main::Constants qw(
PE_LDAPCONNECTFAILED
PE_LDAPERROR
PE_OK
PE_MALFORMEDUSER
);
extends 'Lemonldap::NG::Portal::Lib::LDAP';
extends 'Lemonldap::NG::Portal::Lib::LDAP',
'Lemonldap::NG::Portal::Register::Base';
our $VERSION = '2.0.0';
......@@ -21,9 +23,11 @@ sub computeLogin {
return PE_LDAPCONNECTFAILED unless $self->ldap and $self->bind();
# Get first letter of firstname and lastname
my $login =
substr( lc $req->data->{registerInfo}->{firstname}, 0, 1 )
. lc $req->data->{registerInfo}->{lastname};
my $login = $self->applyLoginRule($req);
unless ($login) {
return PE_MALFORMEDUSER;
}
my $finalLogin = $login;
......
......@@ -44,7 +44,7 @@ SKIP: {
$res = $client->_post(
'/register',
IO::String->new(
'firstname=fôo&lastname=bar&mail=foobar%40badwolf.org'),
'firstname=Fôo&lastname=Bàr&mail=foobar%40badwolf.org'),
length => 53,
accept => 'text/html'
),
......@@ -57,7 +57,7 @@ SKIP: {
'Found register token' );
$query = $1;
ok( $query =~ /register_token=/, 'Found register_token' );
ok( $mail =~ /fôo/, 'UTF-8 works' ) or explain( $mail, 'fôo' );
ok( $mail =~ /Fôo/, 'UTF-8 works' ) or explain( $mail, 'Fôo' );
ok(
$res =
......@@ -77,7 +77,7 @@ SKIP: {
ok(
$res = $client->_post(
'/', IO::String->new('user=fbar&password=fbar'),
'/', IO::String->new("user=fbar&password=fbar"),
length => 23,
accept => 'text/html'
),
......
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