Add index for capi user ID. Add checking if user already registered. #591
This commit is contained in:
parent
8fd9aed174
commit
edaa514f57
2 changed files with 19 additions and 4 deletions
|
|
@ -44,6 +44,12 @@ class CustomerController extends APIController
|
||||||
|
|
||||||
// get capi user to link to mobile user
|
// get capi user to link to mobile user
|
||||||
$user_id = $this->getUser()->getID();
|
$user_id = $this->getUser()->getID();
|
||||||
|
|
||||||
|
// check if capi user already has a mobile user
|
||||||
|
$mobile_user = $this->findMobileUser($user_id, $em);
|
||||||
|
if ($mobile_user != null)
|
||||||
|
return new APIResponse(false, 'User already registered');
|
||||||
|
|
||||||
// retry until we get a unique id
|
// retry until we get a unique id
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|
@ -82,9 +88,8 @@ class CustomerController extends APIController
|
||||||
}
|
}
|
||||||
|
|
||||||
// return data
|
// return data
|
||||||
// need to make sure the names returned to app are the same
|
// TODO: do we need to return the same names as before?
|
||||||
// so we still use session_id name
|
// right now, still usind the old names so we use session_id name
|
||||||
// TODO: depending on what data type we return, this might need changes
|
|
||||||
$data = [
|
$data = [
|
||||||
'session_id' => $mobile_user->getID()
|
'session_id' => $mobile_user->getID()
|
||||||
];
|
];
|
||||||
|
|
@ -468,6 +473,13 @@ class CustomerController extends APIController
|
||||||
return $res->getReturnResponse();
|
return $res->getReturnResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function findMobileUser($user_id, $em)
|
||||||
|
{
|
||||||
|
$mobile_user = $em->getRepository(MobileUser::class)->findBy(['capi_user_id' => $user_id]);
|
||||||
|
|
||||||
|
return $mobile_user;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: this might not be needed if we use APIController's checkRequiredParameters
|
// TODO: this might not be needed if we use APIController's checkRequiredParameters
|
||||||
// or we put this into a service?
|
// or we put this into a service?
|
||||||
protected function checkMissingParameters(Request $req, $params = [])
|
protected function checkMissingParameters(Request $req, $params = [])
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,10 @@ use DateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ORM\Entity
|
* @ORM\Entity
|
||||||
* @ORM\Table(name="mobile_user")
|
* @ORM\Table(
|
||||||
|
* name="mobile_user",
|
||||||
|
* indexes={@ORM\Index(name="capi_user_idx", columns={"capi_user_id"})}
|
||||||
|
* )
|
||||||
*/
|
*/
|
||||||
class MobileUser
|
class MobileUser
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue