Slide 127
Slide 127 text
$app->get('/user/:id', $checkToken(), function ($id) use ($server, $app) {
$user_model = new UserModel();
$user = $user_model->getUser($id);
// Basic response
$response = array(
'error' => null,
'result' => array(
'user_id' => $user['id'],
'firstname' => $user['firstname'],
'lastname' => $user['lastname']
)
);
// If the acess token has the "user.contact" access token include
// an email address and phone number
if ($server->hasScope('user.contact'))
{
$response['result']['email'] = $user['email'];
$response['result']['phone'] = $user['phone'];
}
// Respond
$res = $app->response();
$res['Content-Type'] = 'application/json';
$res->body(json_encode($response));
});
Tuesday, 19 March 13