From d73ddb6ba26d74dbde0fdf43a0eb1fd3d0fda467 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 13 Jun 2017 21:02:24 +0100 Subject: [PATCH 01/10] Remove AgeRange table and first pass of fixing tests --- lib/Pear/LocalLoop/Controller/Api/Register.pm | 44 +++++++++-------- lib/Pear/LocalLoop/Plugin/Validators.pm | 5 ++ lib/Pear/LocalLoop/Schema/Result/AgeRange.pm | 37 --------------- lib/Pear/LocalLoop/Schema/Result/Customer.pm | 10 +--- lib/Test/Pear/LocalLoop.pm | 7 --- t/{ => api}/register.t | 47 ++++++++++--------- 6 files changed, 55 insertions(+), 95 deletions(-) delete mode 100644 lib/Pear/LocalLoop/Schema/Result/AgeRange.pm rename t/{ => api}/register.t (92%) diff --git a/lib/Pear/LocalLoop/Controller/Api/Register.pm b/lib/Pear/LocalLoop/Controller/Api/Register.pm index 4b56b9a..ee760ee 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Register.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Register.pm @@ -33,10 +33,11 @@ has error_messages => sub { required => { message => 'No usertype sent.', status => 400 }, in => { message => '"usertype" is invalid.', status => 400 }, }, - age_range => { - required => { message => 'No age_range sent.', status => 400 }, - number => { message => 'age_range is invalid', status => 400 }, - in_resultset => { message => 'age_range is invalid.', status => 400 }, + year_of_birth => { + required => { message => 'No year_of_birth sent.', status => 400 }, + number => { message => 'year_of_birth is invalid', status => 400 }, + gt_num => { message => 'year_of_birth must be within last 150 years', status => 400 }, + lt_num => { message => 'year_of_birth must be atleast 10 years ago', status => 400 }, }, street_name => { required => { message => 'No street_name sent.', status => 400 }, @@ -68,8 +69,8 @@ sub post_register{ if ( $usertype eq 'customer' ) { $validation->required('display_name'); $validation->required('full_name'); - my $age_rs = $c->schema->resultset('AgeRange'); - $validation->required('age_range')->number->in_resultset('id', $age_rs); + my $year = DateTime->now->year; + $validation->required('year_of_birth')->number->gt_num($year - 150)->lt_num($year - 10); } elsif ( $usertype eq 'organisation' ) { $validation->required('name'); $validation->required('street_name'); @@ -85,13 +86,15 @@ sub post_register{ name => $validation->param('token'), used => 0, })->update({ used => 1 }); + # Create customer as a seperate step, so we dont leak data + my $customer = $c->schema->resultset('Customer')->create({ + full_name => $validation->param('full_name'), + display_name => $validation->param('display_name'), + year_of_birth => $validation->param('year_of_birth'), + postcode => $validation->param('postcode'), + }); $c->schema->resultset('User')->create({ - customer => { - full_name => $validation->param('full_name'), - display_name => $validation->param('display_name'), - age_range_id => $validation->param('age_range'), - postcode => $validation->param('postcode'), - }, + customer => $customer, email => $validation->param('email'), password => $validation->param('password'), }); @@ -106,15 +109,16 @@ sub post_register{ name => $validation->param('token'), used => 0, })->update({ used => 1 }); + my $organisation = $c->schema->resultset('Organisation')->create({ + name => $validation->param('name'), + street_name => $validation->param('street_name'), + town => $validation->param('town'), + postcode => $validation->param('postcode'), + }); $c->schema->resultset('User')->create({ - organisation => { - name => $validation->param('name'), - street_name => $validation->param('street_name'), - town => $validation->param('town'), - postcode => $validation->param('postcode'), - }, - email => $validation->param('email'), - password => $validation->param('password'), + organisation => $organisation, + email => $validation->param('email'), + password => $validation->param('password'), }); }); } diff --git a/lib/Pear/LocalLoop/Plugin/Validators.pm b/lib/Pear/LocalLoop/Plugin/Validators.pm index 6722424..677b4d0 100644 --- a/lib/Pear/LocalLoop/Plugin/Validators.pm +++ b/lib/Pear/LocalLoop/Plugin/Validators.pm @@ -48,6 +48,11 @@ sub register { return $value > $check ? undef : 1; }); + $app->validator->add_check( lt_num => sub { + my ( $validation, $name, $value, $check ) = @_; + return $value < $check ? undef : 1; + }); + $app->validator->add_check( filetype => sub { my ( $validation, $name, $value, $filetype ) = @_; my ( undef, undef, $extension ) = fileparse $value->filename, qr/\.[^.]*/; diff --git a/lib/Pear/LocalLoop/Schema/Result/AgeRange.pm b/lib/Pear/LocalLoop/Schema/Result/AgeRange.pm deleted file mode 100644 index 73c4ffd..0000000 --- a/lib/Pear/LocalLoop/Schema/Result/AgeRange.pm +++ /dev/null @@ -1,37 +0,0 @@ -package Pear::LocalLoop::Schema::Result::AgeRange; - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; - -__PACKAGE__->table("age_ranges"); - -__PACKAGE__->add_columns( - "id", - { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, - "string", - { data_type => "text", is_nullable => 0 }, -); - -__PACKAGE__->set_primary_key("id"); - -__PACKAGE__->add_unique_constraint(["string"]); - -__PACKAGE__->has_many( - "customers", - "Pear::LocalLoop::Schema::Result::Customer", - { "foreign.age_range_id" => "self.id" }, - { cascade_copy => 0, cascade_delete => 0 }, -); - -sub TO_JSON { - my $self = shift; - - return { - id => $self->id, - string => $self->string, - }; -} - -1; diff --git a/lib/Pear/LocalLoop/Schema/Result/Customer.pm b/lib/Pear/LocalLoop/Schema/Result/Customer.pm index 5cd67a1..4ce92e2 100644 --- a/lib/Pear/LocalLoop/Schema/Result/Customer.pm +++ b/lib/Pear/LocalLoop/Schema/Result/Customer.pm @@ -23,9 +23,8 @@ __PACKAGE__->add_columns( size => 255, is_nullable => 0, }, - "age_range_id" => { + "year_of_birth" => { data_type => "integer", - is_foreign_key => 1, is_nullable => 0, }, "postcode" => { @@ -37,13 +36,6 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key("id"); -__PACKAGE__->belongs_to( - "age_range", - "Pear::LocalLoop::Schema::Result::AgeRange", - { id => "age_range_id" }, - { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, -); - __PACKAGE__->might_have( "user", "Pear::LocalLoop::Schema::Result::User", diff --git a/lib/Test/Pear/LocalLoop.pm b/lib/Test/Pear/LocalLoop.pm index 9581b02..12758fe 100644 --- a/lib/Test/Pear/LocalLoop.pm +++ b/lib/Test/Pear/LocalLoop.pm @@ -30,13 +30,6 @@ has framework => sub { my $schema = $t->app->schema; $schema->deploy; - $schema->resultset('AgeRange')->populate([ - [ qw/ string / ], - [ '20-35' ], - [ '35-50' ], - [ '50+' ], - ]); - $schema->resultset('Leaderboard')->populate([ [ qw/ name type / ], [ 'Daily Total', 'daily_total' ], diff --git a/t/register.t b/t/api/register.t similarity index 92% rename from t/register.t rename to t/api/register.t index a654500..40020ac 100644 --- a/t/register.t +++ b/t/api/register.t @@ -7,7 +7,7 @@ use Test::Pear::LocalLoop; my $framework = Test::Pear::LocalLoop->new; my $t = $framework->framework; my $schema = $t->app->schema; -my $dump_error = sub { diag $t->tx->res->dom->at('pre[id="error"]')->text }; +my $dump_error = $framework->dump_error; #Variables to be used for uniqueness when testing. my @tokens = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); @@ -36,7 +36,7 @@ $testJson = { 'email' => 'a@b.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 3 + 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -52,7 +52,7 @@ $testJson = { 'email' => 'a@b.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 3 + 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(401) @@ -68,7 +68,7 @@ $testJson = { 'email' => 'a@b.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 3 + 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -82,7 +82,7 @@ $testJson = { 'email' => 'a@b.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 3 + 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -98,7 +98,7 @@ $testJson = { 'email' => 'a@b.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 3 + 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -114,7 +114,7 @@ $testJson = { 'email' => 'a@b.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 3 + 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -132,7 +132,7 @@ $testJson = { 'email' => 'a@b.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 3 + 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(200) @@ -147,11 +147,14 @@ $testJson = { 'email' => 'b@c.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 2 + 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) + ->or($dump_error) ->status_is(200) - ->json_is('/success', Mojo::JSON->true); + ->or($dump_error) + ->json_is('/success', Mojo::JSON->true) + ->or($dump_error); #Valid customer3 $testJson = { @@ -162,7 +165,7 @@ $testJson = { 'email' => 'c@d.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 1 + 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(200) @@ -176,7 +179,7 @@ $testJson = { 'display_name' => 'test name', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 3 + 'year_of_birth' => 2005 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -192,7 +195,7 @@ $testJson = { 'email' => 'dfsd@.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 2 + 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -209,7 +212,7 @@ $testJson = { 'email' => 'dfsd@com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 2 + 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -226,7 +229,7 @@ $testJson = { 'email' => 'a@b.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 2 + 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(403) @@ -242,7 +245,7 @@ $testJson = { 'display_name' => 'test name', 'email' => 'd@e.com', 'password' => 'Meh', - 'age_range' => 3 + 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -259,7 +262,7 @@ $testJson = { 'display_name' => 'test name', 'email' => 'd@e.com', 'postcode' => 'LA1 1AA', - 'age_range' => 3 + 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -276,7 +279,7 @@ $testJson = { 'email' => 'd@e.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 3 + 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) @@ -300,7 +303,7 @@ $t->post_ok('/api/register' => json => $testJson) ->content_like(qr/invalid/i); -#age_range missing JSON +#year_of_birth missing JSON $testJson = { 'usertype' => 'customer', 'token' => 'f', @@ -313,7 +316,7 @@ $testJson = { $t->post_ok('/api/register' => json => $testJson) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/no age_range sent/i); + ->content_like(qr/no year_of_birth sent/i); #Age is invalid $testJson = { @@ -324,12 +327,12 @@ $testJson = { 'email' => 'test@example.com', 'postcode' => 'LA1 1AA', 'password' => 'Meh', - 'age_range' => 'invalid' + 'year_of_birth' => 'invalid' }; $t->post_ok('/api/register' => json => $testJson) ->status_is(400) ->json_is('/success', Mojo::JSON->false) - ->content_like(qr/age_range/i) + ->content_like(qr/year_of_birth/i) ->content_like(qr/invalid/i); #full address missing JSON From cee5a00d182d3040812877427cfe66231c2b26b0 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 13 Jun 2017 21:05:27 +0100 Subject: [PATCH 02/10] Rename and fix upload test --- t/{ => api}/upload.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename t/{ => api}/upload.t (99%) diff --git a/t/upload.t b/t/api/upload.t similarity index 99% rename from t/upload.t rename to t/api/upload.t index 1cf8215..b3a0a19 100644 --- a/t/upload.t +++ b/t/api/upload.t @@ -43,7 +43,7 @@ my $testJson = { 'email' => $emailRufus, 'postcode' => 'GU10 5SA', 'password' => $passwordRufus, - 'age_range' => 1 + 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(200) @@ -60,7 +60,7 @@ $testJson = { 'email' => $emailHojo, 'postcode' => 'DE15 9LT', 'password' => $passwordHojo, - 'age_range' => 1 + 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(200) From 51617a8cbbd0723855060dade0413b59ab205088 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 13 Jun 2017 21:06:53 +0100 Subject: [PATCH 03/10] Move and fix search test --- t/{ => api}/search.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename t/{ => api}/search.t (99%) diff --git a/t/search.t b/t/api/search.t similarity index 99% rename from t/search.t rename to t/api/search.t index c0ebb3a..320bf1a 100644 --- a/t/search.t +++ b/t/api/search.t @@ -36,7 +36,7 @@ my $testJson = { 'email' => $emailRufus, 'postcode' => 'RG26 5NU', 'password' => $passwordRufus, - 'age_range' => 1 + 'year_of_birth' => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(200)->or($framework->dump_error) From 170a056f3741621cd54fc9d5d34ca03897643eed Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 13 Jun 2017 21:11:54 +0100 Subject: [PATCH 04/10] Fix schema tests from year_of_birth change --- t/schema/leaderboard.t | 8 ++++---- t/schema/leaderboard_trend.t | 8 ++++---- t/schema/resultset_leaderboard.t | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/t/schema/leaderboard.t b/t/schema/leaderboard.t index b03106a..d457f80 100644 --- a/t/schema/leaderboard.t +++ b/t/schema/leaderboard.t @@ -17,7 +17,7 @@ my $user1 = { email => 'test1@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user2 = { @@ -27,7 +27,7 @@ my $user2 = { email => 'test2@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user3 = { @@ -37,7 +37,7 @@ my $user3 = { email => 'test3@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user4 = { @@ -47,7 +47,7 @@ my $user4 = { email => 'test4@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $org = { diff --git a/t/schema/leaderboard_trend.t b/t/schema/leaderboard_trend.t index f8b370a..63fff33 100644 --- a/t/schema/leaderboard_trend.t +++ b/t/schema/leaderboard_trend.t @@ -17,7 +17,7 @@ my $user1 = { email => 'test1@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user2 = { @@ -27,7 +27,7 @@ my $user2 = { email => 'test2@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user3 = { @@ -37,7 +37,7 @@ my $user3 = { email => 'test3@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user4 = { @@ -47,7 +47,7 @@ my $user4 = { email => 'test4@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $org = { diff --git a/t/schema/resultset_leaderboard.t b/t/schema/resultset_leaderboard.t index 76d622e..d257442 100644 --- a/t/schema/resultset_leaderboard.t +++ b/t/schema/resultset_leaderboard.t @@ -17,7 +17,7 @@ my $user1 = { email => 'test1@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user2 = { @@ -27,7 +27,7 @@ my $user2 = { email => 'test2@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user3 = { @@ -37,7 +37,7 @@ my $user3 = { email => 'test3@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user4 = { @@ -47,7 +47,7 @@ my $user4 = { email => 'test4@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $org = { From c7029567778620c9621274c996132af006eeefa2 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 13 Jun 2017 21:23:19 +0100 Subject: [PATCH 05/10] fix admin approve and merge tests --- t/admin-approve.t | 4 ++-- t/admin-merge.t | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/t/admin-approve.t b/t/admin-approve.t index 49ceaf5..3c287ed 100644 --- a/t/admin-approve.t +++ b/t/admin-approve.t @@ -30,7 +30,7 @@ my $testJson = { 'email' => $emailReno, 'postcode' => 'SA4 3FA', 'password' => $passwordReno, - 'age_range' => 1 + year_of_birth => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(200)->or($dump_error) @@ -64,7 +64,7 @@ $testJson = { 'email' => $emailAdmin, 'postcode' => 'HD5 9XU', 'password' => $passwordAdmin, - 'age_range' => 2 + year_of_birth => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(200) diff --git a/t/admin-merge.t b/t/admin-merge.t index b23cfea..661f264 100644 --- a/t/admin-merge.t +++ b/t/admin-merge.t @@ -30,7 +30,7 @@ my $testJson = { 'email' => $emailReno, 'postcode' => 'SA4 3FA', 'password' => $passwordReno, - 'age_range' => 1 + year_of_birth => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(200) @@ -65,7 +65,7 @@ $testJson = { 'email' => $emailAdmin, 'postcode' => 'HD5 9XU', 'password' => $passwordAdmin, - 'age_range' => 2 + year_of_birth => 2006 }; $t->post_ok('/api/register' => json => $testJson) ->status_is(200) From 2bf595d135e2904daa690d23247c8b21417b5dc0 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 13 Jun 2017 21:28:42 +0100 Subject: [PATCH 06/10] fIx final few tests for age_range to year_of_birth change --- t/api/login.t | 2 +- t/api/stats.t | 2 +- t/api/stats_leaderboards.t | 8 ++++---- t/api/user.t | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/t/api/login.t b/t/api/login.t index b1fef6d..1521378 100644 --- a/t/api/login.t +++ b/t/api/login.t @@ -24,7 +24,7 @@ my $test_json = { 'email' => $email, 'postcode' => 'LA1 1AA', 'password' => $password, - 'age_range' => 1 + year_of_birth => 2006 }; $t->post_ok('/api/register' => json => $test_json) ->status_is(200) diff --git a/t/api/stats.t b/t/api/stats.t index 180a91f..7468795 100644 --- a/t/api/stats.t +++ b/t/api/stats.t @@ -17,7 +17,7 @@ my $user = { email => 'test@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $org = { diff --git a/t/api/stats_leaderboards.t b/t/api/stats_leaderboards.t index e8bf855..792c24d 100644 --- a/t/api/stats_leaderboards.t +++ b/t/api/stats_leaderboards.t @@ -17,7 +17,7 @@ my $user1 = { email => 'test1@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user2 = { @@ -27,7 +27,7 @@ my $user2 = { email => 'test2@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user3 = { @@ -37,7 +37,7 @@ my $user3 = { email => 'test3@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $user4 = { @@ -47,7 +47,7 @@ my $user4 = { email => 'test4@example.com', postcode => 'LA1 1AA', password => 'abc123', - age_range => 1, + year_of_birth => 2006, }; my $org = { diff --git a/t/api/user.t b/t/api/user.t index b65abdc..76eb6ee 100644 --- a/t/api/user.t +++ b/t/api/user.t @@ -24,7 +24,7 @@ $framework->register_customer({ 'email' => $email, 'postcode' => 'LA1 1AA', 'password' => $password, - 'age_range' => 1 + year_of_birth => 2006 }); my $session_key = $framework->login({ From bba724bc3b947a344d3d0ee2d06494c948ef56ee Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 13 Jun 2017 21:30:32 +0100 Subject: [PATCH 07/10] Fix dev_data script --- lib/Pear/LocalLoop/Command/dev_data.pm | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/Pear/LocalLoop/Command/dev_data.pm b/lib/Pear/LocalLoop/Command/dev_data.pm index 7c6b04e..132ce7d 100644 --- a/lib/Pear/LocalLoop/Command/dev_data.pm +++ b/lib/Pear/LocalLoop/Command/dev_data.pm @@ -25,13 +25,6 @@ sub run { my $schema = $self->app->schema; - $schema->resultset('AgeRange')->populate([ - [ qw/ string / ], - [ '20-35' ], - [ '35-50' ], - [ '50+' ], - ]); - $schema->resultset('Leaderboard')->populate([ [ qw/ name type / ], [ 'Daily Total', 'daily_total' ], From 9523db76843a70c129616a7c9c7da4618251ec9e Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 13 Jun 2017 21:33:47 +0100 Subject: [PATCH 08/10] Remove register controller as no use anymore --- lib/Pear/LocalLoop/Controller/Register.pm | 84 -------------------- templates/register/index.html.ep | 96 ----------------------- 2 files changed, 180 deletions(-) delete mode 100644 lib/Pear/LocalLoop/Controller/Register.pm delete mode 100644 templates/register/index.html.ep diff --git a/lib/Pear/LocalLoop/Controller/Register.pm b/lib/Pear/LocalLoop/Controller/Register.pm deleted file mode 100644 index 65b00fe..0000000 --- a/lib/Pear/LocalLoop/Controller/Register.pm +++ /dev/null @@ -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; diff --git a/templates/register/index.html.ep b/templates/register/index.html.ep deleted file mode 100644 index e1aa6a9..0000000 --- a/templates/register/index.html.ep +++ /dev/null @@ -1,96 +0,0 @@ -% layout 'default'; -% title 'Register'; -% content_for css => begin - -% end -% content_for javascript => begin -% end -
- % if ( defined $error ) { - - % } -
-
- -
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- -
-
-
-
-
- From 6f5e0fb31e34fb446e9f63c20b31504f8c1f3a8f Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 13 Jun 2017 21:45:23 +0100 Subject: [PATCH 09/10] Remove unneccessary endpoint for AgeRanges --- lib/Pear/LocalLoop.pm | 1 - lib/Pear/LocalLoop/Controller/Api/Info.pm | 12 ------------ 2 files changed, 13 deletions(-) delete mode 100644 lib/Pear/LocalLoop/Controller/Api/Info.pm diff --git a/lib/Pear/LocalLoop.pm b/lib/Pear/LocalLoop.pm index 9db42b9..5409d4e 100644 --- a/lib/Pear/LocalLoop.pm +++ b/lib/Pear/LocalLoop.pm @@ -125,7 +125,6 @@ sub startup { my $c = shift; $c->respond_to(any => { data => '', status => 200 }); }); - $api_public_get->get('/info/ages')->to('api-info#get_ages'); # Always available api routes my $api_public = $api_public_get->under('/')->to('api-auth#check_json'); diff --git a/lib/Pear/LocalLoop/Controller/Api/Info.pm b/lib/Pear/LocalLoop/Controller/Api/Info.pm deleted file mode 100644 index 949847b..0000000 --- a/lib/Pear/LocalLoop/Controller/Api/Info.pm +++ /dev/null @@ -1,12 +0,0 @@ -package Pear::LocalLoop::Controller::Api::Info; -use Mojo::Base 'Mojolicious::Controller'; - -sub get_ages { - my $c = shift; - - my $ages = $c->schema->resultset('AgeRange'); - - $c->render( json => { ages => [ $ages->all ] } ); -} - -1; From 41072acc079b1612ff3c3e3c25759e464859628b Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Tue, 13 Jun 2017 21:46:30 +0100 Subject: [PATCH 10/10] Remove age_range_id setting from dev_data script --- lib/Pear/LocalLoop/Command/dev_data.pm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Pear/LocalLoop/Command/dev_data.pm b/lib/Pear/LocalLoop/Command/dev_data.pm index 132ce7d..33d6326 100644 --- a/lib/Pear/LocalLoop/Command/dev_data.pm +++ b/lib/Pear/LocalLoop/Command/dev_data.pm @@ -43,7 +43,7 @@ sub run { customer => { full_name => 'Test User', display_name => 'Test User', - age_range_id => 1, + year_of_birth => 2006, postcode => 'LA1 1AA', }, administrator => {}, @@ -55,7 +55,7 @@ sub run { customer => { full_name => 'Test User 2', display_name => 'Test User 2', - age_range_id => 1, + year_of_birth => 2006, postcode => 'LA1 1AA', }, }); @@ -66,7 +66,7 @@ sub run { customer => { full_name => 'Test User 3', display_name => 'Test User 3', - age_range_id => 1, + year_of_birth => 2006, postcode => 'LA1 1AA', }, });