Fix new rider api login #617
This commit is contained in:
parent
973ba8ff00
commit
e7fb5014ff
2 changed files with 27 additions and 19 deletions
|
|
@ -16,13 +16,13 @@ security:
|
||||||
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
pattern: ^/(_(profiler|wdt)|css|images|js)/
|
||||||
security: false
|
security: false
|
||||||
|
|
||||||
login:
|
|
||||||
pattern: ^\/login$
|
|
||||||
methods: [GET]
|
|
||||||
security: false
|
|
||||||
|
|
||||||
new_rider_api_login:
|
new_rider_api_login:
|
||||||
pattern: ^\/rider_api\/login$
|
pattern: ^\/rider_api\/login$
|
||||||
|
methods: [POST]
|
||||||
|
security: false
|
||||||
|
|
||||||
|
login:
|
||||||
|
pattern: ^\/login$
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
security: false
|
security: false
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -128,15 +128,26 @@ class RiderAppController extends APIController
|
||||||
];
|
];
|
||||||
|
|
||||||
// TODO: right now, no validation at all. Accept anything.
|
// TODO: right now, no validation at all. Accept anything.
|
||||||
// get capi user
|
|
||||||
$capi_user = $this->getCAPIUser($this->getUser()->getID(), $em);
|
|
||||||
if ($capi_user == null)
|
|
||||||
return new APIResponse(false, 'User not found.');
|
|
||||||
|
|
||||||
// get rider id from capi user metadata
|
|
||||||
$rider = $this->getRiderFromCAPI($capi_user, $em);
|
// NOTE: we retain the username and password in rider for backward compatibility
|
||||||
|
// look for rider with username
|
||||||
|
$rider = $em->getRepository(Rider::class)->findOneBy(['username' => $req->request->get('user')]);
|
||||||
if ($rider == null)
|
if ($rider == null)
|
||||||
return new APIResponse(false, 'No rider found.');
|
return new APIResponse(false, 'Invalid username or password.');
|
||||||
|
|
||||||
|
// check if rider password is correct
|
||||||
|
// NOTE: we use
|
||||||
|
$encoder = $ef->getEncoder(new User());
|
||||||
|
if (!$encoder->isPasswordValid($rider->getPassword(), $req->request->get('pass'), ''))
|
||||||
|
return new APIResponse(false, 'Invalid username or password.');
|
||||||
|
|
||||||
|
// user will be the one linked to the rider
|
||||||
|
$user = $rider->getAPIUser();
|
||||||
|
// no linked user, cannot login
|
||||||
|
if ($user == null)
|
||||||
|
return new APIResponse(false, 'Rider cannot login, no associated user.');
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
$missing = $this->checkMissingParameters($req, $required_params);
|
$missing = $this->checkMissingParameters($req, $required_params);
|
||||||
|
|
@ -225,8 +236,8 @@ class RiderAppController extends APIController
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'api_key' => $capi_user->getAPIKey(),
|
'api_key' => $user->getAPIKey(),
|
||||||
'secret_key' => $capi_user->getSecretKey(),
|
'secret_key' => $user->getSecretKey(),
|
||||||
];
|
];
|
||||||
|
|
||||||
return new APIResponse(true, 'Rider logged in.', $data);
|
return new APIResponse(true, 'Rider logged in.', $data);
|
||||||
|
|
@ -1245,16 +1256,13 @@ class RiderAppController extends APIController
|
||||||
|
|
||||||
protected function getRiderFromCAPI($capi_user, $em)
|
protected function getRiderFromCAPI($capi_user, $em)
|
||||||
{
|
{
|
||||||
// TODO: uncomment once getMetadata is available
|
|
||||||
/*
|
|
||||||
$metadata = $capi_user->getMetadata();
|
|
||||||
//get rider id from metadata
|
//get rider id from metadata
|
||||||
|
$metadata = $capi_user->getMetadata();
|
||||||
$rider_id = $metadata['rider_id'];
|
$rider_id = $metadata['rider_id'];
|
||||||
|
|
||||||
// get rider
|
// get rider
|
||||||
$rider = $em->getRepository(Rider::class)->find($rider_id);
|
$rider = $em->getRepository(Rider::class)->find($rider_id);
|
||||||
return $rider;
|
return $rider;
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkMissingParameters(Request $req, $params = [])
|
protected function checkMissingParameters(Request $req, $params = [])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue