Started working on registration page on website, with validation
This commit is contained in:
parent
cb9819aa2e
commit
0a32b05b6c
6 changed files with 151 additions and 4 deletions
31
lib/Pear/LocalLoop/Controller/Register.pm
Normal file
31
lib/Pear/LocalLoop/Controller/Register.pm
Normal file
|
@ -0,0 +1,31 @@
|
|||
package Pear::LocalLoop::Controller::Register;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
|
||||
sub index {
|
||||
my $c = shift;
|
||||
|
||||
my $agerange_rs = $c->schema->resultset('AgeRange');
|
||||
$agerange_rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
|
||||
$c->stash( ageranges => [ $agerange_rs->all ] );
|
||||
}
|
||||
|
||||
sub register {
|
||||
my $c = shift;
|
||||
my $validation = $c->validation;
|
||||
$validation->required('token')->in_resultset(
|
||||
'accounttokenname',
|
||||
$c->schema->resultset('AccountToken')->search_rs({used => 0}),
|
||||
);
|
||||
$validation->required('name', 'trim');
|
||||
$validation->required('email')->email;
|
||||
$validation->required('agerange')->in_resultset(
|
||||
'agerangeid',
|
||||
$c->schema->resultset('AgeRange'),
|
||||
);
|
||||
|
||||
use Devel::Dwarn;
|
||||
Dwarn $validation;
|
||||
$c->redirect_to('/register');
|
||||
}
|
||||
|
||||
1;
|
19
lib/Pear/LocalLoop/Plugin/Validators.pm
Normal file
19
lib/Pear/LocalLoop/Plugin/Validators.pm
Normal file
|
@ -0,0 +1,19 @@
|
|||
package Pear::LocalLoop::Plugin::Validators;
|
||||
use Mojo::Base 'Mojolicious::Plugin';
|
||||
|
||||
use Email::Valid;
|
||||
|
||||
sub register {
|
||||
my ( $plugin, $app, $conf ) = @_;
|
||||
|
||||
$app->validator->add_check( email => sub {
|
||||
my ( $validation, $name, $email ) = @_;
|
||||
return Email::Valid->address( $email ) ? undef : 1;
|
||||
});
|
||||
$app->validator->add_check( in_resultset => sub {
|
||||
my ( $validation, $name, $value, $key, $rs ) = @_;
|
||||
return $rs->search({ $key => $value })->count ? undef : 1;
|
||||
});
|
||||
}
|
||||
|
||||
1;
|
Reference in a new issue