Remove register controller as no use anymore

This commit is contained in:
Tom Bloor 2017-06-13 21:33:47 +01:00
parent bba724bc3b
commit 9523db7684
2 changed files with 0 additions and 180 deletions

View file

@ -1,84 +0,0 @@
package Pear::LocalLoop::Controller::Register;
use Mojo::Base 'Mojolicious::Controller';
use DateTime;
has error_messages => sub {
return {
name => 'Full Name is required',
email => 'Email Address is required, and must be a valid address that is not already registered',
password => 'Password is required, and must match the Confirmation field',
postcode => 'Postcode is required, and must be a valid UK Postcode',
token => 'Token is required, and must be a valid, unused token',
agerange => 'Age Range is required, and must be a selection from the drop-down',
unknown => 'Sorry, there was a problem registering! Have you already registered?',
};
};
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 ], form_data => {}, error => undef );
}
sub register {
my $c = shift;
my $validation = $c->validation;
$validation->required('name');
$validation->required('password')->equal_to('password2');
$validation->required('postcode')->postcode;
my $user_rs = $c->schema->resultset('User');
$validation->required('email')->email->not_in_resultset('email', $user_rs);
my $token_rs = $c->schema->resultset('AccountToken')->search_rs({used => 0});
$validation->required('token')->in_resultset('name', $token_rs);
my $age_rs = $c->schema->resultset('AgeRange');
$validation->required('agerange')->in_resultset('id', $age_rs);
my @error_messages;
if ( $validation->has_error ) {
my $failed_vals = $validation->failed;
@error_messages = map {$c->error_messages->{ $_ } } @$failed_vals;
} else {
my $new_user = $c->schema->resultset('User')->find_or_new({
email => $validation->param('email'),
password => $validation->param('password'),
customer => {
username => $validation->param('name'),
postcode => $validation->param('postcode'),
age_range_id => $validation->param('agerange'),
},
});
if ( $new_user->in_storage ) {
@error_messages = ( $c->error_messages->{unknown} );
} else {
$new_user->insert;
}
}
if ( scalar @error_messages ) {
$age_rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
$c->stash(
error => \@error_messages,
ageranges => [ $age_rs->all ],
form_data => {
name => $validation->param('name'),
email => $validation->param('email'),
postcode => $validation->param('postcode'),
token => $validation->param('token'),
agerange => $validation->param('agerange'),
}
);
$c->render( template => 'register/index' );
} else {
$c->flash( success => 'Registered Successfully, please log in' );
$c->redirect_to('/');
}
}
1;

View file

@ -1,96 +0,0 @@
% layout 'default';
% title 'Register';
% content_for css => begin
<style>
body {
background: whitesmoke;
padding-top: 70px;
}
.panel {
background: white;
padding: 16px;
-webkit-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
-moz-box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
box-shadow: 0px 2px 4px 0px rgba(0,0,0,0.2);
}
</style>
% end
% content_for javascript => begin
% end
<div class="container">
% if ( defined $error ) {
<div class="alert alert-danger" role="alert">
<strong>Error!</strong><br>
% for my $error_single ( @$error ) {
<%= $error_single %><br>
% }
</div>
% }
<div class="row justify-content-center">
<div class="col-8">
<div class="register-form panel">
<form action="<%= url_for %>" method="post">
<div class="form-group">
<label for="register-token">Invitation Token</label>
<input type="text"
id="register-token"
class="form-control"
name="token"
value="<%= $form_data->{token} %>"
required>
</div>
<div class="form-group">
<label for="register-name">Full Name</label>
<input type="text"
id="register-name"
class="form-control"
name="name"
value="<%= $form_data->{name} %>"
required>
</div>
<div class="form-group">
<label for="register-email">Email Address</label>
<input type="email"
id="register-email"
class="form-control"
name="email"
value="<%= $form_data->{email} %>"
required>
</div>
<div class="form-group">
<label for="register-postcode">Postcode</label>
<input type="text"
id="register-postcode"
class="form-control"
name="postcode"
value="<%= $form_data->{postcode} %>"
required>
</div>
<div class="form-group">
<label for="register-age">Age Range</label>
<select id="register-age" class="form-control" name="agerange" required>
% for my $agerange ( @$ageranges ) {
<option value="<%= $agerange->{id} %>"<%= defined $form_data->{agerange} && $form_data->{agerange} eq $agerange->{id} ? ' selected' : '' %>>
<%= $agerange->{string} %>
</option>
% }
</select>
</div>
<div class="form-group">
<label for="login-password">Password</label>
<input type="password" id="login-password" class="form-control" name="password" required>
</div>
<div class="form-group">
<label for="login-password">Confirm Password</label>
<input type="password" id="login-password" class="form-control" name="password2" required>
</div>
<input type="submit" class="btn btn-block btn-primary" value="Register">
</form>
</div>
</div>
</div>
</div><!-- Container fluid-->