aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--META.yml12
-rw-r--r--Makefile.PL12
-rw-r--r--lib/CatDap.pm1
-rw-r--r--lib/CatDap/Controller/register.pm164
-rw-r--r--t/04compile.t14
5 files changed, 127 insertions, 76 deletions
diff --git a/META.yml b/META.yml
index 13c53f4..1034889 100644
--- a/META.yml
+++ b/META.yml
@@ -20,10 +20,22 @@ no_index:
- t
requires:
Catalyst::Action::RenderView: 0
+ Catalyst::Model::LDAP::FromAuthentication: 0
+ Catalyst::Plugin::Authentication: 0
+ Catalyst::Plugin::Authentication::Store::LDAP: 0
+ Catalyst::Plugin::Captcha: 0
Catalyst::Plugin::ConfigLoader: 0
+ Catalyst::Plugin::I18N: 0
+ Catalyst::Plugin::Session::State::Cookie: 0
+ Catalyst::Plugin::Session::Store::File: 0
Catalyst::Plugin::Static::Simple: 0
Catalyst::Runtime: 5.80022
+ Catalyst::View::Email: 0
+ Catalyst::View::TT: 0
Config::General: 0
+ Crypt::CBC: 0
+ Data::UUID: 0
+ Email::Valid: 0
Moose: 0
namespace::autoclean: 0
resources:
diff --git a/Makefile.PL b/Makefile.PL
index 7a4561c..c965166 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -12,8 +12,20 @@ all_from 'lib/CatDap.pm';
requires 'Catalyst::Runtime' => '5.80022';
requires 'Catalyst::Plugin::ConfigLoader';
requires 'Catalyst::Plugin::Static::Simple';
+requires 'Catalyst::Plugin::I18N';
+requires 'Catalyst::Plugin::Authentication';
+requires 'Catalyst::Plugin::Authentication::Store::LDAP';
+requires 'Catalyst::Plugin::Captcha';
+requires 'Catalyst::Plugin::Session::Store::File';
+requires 'Catalyst::Plugin::Session::State::Cookie';
requires 'Catalyst::Action::RenderView';
+requires 'Catalyst::View::TT';
+requires 'Catalyst::View::Email';
+requires 'Catalyst::Model::LDAP::FromAuthentication';
requires 'Moose';
+requires 'Crypt::CBC';
+requires 'Email::Valid';
+requires 'Data::UUID';
requires 'namespace::autoclean';
requires 'Config::General'; # This should reflect the config file format you've chosen
# See Catalyst::Plugin::ConfigLoader for supported formats
diff --git a/lib/CatDap.pm b/lib/CatDap.pm
index d9a37a9..93f5ece 100644
--- a/lib/CatDap.pm
+++ b/lib/CatDap.pm
@@ -13,7 +13,6 @@ use Catalyst::Runtime 5.80;
# directory
use Catalyst qw/
- -Debug
ConfigLoader
Static::Simple
Session
diff --git a/lib/CatDap/Controller/register.pm b/lib/CatDap/Controller/register.pm
index d8fc7c1..24ceb53 100644
--- a/lib/CatDap/Controller/register.pm
+++ b/lib/CatDap/Controller/register.pm
@@ -1,7 +1,6 @@
package CatDap::Controller::register;
use Moose;
use namespace::autoclean;
-use Data::Dumper;
use Email::Valid;
use Data::UUID;
@@ -35,96 +34,111 @@ sub check : Local {
my ( $self, $c ) = @_;
my %details = %{$c->request->params};
- my $username = $c->request->params->{uid};
- $username =~ s/[A-Z]/[a-z]/g;
+ my $username = lc($c->request->params->{uid});
my @errors;
$c->stash(errors => []);
# Check username, start with letter, followed by letters or numbers
- if ($username !~ /^[a-z][a-z0-9_\-]*$/) {
- push @errors, $c->loc('Invalid username');
+ if ($username !~ /^[a-z][a-z0-9_-]*$/) {
+ push @errors, $c->loc('Invalid username');
}
my $email = $c->request->params->{mail1};
if (! Email::Valid->address($email)) {
- push @errors, $c->loc('Invalid email address');
+ push @errors, $c->loc('Invalid email address');
}
if ($email ne $c->request->params->{mail2}) {
- push @errors, $c->loc('Addresses do not match');
+ push @errors, $c->loc('Addresses do not match');
}
if (! $c->validate_captcha($c->req->param('validate'))){
push @errors, $c->loc('Incorrect validation text, please try again');
}
- if ($c->request->params->{gn} !~ /^\p{IsAlnum}*\z$/) {
- push @errors, $c->loc('The first name supplied contains illegal characters');
+ if ($c->request->params->{gn} !~ /^\p{IsAlnum}+$/) {
+ push @errors, $c->loc(
+ 'The first name supplied contains illegal characters'
+ );
}
- if ($c->request->params->{sn} !~ /^\p{IsAlnum}*\z$/) {
- #push @errors, $c->loc('The') . ' ' $c->loc('surname') . ' ' . $c->loc('supplied contains unprintable characters');
- push @errors, $c->loc('The surname supplied contains illegal characters');
+ if ($c->request->params->{sn} !~ /^\p{IsAlnum}+$/) {
+ push @errors, $c->loc(
+ 'The surname supplied contains illegal characters'
+ );
}
- if (@errors gt 0) {
- $c->stash(errors => \@errors);
- $c->stash(template => 'register/index.tt');
- } else {
- # check in LDAP now that we have validated username and email
- my $mesg = $c->model('Proxy')->search("(mail=$email)");
- if ($mesg->entries ne 0) {
- push @errors,$c->loc('An account already exists with this email address');
- }
- $mesg = $c->model('Proxy')->search("(uid=$username)");
- if ($mesg->entries ne 0) {
- my $foo = Dumper(${$c->config}{'Model::Proxy'}{'base'});
- push @errors,$c->loc('An account already exists with this username');
- #push @errors,"under base" . __PACKAGE__->config{Model::Proxy}{base};
- push @errors,$foo;
- }
- if (@errors gt 0) {
- $c->stash(errors => \@errors);
- $c->stash(template => 'register/index.tt');
- } else {
- my $dn = "uid=$username,${$c->config}{'Model::Proxy'}{'base'}";
- my $ug = Data::UUID->new;
- my $password = $ug->create_str();
- my $cn = $c->request->params->{gn} . " " . $c->request->params->{sn};
- $mesg = $c->model('Proxy')->add($dn,
- attr => [
- objectclass => [ 'inetOrgPerson' ],
- sn => $c->request->params->{sn},
- gn => $c->request->params->{gn},
- cn => $cn,
- mail => $email,
- pwdReset => 'TRUE',
- userPassword => $password,
- ]
- );
- if ($mesg) {
- push @errors,$mesg->error;
- $c->stash(errors => \@errors);
- #$c->stash(template => 'register/index.tt');
- }
- #} else {
- my $body;
- $body .= $c->loc('Dear') . " $c->request->params->{gn},\n";
- $body .= $c->loc("Your Mageia indentity has been successfully created, but requires activation.\n");
- $body .= $c->loc("To activate your account, please follow the link below.\n");
- $body .= $c->uri_for('/user/firstlogin') . "?username=$username&key=$password";
- $c->stash->{email} = {
- to => $email,
- from => 'no-reply@mageia.org',
- subject => $c->loc('Mageia Identity Activation'),
- body => $body,
- };
-
- $c->forward( $c->view('Email') );
- if ( scalar( @{ $c->error } ) ) {
- my $errors = join "\n",@{ $c->error };
- $c->response->body($c->loc('An error occured sending the email, but your account was created. Please try the password recovery process f you entered the correct email address: [_1]', $errors));
- $c->error(0); # Reset the error condition if you need to
- }
- $c->stash(template => 'register/complete.tt');
- $c->stash(message => 'Check your email');
- #}
- }
+ if (@errors) {
+ $c->stash(errors => \@errors);
+ $c->stash(template => 'register/index.tt');
+ return;
}
+
+ # check in LDAP now that we have validated username and email
+ my $mesg = $c->model('Proxy')->search("(mail=$email)");
+ if ($mesg->entries()) {
+ push @errors,$c->loc(
+ 'An account already exists with this email address'
+ );
+ }
+ $mesg = $c->model('Proxy')->search("(uid=$username)");
+ if ($mesg->entries()) {
+ push @errors,$c->loc('An account already exists with this username');
+ push @errors;
+ }
+
+ if (@errors) {
+ $c->stash(errors => \@errors);
+ $c->stash(template => 'register/index.tt');
+ return;
+ }
+
+ my $dn = "uid=$username,${$c->config}{'Model::Proxy'}{'base'}";
+ my $ug = Data::UUID->new;
+ my $password = $ug->create_str();
+ my $cn = $c->request->params->{gn} . " " . $c->request->params->{sn};
+ $mesg = $c->model('Proxy')->add($dn,
+ attr => [
+ objectclass => [ 'inetOrgPerson' ],
+ sn => $c->request->params->{sn},
+ gn => $c->request->params->{gn},
+ cn => $cn,
+ mail => $email,
+ pwdReset => 'TRUE',
+ userPassword => $password,
+ ]
+ );
+ if ($mesg) {
+ push @errors,$mesg->error;
+ $c->stash(errors => \@errors);
+ #$c->stash(template => 'register/index.tt');
+ }
+
+ my $text = <<EOF;
+Dear %s,
+Your Mageia indentity has been successfully created, but requires activation.
+To activate your account, please follow the link below.
+%s?username=%s&key=%s
+EOF
+ my $body = $c->loc(
+ sprintf(
+ $text,
+ $c->request->params->{gn},
+ $c->uri_for('/user/firstlogin'),
+ $username,
+ $password
+ )
+ );
+ $c->stash->{email} = {
+ to => $email,
+ from => 'no-reply@mageia.org',
+ subject => $c->loc('Mageia Identity Activation'),
+ body => $body,
+ };
+
+ $c->forward( $c->view('Email') );
+ if ( @{ $c->error } ) {
+ my $errors = join "\n",@{ $c->error };
+ $c->response->body($c->loc('An error occured sending the email, but your account was created. Please try the password recovery process f you entered the correct email address: [_1]', $errors));
+ $c->error(0); # Reset the error condition if you need to
+ }
+
+ $c->stash(template => 'register/complete.tt');
+ $c->stash(message => 'Check your email');
}
sub captcha : Local {
diff --git a/t/04compile.t b/t/04compile.t
new file mode 100644
index 0000000..137c3f3
--- /dev/null
+++ b/t/04compile.t
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use English qw(-no_match_vars);
+use Test::More;
+use Test::Compile;
+
+my @files = $OSNAME eq 'MSWin32' ?
+ grep { ! /Syslog/ } all_pm_files('lib') :
+ grep { ! /Win32/ } all_pm_files('lib') ;
+
+all_pm_files_ok(@files);