public function profile($id = null)
{
$loggedUserId = $this->Auth->user('id');
$isCurrentUser = false;
if (!Configure::read('Users.Profile.viewOthers') || empty($id)) {
$id = $loggedUserId;
}
try {
$appContain = (array) Configure::read('Auth.authenticate.' . AuthComponent::ALL . '.contain');
$socialContain = Configure::read('Users.Social.login') ? ['SocialAccounts'] : [];
$user = $this->getUsersTable()->get($id, ['contain' => array_merge((array) $appContain, (array) $socialContain)]);
$this->set('avatarPlaceholder', Configure::read('Users.Avatar.placeholder'));
if ($user->id === $loggedUserId) {
$isCurrentUser = true;
}
} catch (RecordNotFoundException $ex) {
$this->Flash->error(__d('CakeDC/Users', 'User was not found'));
return $this->redirect($this->request->referer());
} catch (InvalidPrimaryKeyException $ex) {
$this->Flash->error(__d('CakeDC/Users', 'Not authorized, please login first'));
return $this->redirect($this->request->referer());
}
$this->set(compact('user', 'isCurrentUser'));
$this->set('_serialize', ['user', 'isCurrentUser']);
}