Merge pull request #37 from Pear-Trading/TBSliver/Login-Info
Added extra info to login return
This commit is contained in:
commit
df7f1de1a6
5 changed files with 31 additions and 34 deletions
|
@ -50,7 +50,7 @@ sub startup {
|
||||||
return $user->id;
|
return $user->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undef;
|
return;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -79,20 +79,12 @@ 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 = $user_result->generate_session;
|
my $session_key = $user_result->generate_session;
|
||||||
my $display_name;
|
|
||||||
|
|
||||||
if ( defined $user_result->customer_id ) {
|
|
||||||
$display_name = $user_result->customer->display_name;
|
|
||||||
} elsif ( defined $user_result->organisation_id ) {
|
|
||||||
$display_name = $user_result->organisation->name;
|
|
||||||
} else {
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $c->render( json => {
|
return $c->render( json => {
|
||||||
success => Mojo::JSON->true,
|
success => Mojo::JSON->true,
|
||||||
session_key => $session_key,
|
session_key => $session_key,
|
||||||
display_name => $display_name,
|
display_name => $user_result->name,
|
||||||
|
user_type => $user_result->type,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ sub post_account {
|
||||||
} elsif ( defined $user_result->organisation_id ) {
|
} elsif ( defined $user_result->organisation_id ) {
|
||||||
$display_name = $user_result->organisation->name;
|
$display_name = $user_result->organisation->name;
|
||||||
} else {
|
} else {
|
||||||
return undef;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $c->render( json => {
|
return $c->render( json => {
|
||||||
|
|
|
@ -149,8 +149,17 @@ sub name {
|
||||||
} elsif ( defined $self->organisation_id ) {
|
} elsif ( defined $self->organisation_id ) {
|
||||||
return $self->organisation->name;
|
return $self->organisation->name;
|
||||||
} else {
|
} else {
|
||||||
return undef;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub type {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
if ( defined $self->customer_id ) {
|
||||||
|
return "customer";
|
||||||
|
}
|
||||||
|
return "organisation";
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -8,28 +8,22 @@ my $framework = Test::Pear::LocalLoop->new;
|
||||||
my $t = $framework->framework;
|
my $t = $framework->framework;
|
||||||
my $schema = $t->app->schema;
|
my $schema = $t->app->schema;
|
||||||
|
|
||||||
my $account_token = 'a';
|
my $user = {
|
||||||
my $email = 'rufus@shinra.energy';
|
token => 'a',
|
||||||
my $password = 'MakoGold';
|
usertype => 'customer',
|
||||||
|
display_name => 'Display Guy',
|
||||||
$schema->resultset('AccountToken')->create({
|
full_name => 'Real Name',
|
||||||
name => $account_token
|
email => 'test@example.com',
|
||||||
});
|
postcode => 'LA1 1AA',
|
||||||
|
password => 'testerising',
|
||||||
my $test_json = {
|
year_of_birth => 2006,
|
||||||
'usertype' => 'customer',
|
|
||||||
'token' => $account_token,
|
|
||||||
'display_name' => 'RufusShinra',
|
|
||||||
'full_name' => 'RufusShinra',
|
|
||||||
'email' => $email,
|
|
||||||
'postcode' => 'LA1 1AA',
|
|
||||||
'password' => $password,
|
|
||||||
year_of_birth => 2006
|
|
||||||
};
|
};
|
||||||
$t->post_ok('/api/register' => json => $test_json)
|
|
||||||
|
$schema->resultset('AccountToken')->create({ name => $user->{token} });
|
||||||
|
|
||||||
|
$t->post_ok('/api/register' => json => $user)
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true);
|
->json_is('/success', Mojo::JSON->true);
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
is $schema->resultset('User')->count, 1, 'found a user';
|
is $schema->resultset('User')->count, 1, 'found a user';
|
||||||
|
|
||||||
|
@ -48,11 +42,13 @@ $t->post_ok('/api/login' => json => {
|
||||||
->json_is('/success', Mojo::JSON->false);
|
->json_is('/success', Mojo::JSON->false);
|
||||||
|
|
||||||
$t->post_ok('/api/login' => json => {
|
$t->post_ok('/api/login' => json => {
|
||||||
email => $email,
|
email => $user->{email},
|
||||||
password => $password,
|
password => $user->{password},
|
||||||
})
|
})
|
||||||
->status_is(200)
|
->status_is(200)
|
||||||
->json_is('/success', Mojo::JSON->true)
|
->json_is('/success', Mojo::JSON->true)
|
||||||
|
->json_is('/display_name', 'Display Guy')
|
||||||
|
->json_is('/user_type', 'customer')
|
||||||
->json_has('/session_key');
|
->json_has('/session_key');
|
||||||
|
|
||||||
my $session_key = $t->tx->res->json->{session_key};
|
my $session_key = $t->tx->res->json->{session_key};
|
||||||
|
|
Reference in a new issue