Finish major rework of schema

This commit is contained in:
Tom Bloor 2017-04-21 22:12:53 +01:00
parent dd7862d93d
commit 3be6289fc3
15 changed files with 157 additions and 318 deletions

View file

@ -150,18 +150,6 @@ sub startup {
$self->res->headers->header('Access-Control-Allow-Origin' => '*') if $self->app->mode eq 'development'; $self->res->headers->header('Access-Control-Allow-Origin' => '*') if $self->app->mode eq 'development';
}); });
#This assumes the user has no current session on that device.
$self->helper(generate_session => sub {
my ($self, $user) = @_;
my $sessionToken = Data::UUID->new->create_str();
my $insertStatement = $self->db->prepare('INSERT INTO SessionTokens (SessionTokenName, UserIdAssignedTo_FK, ExpireDateTime) VALUES (?, ?, ?)');
my $rowsAdded = $insertStatement->execute($sessionToken, $user, DateTime->now()->add( years => 1 ));
return $sessionToken;
});
$self->helper(get_age_foreign_key => sub { $self->helper(get_age_foreign_key => sub {
my ( $c, $age_string ) = @_; my ( $c, $age_string ) = @_;
my $age_range = $c->schema->resultset('AgeRange')->find({ agerangestring => $age_string }); my $age_range = $c->schema->resultset('AgeRange')->find({ agerangestring => $age_string });

View file

@ -105,15 +105,15 @@ sub post_admin_merge {
sub copy_transactions_and_delete { sub copy_transactions_and_delete {
my ( $c, $from_org, $to_org ) = @_; my ( $c, $from_org, $to_org ) = @_;
my $from_org_transaction_rs = $from_org->pending_transactions; my $from_org_transaction_rs = $from_org->transactions;
while ( my $from_org_transaction = $from_org_transaction_rs->next ) { while ( my $from_org_transaction = $from_org_transaction_rs->next ) {
$to_org->create_related( $to_org->create_related(
'transactions', { 'transactions', {
buyeruserid_fk => $from_org_transaction->buyeruserid_fk, buyer_id => $from_org_transaction->buyer_id,
valuemicrocurrency => $from_org_transaction->valuemicrocurrency, value => $from_org_transaction->value,
proof_image => $from_org_transaction->proof_image, proof_image => $from_org_transaction->proof_image,
timedatesubmitted => $from_org_transaction->timedatesubmitted, submitted_at => $from_org_transaction->submitted_at,
} }
); );
} }

View file

@ -42,7 +42,7 @@ sub auth {
my $session_key = $c->stash->{api_json}->{session_key}; my $session_key = $c->stash->{api_json}->{session_key};
if ( defined $session_key ) { if ( defined $session_key ) {
my $session_result = $c->schema->resultset('SessionToken')->find({ sessiontokenname => $session_key }); my $session_result = $c->schema->resultset('SessionToken')->find({ token => $session_key });
if ( defined $session_result ) { if ( defined $session_result ) {
$c->stash( api_user => $session_result->user ); $c->stash( api_user => $session_result->user );
@ -78,7 +78,7 @@ sub post_login {
if ( defined $user_result ) { if ( defined $user_result ) {
if ( $user_result->check_password($password) ) { if ( $user_result->check_password($password) ) {
my $session_key = $c->generate_session( $user_result->id ); my $session_key = $user_result->generate_session;
return $c->render( json => { return $c->render( json => {
success => Mojo::JSON->true, success => Mojo::JSON->true,
@ -101,7 +101,7 @@ sub post_logout {
my $session_key = $c->req->json( '/session_key' ); my $session_key = $c->req->json( '/session_key' );
my $session_result = $c->schema->resultset('SessionToken')->find({ sessiontokenname => $session_key }); my $session_result = $c->schema->resultset('SessionToken')->find({ token => $session_key });
if ( defined $session_result ) { if ( defined $session_result ) {
$session_result->delete; $session_result->delete;

View file

@ -30,6 +30,7 @@ has error_messages => sub {
}, },
age => { age => {
required => { message => 'No age sent.', status => 400 }, required => { message => 'No age sent.', status => 400 },
number => { message => 'Age range is invalid', status => 400 },
in_resultset => { message => 'Age range is invalid.', status => 400 }, in_resultset => { message => 'Age range is invalid.', status => 400 },
}, },
street_name => { street_name => {
@ -79,7 +80,7 @@ sub post_register{
if ( $usertype eq 'customer' ) { if ( $usertype eq 'customer' ) {
my $age_rs = $c->schema->resultset('AgeRange'); my $age_rs = $c->schema->resultset('AgeRange');
$validation->required('age')->in_resultset('id', $age_rs); $validation->required('age')->number->in_resultset('id', $age_rs);
} elsif ( $usertype eq 'organisation' ) { } elsif ( $usertype eq 'organisation' ) {

View file

@ -75,7 +75,6 @@ has error_messages => sub {
sub post_upload { sub post_upload {
my $c = shift; my $c = shift;
my $self = $c;
my $user = $c->stash->{api_user}; my $user = $c->stash->{api_user};
@ -94,75 +93,62 @@ sub post_upload {
my $type = $validation->param('transaction_type'); my $type = $validation->param('transaction_type');
my $organisation;
if ( $type == 1 ) { if ( $type == 1 ) {
# Validated Organisation # Validated Organisation
my $valid_org_rs = $c->schema->resultset('Organisation'); my $valid_org_rs = $c->schema->resultset('Organisation');
$validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs ); $validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs );
return $c->api_validation_error if $validation->has_error;
$organisation = $valid_org_rs->find( $validation->param('organisation_id') );
} elsif ( $type == 2 ) { } elsif ( $type == 2 ) {
# Unvalidated Organisation # Unvalidated Organisation
my $valid_org_rs = $c->schema->resultset('PendingOrganisation')->search({ submitted_by_id => $user->id }); my $valid_org_rs = $c->schema->resultset('PendingOrganisation')->search({ submitted_by_id => $user->id });
$validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs ); $validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs );
return $c->api_validation_error if $validation->has_error;
$organisation = $valid_org_rs->find( $validation->param('organisation_id') );
} elsif ( $type == 3 ) { } elsif ( $type == 3 ) {
# Unknown Organisation # Unknown Organisation
$validation->required('organisation_name'); $validation->required('organisation_name');
$validation->optional('street_name'); $validation->optional('street_name');
$validation->optional('town'); $validation->optional('town');
$validation->optional('postcode')->postcode; $validation->optional('postcode')->postcode;
}
return $c->api_validation_error if $validation->has_error; return $c->api_validation_error if $validation->has_error;
$organisation = $c->schema->resultset('PendingOrganisation')->create({
submitted_by => $user,
submitted_at => DateTime->now,
name => $validation->param('organisation_name'),
street_name => $validation->param('street_name'),
town => $validation->param('town'),
postcode => $validation->param('postcode'),
});
}
my $transaction_value = $validation->param('transaction_value'); my $transaction_value = $validation->param('transaction_value');
my $upload = $validation->param('file'); my $upload = $validation->param('file');
my $file = $c->store_file_from_upload( $upload ); my $file = $c->store_file_from_upload( $upload );
if ( $type == 1 ) { $organisation->create_related(
# Validated organisation 'transactions',
$c->schema->resultset('Transaction')->create({ {
buyeruserid_fk => $user->id, buyer => $user,
sellerorganisationid_fk => $validation->param('organisation_id'), value => $transaction_value,
valuemicrocurrency => $transaction_value,
proof_image => $file, proof_image => $file,
timedatesubmitted => DateTime->now, }
}); );
} elsif ( $type == 2 ) {
# Unvalidated Organisation
$c->schema->resultset('PendingTransaction')->create({
buyeruserid_fk => $user->id,
pendingsellerorganisationid_fk => $validation->param('organisation_id'),
valuemicrocurrency => $transaction_value,
proof_image => $file,
timedatesubmitted => DateTime->now,
});
} elsif ( $type == 3 ) {
my $organisation_name = $validation->param('organisation_name');
my $street_name = $validation->param('street_name');
my $town = $validation->param('town');
my $postcode = $validation->param('postcode');
my $pending_org = $c->schema->resultset('PendingOrganisation')->create({ return $c->render( json => {
submitted_by => $user,
submitted_at => DateTime->now,
name => $organisation_name,
street_name => $street_name,
town => $town,
postcode => $postcode,
});
$c->schema->resultset('PendingTransaction')->create({
buyeruserid_fk => $user->id,
pendingsellerorganisationid_fk => $pending_org->id,
valuemicrocurrency => $transaction_value,
proof_image => $file,
timedatesubmitted => DateTime->now,
});
}
return $self->render( json => {
success => Mojo::JSON->true, success => Mojo::JSON->true,
message => 'Upload Successful', message => 'Upload Successful',
}); });
} }

View file

@ -1,4 +1,3 @@
use utf8;
package Pear::LocalLoop::Schema::Result::AccountToken; package Pear::LocalLoop::Schema::Result::AccountToken;
use strict; use strict;

View file

@ -1,4 +1,3 @@
use utf8;
package Pear::LocalLoop::Schema::Result::AgeRange; package Pear::LocalLoop::Schema::Result::AgeRange;
use strict; use strict;

View file

@ -1,4 +1,3 @@
use utf8;
package Pear::LocalLoop::Schema::Result::Customer; package Pear::LocalLoop::Schema::Result::Customer;
use strict; use strict;

View file

@ -41,7 +41,7 @@ __PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many( __PACKAGE__->has_many(
"transactions", "transactions",
"Pear::LocalLoop::Schema::Result::Transaction", "Pear::LocalLoop::Schema::Result::Transaction",
{ "foreign.sellerorganisationid_fk" => 'self.id' }, { "foreign.seller_id" => 'self.id' },
{ cascade_copy => 0, cascade_delete => 0 }, { cascade_copy => 0, cascade_delete => 0 },
); );

View file

@ -5,7 +5,10 @@ use warnings;
use base 'DBIx::Class::Core'; use base 'DBIx::Class::Core';
__PACKAGE__->load_components("InflateColumn::DateTime"); __PACKAGE__->load_components( qw/
InflateColumn::DateTime
TimeStamp
/);
__PACKAGE__->table("pending_organisations"); __PACKAGE__->table("pending_organisations");
@ -42,16 +45,17 @@ __PACKAGE__->add_columns(
submitted_at => { submitted_at => {
data_type => "datetime", data_type => "datetime",
is_nullable => 0, is_nullable => 0,
set_on_create => 1,
}, },
); );
__PACKAGE__->set_primary_key('id'); __PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many( __PACKAGE__->has_many(
"pending_transactions", "transactions",
"Pear::LocalLoop::Schema::Result::PendingTransaction", "Pear::LocalLoop::Schema::Result::PendingTransaction",
{ {
"foreign.pendingsellerorganisationid_fk" => "self.id", "foreign.seller_id" => "self.id",
}, },
{ cascade_copy => 0, cascade_delete => 1 }, { cascade_copy => 0, cascade_delete => 1 },
); );

View file

@ -1,4 +1,3 @@
use utf8;
package Pear::LocalLoop::Schema::Result::PendingTransaction; package Pear::LocalLoop::Schema::Result::PendingTransaction;
use strict; use strict;
@ -8,43 +7,56 @@ use base 'DBIx::Class::Core';
__PACKAGE__->load_components( qw/ __PACKAGE__->load_components( qw/
InflateColumn::DateTime InflateColumn::DateTime
InflateColumn::FS TimeStamp
/); /);
__PACKAGE__->table("PendingTransactions"); __PACKAGE__->table("pending_transactions");
__PACKAGE__->add_columns( __PACKAGE__->add_columns(
"pendingtransactionid", "id" => {
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, data_type => "integer",
"buyeruserid_fk", is_auto_increment => 1,
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, is_nullable => 0,
"pendingsellerorganisationid_fk", },
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, "buyer_id" => {
"valuemicrocurrency", data_type => "integer",
{ data_type => "integer", is_nullable => 0 }, is_foreign_key => 1,
"proof_image", is_nullable => 0,
{ },
"seller_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
"value" => {
data_type => "decimal",
size => [ 16, 2 ],
is_nullable => 0,
},
"proof_image" => {
data_type => "text", data_type => "text",
is_nullable => 0, is_nullable => 0,
}, },
"timedatesubmitted", "submitted_at" => {
{ data_type => "datetime", is_nullable => 0 }, data_type => "datetime",
is_nullable => 0,
set_on_create => 1,
},
); );
__PACKAGE__->set_primary_key("id");
__PACKAGE__->set_primary_key("pendingtransactionid");
__PACKAGE__->belongs_to( __PACKAGE__->belongs_to(
"buyeruserid_fk", "buyer",
"Pear::LocalLoop::Schema::Result::User", "Pear::LocalLoop::Schema::Result::User",
{ id => "buyeruserid_fk" }, { id => "buyer_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
); );
__PACKAGE__->belongs_to( __PACKAGE__->belongs_to(
"pendingsellerorganisationid_fk", "seller",
"Pear::LocalLoop::Schema::Result::PendingOrganisation", "Pear::LocalLoop::Schema::Result::PendingOrganisation",
{ id => "pendingsellerorganisationid_fk" }, { id => "seller_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
); );

View file

@ -1,122 +1,39 @@
use utf8;
package Pear::LocalLoop::Schema::Result::SessionToken; package Pear::LocalLoop::Schema::Result::SessionToken;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
=head1 NAME
Pear::LocalLoop::Schema::Result::SessionToken
=cut
use strict; use strict;
use warnings; use warnings;
use base 'DBIx::Class::Core'; use base 'DBIx::Class::Core';
=head1 COMPONENTS LOADED __PACKAGE__->table("session_tokens");
=over 4
=item * L<DBIx::Class::InflateColumn::DateTime>
=back
=cut
__PACKAGE__->load_components("InflateColumn::DateTime");
=head1 TABLE: C<SessionTokens>
=cut
__PACKAGE__->table("SessionTokens");
=head1 ACCESSORS
=head2 sessiontokenid
data_type: 'integer'
is_auto_increment: 1
is_nullable: 0
=head2 sessiontokenname
data_type: 'text'
is_nullable: 0
=head2 useridassignedto_fk
data_type: 'integer'
is_foreign_key: 1
is_nullable: 0
=head2 expiredatetime
data_type: 'integer'
is_nullable: 0
=cut
__PACKAGE__->add_columns( __PACKAGE__->add_columns(
"sessiontokenid", "id" => {
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, data_type => "integer",
"sessiontokenname", is_auto_increment => 1,
{ data_type => "text", is_nullable => 0 }, is_nullable => 0,
"useridassignedto_fk", },
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, "token" => {
"expiredatetime", data_type => "varchar",
{ data_type => "datetime", is_nullable => 0 }, size => 255,
is_nullable => 0,
},
"user_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
); );
=head1 PRIMARY KEY __PACKAGE__->set_primary_key("id");
=over 4 __PACKAGE__->add_unique_constraint(["token"]);
=item * L</sessiontokenid>
=back
=cut
__PACKAGE__->set_primary_key("sessiontokenid");
=head1 UNIQUE CONSTRAINTS
=head2 C<sessiontokenname_unique>
=over 4
=item * L</sessiontokenname>
=back
=cut
__PACKAGE__->add_unique_constraint("sessiontokenname_unique", ["sessiontokenname"]);
=head1 RELATIONS
=head2 useridassignedto_fk
Type: belongs_to
Related object: L<Pear::LocalLoop::Schema::Result::User>
=cut
__PACKAGE__->belongs_to( __PACKAGE__->belongs_to(
"user", "user",
"Pear::LocalLoop::Schema::Result::User", "Pear::LocalLoop::Schema::Result::User",
{ id => "useridassignedto_fk" }, { id => "user_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
); );
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-24 17:32:21
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/mNAPeSmfsDSIpey+eUucg
# You can replace this text with custom code or comments, and it will be preserved on regeneration
1; 1;

View file

@ -1,144 +1,63 @@
use utf8;
package Pear::LocalLoop::Schema::Result::Transaction; package Pear::LocalLoop::Schema::Result::Transaction;
# Created by DBIx::Class::Schema::Loader
# DO NOT MODIFY THE FIRST PART OF THIS FILE
=head1 NAME
Pear::LocalLoop::Schema::Result::Transaction
=cut
use strict; use strict;
use warnings; use warnings;
use base 'DBIx::Class::Core'; use base 'DBIx::Class::Core';
=head1 COMPONENTS LOADED
=over 4
=item * L<DBIx::Class::InflateColumn::DateTime>
=back
=cut
__PACKAGE__->load_components(qw/ __PACKAGE__->load_components(qw/
InflateColumn::DateTime InflateColumn::DateTime
InflateColumn::FS TimeStamp
/); /);
=head1 TABLE: C<Transactions> __PACKAGE__->table("transactions");
=cut
__PACKAGE__->table("Transactions");
=head1 ACCESSORS
=head2 transactionid
data_type: 'integer'
is_auto_increment: 1
is_nullable: 0
=head2 buyeruserid_fk
data_type: 'integer'
is_foreign_key: 1
is_nullable: 0
=head2 sellerorganisationid_fk
data_type: 'integer'
is_foreign_key: 1
is_nullable: 0
=head2 valuemicrocurrency
data_type: 'integer'
is_nullable: 0
=head2 proofimage
data_type: 'text'
is_nullable: 0
=head2 timedatesubmitted
data_type: 'integer'
is_nullable: 0
=cut
__PACKAGE__->add_columns( __PACKAGE__->add_columns(
"transactionid", "id" => {
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, data_type => "integer",
"buyeruserid_fk", is_auto_increment => 1,
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, is_nullable => 0,
"sellerorganisationid_fk", },
{ data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, "buyer_id" => {
"valuemicrocurrency", data_type => "integer",
{ data_type => "integer", is_nullable => 0 }, is_foreign_key => 1,
"proof_image", is_nullable => 0,
{ },
"seller_id" => {
data_type => "integer",
is_foreign_key => 1,
is_nullable => 0,
},
"value" => {
data_type => "decimal",
size => [ 16, 2 ],
is_nullable => 0,
},
"proof_image" => {
data_type => "text", data_type => "text",
is_nullable => 0, is_nullable => 0,
}, },
"timedatesubmitted", "submitted_at" => {
{ data_type => "datetime", is_nullable => 0 }, data_type => "datetime",
is_nullable => 0,
set_on_create => 1,
},
); );
=head1 PRIMARY KEY __PACKAGE__->set_primary_key("id");
=over 4
=item * L</transactionid>
=back
=cut
__PACKAGE__->set_primary_key("transactionid");
=head1 RELATIONS
=head2 buyeruserid_fk
Type: belongs_to
Related object: L<Pear::LocalLoop::Schema::Result::User>
=cut
__PACKAGE__->belongs_to( __PACKAGE__->belongs_to(
"buyeruserid_fk", "buyer",
"Pear::LocalLoop::Schema::Result::User", "Pear::LocalLoop::Schema::Result::User",
{ id => "buyeruserid_fk" }, { id => "buyer_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
); );
=head2 sellerorganisationid_fk
Type: belongs_to
Related object: L<Pear::LocalLoop::Schema::Result::Organisation>
=cut
__PACKAGE__->belongs_to( __PACKAGE__->belongs_to(
"sellerorganisationid_fk", "seller",
"Pear::LocalLoop::Schema::Result::Organisation", "Pear::LocalLoop::Schema::Result::Organisation",
{ id => "sellerorganisationid_fk" }, { id => "seller_id" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, { is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" },
); );
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2017-02-24 17:32:21
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:CfPoE2egoSD1tKo7fYjZdg
# You can replace this text with custom code or comments, and it will be preserved on regeneration
1; 1;

View file

@ -1,4 +1,3 @@
use utf8;
package Pear::LocalLoop::Schema::Result::User; package Pear::LocalLoop::Schema::Result::User;
use strict; use strict;
@ -6,6 +5,8 @@ use warnings;
use base 'DBIx::Class::Core'; use base 'DBIx::Class::Core';
use Data::UUID;
__PACKAGE__->load_components( qw/ __PACKAGE__->load_components( qw/
InflateColumn::DateTime InflateColumn::DateTime
PassphraseColumn PassphraseColumn
@ -70,7 +71,7 @@ __PACKAGE__->might_have(
__PACKAGE__->belongs_to( __PACKAGE__->belongs_to(
"customer", "customer",
"Pear::LocalLoop::Schema::Result::Customer", "Pear::LocalLoop::Schema::Result::Customer",
{ id => "customer_id" }, { "foreign.id" => "self.customer_id" },
{ {
is_deferrable => 0, is_deferrable => 0,
join_type => "LEFT", join_type => "LEFT",
@ -82,7 +83,7 @@ __PACKAGE__->belongs_to(
__PACKAGE__->belongs_to( __PACKAGE__->belongs_to(
"organisation", "organisation",
"Pear::LocalLoop::Schema::Result::Organisation", "Pear::LocalLoop::Schema::Result::Organisation",
{ id => "organisation_id" }, { "foreign.id" => "self.organisation_id" },
{ {
is_deferrable => 0, is_deferrable => 0,
join_type => "LEFT", join_type => "LEFT",
@ -101,22 +102,36 @@ __PACKAGE__->has_many(
__PACKAGE__->has_many( __PACKAGE__->has_many(
"pending_transactions", "pending_transactions",
"Pear::LocalLoop::Schema::Result::PendingTransaction", "Pear::LocalLoop::Schema::Result::PendingTransaction",
{ "foreign.buyeruserid_fk" => "self.id" }, { "foreign.buyer_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 }, { cascade_copy => 0, cascade_delete => 0 },
); );
__PACKAGE__->has_many( __PACKAGE__->has_many(
"session_tokens", "session_tokens",
"Pear::LocalLoop::Schema::Result::SessionToken", "Pear::LocalLoop::Schema::Result::SessionToken",
{ "foreign.useridassignedto_fk" => "self.id" }, { "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 }, { cascade_copy => 0, cascade_delete => 0 },
); );
__PACKAGE__->has_many( __PACKAGE__->has_many(
"transactions", "transactions",
"Pear::LocalLoop::Schema::Result::Transaction", "Pear::LocalLoop::Schema::Result::Transaction",
{ "foreign.buyeruserid_fk" => "self.id" }, { "foreign.buyer_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 }, { cascade_copy => 0, cascade_delete => 0 },
); );
sub generate_session {
my $self = shift;
my $token = Data::UUID->new->create_str();
$self->create_related(
'session_tokens',
{
token => $token,
},
);
return $token;
}
1; 1;

View file

@ -84,7 +84,7 @@ $testJson = {
'password' => $passwordReno, 'password' => $passwordReno,
}; };
$t->post_ok('/api/login' => json => $testJson) $t->post_ok('/api/login' => json => $testJson)
->status_is(200) ->status_is(200)->or($dump_error)
->json_is('/success', Mojo::JSON->true); ->json_is('/success', Mojo::JSON->true);
my $session_key = $t->tx->res->json('/session_key'); my $session_key = $t->tx->res->json('/session_key');
@ -129,7 +129,7 @@ $t->post_ok('/api/admin-approve' => json => $json)
print "test 8 - Logout Reno\n"; print "test 8 - Logout Reno\n";
$t->post_ok('/api/logout', json => { session_key => $session_key } ) $t->post_ok('/api/logout', json => { session_key => $session_key } )
->status_is(200) ->status_is(200)->or($dump_error)
->json_is('/success', Mojo::JSON->true); ->json_is('/success', Mojo::JSON->true);
#End of non-admin Reno #End of non-admin Reno