forked from CakeDC/users
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfileTrait.php
More file actions
52 lines (47 loc) · 1.55 KB
/
Copy pathProfileTrait.php
File metadata and controls
52 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2015, Cake Development Corporation (http://cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
namespace Users\Controller\Traits;
use Cake\Core\Configure;
use Cake\Datasource\Exception\InvalidPrimaryKeyException;
/**
* Covers the login, logout and social login, proxy to UsersAuthComponent methods
*
*/
trait ProfileTrait
{
/**
* Profile action
* @param mixed $id Profile id object.
* @return mixed
*/
public function profile($id = null)
{
$loggedUserId = $this->Auth->user('id');
$isCurrentUser = false;
if (!Configure::read('Users.Profile.viewOthers') || empty($id)) {
$id = $loggedUserId;
}
try {
$user = $this->getUsersTable()->get($id, [
'contain' => ['SocialAccounts']
]);
$this->set('avatarPlaceholder', Configure::read('Users.Avatar.placeholder'));
if ($user->id === $loggedUserId) {
$isCurrentUser = true;
}
} catch (InvalidPrimaryKeyException $ipke) {
$this->Flash->error(__d('Users', 'User was not found', $id));
return $this->redirect($this->request->referer());
}
$this->set(compact('user', 'isCurrentUser'));
$this->set('_serialize', ['user', 'isCurrentUser']);
}
}