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 undef;
|
||||
return;
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -79,20 +79,12 @@ sub post_login {
|
|||
if ( defined $user_result ) {
|
||||
if ( $user_result->check_password($password) ) {
|
||||
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 => {
|
||||
success => Mojo::JSON->true,
|
||||
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 ) {
|
||||
$display_name = $user_result->organisation->name;
|
||||
} else {
|
||||
return undef;
|
||||
return;
|
||||
}
|
||||
|
||||
return $c->render( json => {
|
||||
|
|
|
@ -149,8 +149,17 @@ sub name {
|
|||
} elsif ( defined $self->organisation_id ) {
|
||||
return $self->organisation->name;
|
||||
} else {
|
||||
return undef;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sub type {
|
||||
my $self = shift;
|
||||
|
||||
if ( defined $self->customer_id ) {
|
||||
return "customer";
|
||||
}
|
||||
return "organisation";
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -8,28 +8,22 @@ my $framework = Test::Pear::LocalLoop->new;
|
|||
my $t = $framework->framework;
|
||||
my $schema = $t->app->schema;
|
||||
|
||||
my $account_token = 'a';
|
||||
my $email = 'rufus@shinra.energy';
|
||||
my $password = 'MakoGold';
|
||||
|
||||
$schema->resultset('AccountToken')->create({
|
||||
name => $account_token
|
||||
});
|
||||
|
||||
my $test_json = {
|
||||
'usertype' => 'customer',
|
||||
'token' => $account_token,
|
||||
'display_name' => 'RufusShinra',
|
||||
'full_name' => 'RufusShinra',
|
||||
'email' => $email,
|
||||
'postcode' => 'LA1 1AA',
|
||||
'password' => $password,
|
||||
year_of_birth => 2006
|
||||
my $user = {
|
||||
token => 'a',
|
||||
usertype => 'customer',
|
||||
display_name => 'Display Guy',
|
||||
full_name => 'Real Name',
|
||||
email => 'test@example.com',
|
||||
postcode => 'LA1 1AA',
|
||||
password => 'testerising',
|
||||
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)
|
||||
->json_is('/success', Mojo::JSON->true);
|
||||
use Data::Dumper;
|
||||
|
||||
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);
|
||||
|
||||
$t->post_ok('/api/login' => json => {
|
||||
email => $email,
|
||||
password => $password,
|
||||
email => $user->{email},
|
||||
password => $user->{password},
|
||||
})
|
||||
->status_is(200)
|
||||
->json_is('/success', Mojo::JSON->true)
|
||||
->json_is('/display_name', 'Display Guy')
|
||||
->json_is('/user_type', 'customer')
|
||||
->json_has('/session_key');
|
||||
|
||||
my $session_key = $t->tx->res->json->{session_key};
|
||||
|
|
Reference in a new issue