From dd7862d93d6841741270b4da7db74b3457ef5407 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Fri, 21 Apr 2017 21:28:50 +0100 Subject: [PATCH] Refactored AccountToken table --- lib/Pear/LocalLoop/Controller/Api/Register.pm | 6 +- lib/Pear/LocalLoop/Controller/Register.pm | 2 +- .../LocalLoop/Schema/Result/AccountToken.pm | 84 ++----------------- .../LocalLoop/Schema/Result/Administrator.pm | 2 +- t/admin-approve.t | 2 +- t/admin-merge.t | 2 +- t/api/login.t | 2 +- t/register.t | 2 +- t/search.t | 2 +- t/upload.t | 2 +- 10 files changed, 16 insertions(+), 90 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Register.pm b/lib/Pear/LocalLoop/Controller/Api/Register.pm index 54260fc..2fb4aad 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Register.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Register.pm @@ -58,7 +58,7 @@ sub post_register{ $validation->input( $json ); my $token_rs = $c->schema->resultset('AccountToken')->search_rs({used => 0}); - $validation->required('token')->in_resultset('accounttokenname', $token_rs); + $validation->required('token')->in_resultset('name', $token_rs); my $customer_rs = $c->schema->resultset('Customer'); $validation->required('username')->like(qr/^[A-Za-z0-9]+$/)->not_in_resultset('username', $customer_rs); @@ -106,7 +106,7 @@ sub post_register{ $c->schema->txn_do( sub { $c->schema->resultset('AccountToken')->find({ - accounttokenname => $validation->param('token'), + name => $validation->param('token'), used => 0, })->update({ used => 1 }); $c->schema->resultset('User')->create({ @@ -126,7 +126,7 @@ sub post_register{ $c->schema->txn_do( sub { $c->schema->resultset('AccountToken')->find({ - accounttokenname => $validation->param('token'), + name => $validation->param('token'), used => 0, })->update({ used => 1 }); $c->schema->resultset('User')->create({ diff --git a/lib/Pear/LocalLoop/Controller/Register.pm b/lib/Pear/LocalLoop/Controller/Register.pm index e34cbbb..65b00fe 100644 --- a/lib/Pear/LocalLoop/Controller/Register.pm +++ b/lib/Pear/LocalLoop/Controller/Register.pm @@ -35,7 +35,7 @@ sub register { $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('accounttokenname', $token_rs); + $validation->required('token')->in_resultset('name', $token_rs); my $age_rs = $c->schema->resultset('AgeRange'); $validation->required('agerange')->in_resultset('id', $age_rs); diff --git a/lib/Pear/LocalLoop/Schema/Result/AccountToken.pm b/lib/Pear/LocalLoop/Schema/Result/AccountToken.pm index 7bace3b..fcd6a93 100644 --- a/lib/Pear/LocalLoop/Schema/Result/AccountToken.pm +++ b/lib/Pear/LocalLoop/Schema/Result/AccountToken.pm @@ -1,98 +1,24 @@ use utf8; package Pear::LocalLoop::Schema::Result::AccountToken; -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Pear::LocalLoop::Schema::Result::AccountToken - -=cut - use strict; use warnings; use base 'DBIx::Class::Core'; -=head1 COMPONENTS LOADED - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->load_components("InflateColumn::DateTime"); - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("AccountTokens"); - -=head1 ACCESSORS - -=head2 accounttokenid - - data_type: 'integer' - is_auto_increment: 1 - is_nullable: 0 - -=head2 accounttokenname - - data_type: 'text' - is_nullable: 0 - -=head2 used - - data_type: 'integer' - default_value: 0 - is_nullable: 0 - -=cut +__PACKAGE__->table("account_tokens"); __PACKAGE__->add_columns( - "accounttokenid", + "id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, - "accounttokenname", + "name", { data_type => "text", is_nullable => 0 }, "used", { data_type => "integer", default_value => 0, is_nullable => 0 }, ); -=head1 PRIMARY KEY +__PACKAGE__->set_primary_key("id"); -=over 4 +__PACKAGE__->add_unique_constraint(["name"]); -=item * L - -=back - -=cut - -__PACKAGE__->set_primary_key("accounttokenid"); - -=head1 UNIQUE CONSTRAINTS - -=head2 C - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->add_unique_constraint("accounttokenname_unique", ["accounttokenname"]); - - -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-24 17:32:21 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:MeN6dMZY0drrWk+En7E5Ag - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/lib/Pear/LocalLoop/Schema/Result/Administrator.pm b/lib/Pear/LocalLoop/Schema/Result/Administrator.pm index 5797fc0..1fd2bfc 100644 --- a/lib/Pear/LocalLoop/Schema/Result/Administrator.pm +++ b/lib/Pear/LocalLoop/Schema/Result/Administrator.pm @@ -5,7 +5,7 @@ use warnings; use base 'DBIx::Class::Core'; -__PACKAGE__->table("Administrators"); +__PACKAGE__->table("administrators"); __PACKAGE__->add_columns( "user_id", diff --git a/t/admin-approve.t b/t/admin-approve.t index 29d22ed..d6fc09b 100644 --- a/t/admin-approve.t +++ b/t/admin-approve.t @@ -12,7 +12,7 @@ my $dump_error = sub { diag $t->tx->res->dom->at('pre[id="error"]')->text }; my @account_tokens = ('a', 'b', 'c'); $schema->resultset('AccountToken')->populate([ - [ 'accounttokenname' ], + [ 'name' ], map { [ $_ ] } @account_tokens, ]); diff --git a/t/admin-merge.t b/t/admin-merge.t index 9b240c4..dac5ce4 100644 --- a/t/admin-merge.t +++ b/t/admin-merge.t @@ -12,7 +12,7 @@ my $dump_error = sub { diag $t->tx->res->dom->at('pre[id="error"]')->text }; my @account_tokens = ('a', 'b', 'c'); $schema->resultset('AccountToken')->populate([ - [ 'accounttokenname' ], + [ 'name' ], map { [ $_ ] } @account_tokens, ]); diff --git a/t/api/login.t b/t/api/login.t index 830699f..93a0fb8 100644 --- a/t/api/login.t +++ b/t/api/login.t @@ -13,7 +13,7 @@ my $email = 'rufus@shinra.energy'; my $password = 'MakoGold'; $schema->resultset('AccountToken')->create({ - accounttokenname => $account_token + name => $account_token }); my $test_json = { diff --git a/t/register.t b/t/register.t index e7dd305..6ea19eb 100644 --- a/t/register.t +++ b/t/register.t @@ -14,7 +14,7 @@ my @emails = ('a@a.com', 'b@a.com', 'c@a.com', 'd@a.com', 'e@a.com', 'f@a.com', 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'); $schema->resultset('AccountToken')->populate([ - [ qw/ accounttokenname / ], + [ qw/ name / ], map { [ $_ ] } @tokens, ]); diff --git a/t/search.t b/t/search.t index be6e302..7df9213 100644 --- a/t/search.t +++ b/t/search.t @@ -10,7 +10,7 @@ my $schema = $t->app->schema; my @account_tokens = ('a', 'b'); $schema->resultset('AccountToken')->populate([ - [ qw/ accounttokenname / ], + [ qw/ name / ], map { [ $_ ] } @account_tokens, ]); diff --git a/t/upload.t b/t/upload.t index 56a541d..7778b5f 100644 --- a/t/upload.t +++ b/t/upload.t @@ -12,7 +12,7 @@ my $dump_error = sub { diag $t->tx->res->dom->at('pre[id="error"]')->text }; my @account_tokens = ('a', 'b', 'c'); $schema->resultset('AccountToken')->populate([ - [ 'accounttokenname' ], + [ 'name' ], map { [ $_ ] } @account_tokens, ]);