« blib/lib/Lemonldap/NG/Portal/Password/Custom.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Register/Custom.pm »
| 1 | # Base package for Register modules | ||
| 2 | package Lemonldap::NG::Portal::Register::Base; | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use Mouse; | ||
| 6 | use Text::Unidecode; | ||
| 7 | |||
| 8 | extends 'Lemonldap::NG::Portal::Main::Plugin'; | ||
| 9 | |||
| 10 | our $VERSION = '2.0.10'; | ||
| 11 | |||
| 12 | sub _stripaccents { | ||
| 13 | my ( $self, $str ) = @_; | ||
| 14 | |||
| 15 | # UTF8 really shouldn't be decoded here, but in PSGI layer instead | ||
| 16 | utf8::decode($str); | ||
| 17 | |||
| 18 | # This method replaces all non-ascii characters by the | ||
| 19 | # closest ascii lookalike | ||
| 20 | my $res = unidecode($str); | ||
| 21 | return $res; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub applyLoginRule { | ||
| 25 | my ( $self, $req ) = @_; | ||
| 26 | |||
| 27 | my $firstname = | ||
| 28 | lc $self->_stripaccents( $req->data->{registerInfo}->{firstname} ); | ||
| 29 | my $lastname = | ||
| 30 | lc $self->_stripaccents( $req->data->{registerInfo}->{lastname} ); | ||
| 31 | |||
| 32 | # For now, get first letter of firstname and lastname | ||
| 33 | my $login = substr( $firstname, 0, 1 ) . $lastname; | ||
| 34 | $login =~ s/\s*//g; | ||
| 35 | return $login; | ||
| 36 | } | ||
| 37 | |||
| 38 | 1; |