@@ -5,113 +5,113 @@ |
||
5 | 5 | |
6 | 6 | class CachingDecorator |
7 | 7 | { |
8 | - /** |
|
9 | - * The repo implementation. |
|
10 | - * |
|
11 | - * @var string |
|
12 | - */ |
|
13 | - public $repo; |
|
8 | + /** |
|
9 | + * The repo implementation. |
|
10 | + * |
|
11 | + * @var string |
|
12 | + */ |
|
13 | + public $repo; |
|
14 | 14 | |
15 | - /** |
|
16 | - * The cache implementation. |
|
17 | - * |
|
18 | - * @var object |
|
19 | - */ |
|
20 | - protected $cache; |
|
15 | + /** |
|
16 | + * The cache implementation. |
|
17 | + * |
|
18 | + * @var object |
|
19 | + */ |
|
20 | + protected $cache; |
|
21 | 21 | |
22 | - /** |
|
23 | - * The modelKey implementation. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - public $modelKey; |
|
22 | + /** |
|
23 | + * The modelKey implementation. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public $modelKey; |
|
28 | 28 | |
29 | - /** |
|
30 | - * The model implementation. |
|
31 | - * |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - public $model; |
|
29 | + /** |
|
30 | + * The model implementation. |
|
31 | + * |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + public $model; |
|
35 | 35 | |
36 | - /** |
|
37 | - * The modelClass implementation. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $modelClass; |
|
36 | + /** |
|
37 | + * The modelClass implementation. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $modelClass; |
|
42 | 42 | |
43 | - /** |
|
44 | - * The cacheConfig implementation. |
|
45 | - * |
|
46 | - * @var mixed |
|
47 | - */ |
|
48 | - public $cacheConfig; |
|
43 | + /** |
|
44 | + * The cacheConfig implementation. |
|
45 | + * |
|
46 | + * @var mixed |
|
47 | + */ |
|
48 | + public $cacheConfig; |
|
49 | 49 | |
50 | - /** |
|
51 | - * The cacheTag implementation. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - public $cacheTag; |
|
50 | + /** |
|
51 | + * The cacheTag implementation. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + public $cacheTag; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Init new object. |
|
59 | - * |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public function __construct($repo, $cache) |
|
63 | - { |
|
64 | - $this->repo = $repo; |
|
65 | - $this->cache = $cache; |
|
66 | - $this->model = $this->repo->model; |
|
67 | - $this->modelClass = get_class($this->model); |
|
68 | - $repoClass = explode('\\', get_class($this->repo)); |
|
69 | - $repoName = end($repoClass); |
|
70 | - $this->cacheTag = Str::plural(lcfirst(substr($repoName, 0, strpos($repoName, 'Repository')))); |
|
71 | - } |
|
57 | + /** |
|
58 | + * Init new object. |
|
59 | + * |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public function __construct($repo, $cache) |
|
63 | + { |
|
64 | + $this->repo = $repo; |
|
65 | + $this->cache = $cache; |
|
66 | + $this->model = $this->repo->model; |
|
67 | + $this->modelClass = get_class($this->model); |
|
68 | + $repoClass = explode('\\', get_class($this->repo)); |
|
69 | + $repoName = end($repoClass); |
|
70 | + $this->cacheTag = Str::plural(lcfirst(substr($repoName, 0, strpos($repoName, 'Repository')))); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Handle the cache mechanism for the called method |
|
75 | - * based the configurations. |
|
76 | - * |
|
77 | - * @param string $name the called method name |
|
78 | - * @param array $arguments the method arguments |
|
79 | - * @return object |
|
80 | - */ |
|
81 | - public function __call($name, $arguments) |
|
82 | - { |
|
83 | - $this->setCacheConfig($name); |
|
73 | + /** |
|
74 | + * Handle the cache mechanism for the called method |
|
75 | + * based the configurations. |
|
76 | + * |
|
77 | + * @param string $name the called method name |
|
78 | + * @param array $arguments the method arguments |
|
79 | + * @return object |
|
80 | + */ |
|
81 | + public function __call($name, $arguments) |
|
82 | + { |
|
83 | + $this->setCacheConfig($name); |
|
84 | 84 | |
85 | - if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
|
86 | - $page = \Request::get('page') !== null ? \Request::get('page') : '1'; |
|
87 | - $cacheKey = $name.$page.\Session::get('locale').serialize($arguments); |
|
88 | - return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
89 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
90 | - }); |
|
91 | - } elseif ($this->cacheConfig) { |
|
92 | - $this->cache->tags($this->cacheConfig)->flush(); |
|
93 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
94 | - } |
|
85 | + if ($this->cacheConfig && $this->cacheConfig == 'cache') { |
|
86 | + $page = \Request::get('page') !== null ? \Request::get('page') : '1'; |
|
87 | + $cacheKey = $name.$page.\Session::get('locale').serialize($arguments); |
|
88 | + return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function () use ($arguments, $name) { |
|
89 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
90 | + }); |
|
91 | + } elseif ($this->cacheConfig) { |
|
92 | + $this->cache->tags($this->cacheConfig)->flush(); |
|
93 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
94 | + } |
|
95 | 95 | |
96 | - return call_user_func_array([$this->repo, $name], $arguments); |
|
97 | - } |
|
96 | + return call_user_func_array([$this->repo, $name], $arguments); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Set cache config based on the called method. |
|
101 | - * |
|
102 | - * @param string $name |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - private function setCacheConfig($name) |
|
106 | - { |
|
107 | - $config = \CoreConfig::getConfig(); |
|
108 | - $cacheConfig = Arr::get($config['cacheConfig'], $this->cacheTag, false); |
|
109 | - $this->cacheConfig = false; |
|
99 | + /** |
|
100 | + * Set cache config based on the called method. |
|
101 | + * |
|
102 | + * @param string $name |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + private function setCacheConfig($name) |
|
106 | + { |
|
107 | + $config = \CoreConfig::getConfig(); |
|
108 | + $cacheConfig = Arr::get($config['cacheConfig'], $this->cacheTag, false); |
|
109 | + $this->cacheConfig = false; |
|
110 | 110 | |
111 | - if ($cacheConfig && in_array($name, $cacheConfig['cache'])) { |
|
112 | - $this->cacheConfig = 'cache'; |
|
113 | - } elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) { |
|
114 | - $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
115 | - } |
|
116 | - } |
|
111 | + if ($cacheConfig && in_array($name, $cacheConfig['cache'])) { |
|
112 | + $this->cacheConfig = 'cache'; |
|
113 | + } elseif ($cacheConfig && isset($cacheConfig['clear'][$name])) { |
|
114 | + $this->cacheConfig = $cacheConfig['clear'][$name]; |
|
115 | + } |
|
116 | + } |
|
117 | 117 | } |
@@ -5,14 +5,14 @@ |
||
5 | 5 | |
6 | 6 | class PermissionRepository extends BaseRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Init new object. |
|
10 | - * |
|
11 | - * @param AclPermission $model |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function __construct(AclPermission $model) |
|
15 | - { |
|
16 | - parent::__construct($model); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Init new object. |
|
10 | + * |
|
11 | + * @param AclPermission $model |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function __construct(AclPermission $model) |
|
15 | + { |
|
16 | + parent::__construct($model); |
|
17 | + } |
|
18 | 18 | } |
@@ -5,38 +5,38 @@ |
||
5 | 5 | |
6 | 6 | class OauthClientRepository extends BaseRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Init new object. |
|
10 | - * |
|
11 | - * @param OauthClient $model |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function __construct(OauthClient $model) |
|
15 | - { |
|
16 | - parent::__construct($model); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Init new object. |
|
10 | + * |
|
11 | + * @param OauthClient $model |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function __construct(OauthClient $model) |
|
15 | + { |
|
16 | + parent::__construct($model); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Revoke the given client. |
|
21 | - * |
|
22 | - * @param integer $clientId |
|
23 | - * @return void |
|
24 | - */ |
|
25 | - public function revoke($clientId) |
|
26 | - { |
|
27 | - $client = $this->find($clientId); |
|
28 | - $client->tokens()->update(['revoked' => true]); |
|
29 | - $this->save(['id'=> $clientId, 'revoked' => true]); |
|
30 | - } |
|
19 | + /** |
|
20 | + * Revoke the given client. |
|
21 | + * |
|
22 | + * @param integer $clientId |
|
23 | + * @return void |
|
24 | + */ |
|
25 | + public function revoke($clientId) |
|
26 | + { |
|
27 | + $client = $this->find($clientId); |
|
28 | + $client->tokens()->update(['revoked' => true]); |
|
29 | + $this->save(['id'=> $clientId, 'revoked' => true]); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Un revoke the given client. |
|
34 | - * |
|
35 | - * @param integer $clientId |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - public function unRevoke($clientId) |
|
39 | - { |
|
40 | - $this->save(['id'=> $clientId, 'revoked' => false]); |
|
41 | - } |
|
32 | + /** |
|
33 | + * Un revoke the given client. |
|
34 | + * |
|
35 | + * @param integer $clientId |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + public function unRevoke($clientId) |
|
39 | + { |
|
40 | + $this->save(['id'=> $clientId, 'revoked' => false]); |
|
41 | + } |
|
42 | 42 | } |
@@ -5,32 +5,32 @@ |
||
5 | 5 | |
6 | 6 | class GroupRepository extends BaseRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Init new object. |
|
10 | - * |
|
11 | - * @param AclGroup $model |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function __construct(AclGroup $model) |
|
15 | - { |
|
16 | - parent::__construct($model); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Init new object. |
|
10 | + * |
|
11 | + * @param AclGroup $model |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function __construct(AclGroup $model) |
|
15 | + { |
|
16 | + parent::__construct($model); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Assign the given permission ids to the given group. |
|
21 | - * |
|
22 | - * @param integer $groupId |
|
23 | - * @param array $permissionIds |
|
24 | - * @return object |
|
25 | - */ |
|
26 | - public function assignPermissions($groupId, $permissionIds) |
|
27 | - { |
|
28 | - \DB::transaction(function () use ($groupId, $permissionIds) { |
|
29 | - $group = $this->find($groupId); |
|
30 | - $group->permissions()->detach(); |
|
31 | - $group->permissions()->attach($permissionIds); |
|
32 | - }); |
|
19 | + /** |
|
20 | + * Assign the given permission ids to the given group. |
|
21 | + * |
|
22 | + * @param integer $groupId |
|
23 | + * @param array $permissionIds |
|
24 | + * @return object |
|
25 | + */ |
|
26 | + public function assignPermissions($groupId, $permissionIds) |
|
27 | + { |
|
28 | + \DB::transaction(function () use ($groupId, $permissionIds) { |
|
29 | + $group = $this->find($groupId); |
|
30 | + $group->permissions()->detach(); |
|
31 | + $group->permissions()->attach($permissionIds); |
|
32 | + }); |
|
33 | 33 | |
34 | - return $this->find($groupId); |
|
35 | - } |
|
34 | + return $this->find($groupId); |
|
35 | + } |
|
36 | 36 | } |
@@ -6,391 +6,391 @@ |
||
6 | 6 | |
7 | 7 | class UserRepository extends BaseRepository |
8 | 8 | { |
9 | - /** |
|
10 | - * Init new object. |
|
11 | - * |
|
12 | - * @param AclUser $model |
|
13 | - * @return void |
|
14 | - */ |
|
15 | - public function __construct(AclUser $model) |
|
16 | - { |
|
17 | - parent::__construct($model); |
|
18 | - } |
|
19 | - |
|
20 | - /** |
|
21 | - * Return the logged in user account. |
|
22 | - * |
|
23 | - * @param array $relations |
|
24 | - * @return boolean |
|
25 | - */ |
|
26 | - public function account($relations = []) |
|
27 | - { |
|
28 | - $permissions = []; |
|
29 | - $user = $this->find(\Auth::id(), $relations); |
|
30 | - foreach ($user->groups()->get() as $group) { |
|
31 | - $group->permissions->each(function ($permission) use (&$permissions) { |
|
32 | - $permissions[$permission->model][$permission->id] = $permission->name; |
|
33 | - }); |
|
34 | - } |
|
35 | - $user->permissions = $permissions; |
|
36 | - |
|
37 | - return $user; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Check if the logged in user or the given user |
|
42 | - * has the given permissions on the given model. |
|
43 | - * |
|
44 | - * @param string $nameOfPermission |
|
45 | - * @param string $model |
|
46 | - * @param mixed $user |
|
47 | - * @return boolean |
|
48 | - */ |
|
49 | - public function can($nameOfPermission, $model, $user = false) |
|
50 | - { |
|
51 | - $user = $user ?: $this->find(\Auth::id(), ['groups.permissions']); |
|
52 | - $permissions = []; |
|
53 | - |
|
54 | - $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model) { |
|
55 | - $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
56 | - }); |
|
9 | + /** |
|
10 | + * Init new object. |
|
11 | + * |
|
12 | + * @param AclUser $model |
|
13 | + * @return void |
|
14 | + */ |
|
15 | + public function __construct(AclUser $model) |
|
16 | + { |
|
17 | + parent::__construct($model); |
|
18 | + } |
|
19 | + |
|
20 | + /** |
|
21 | + * Return the logged in user account. |
|
22 | + * |
|
23 | + * @param array $relations |
|
24 | + * @return boolean |
|
25 | + */ |
|
26 | + public function account($relations = []) |
|
27 | + { |
|
28 | + $permissions = []; |
|
29 | + $user = $this->find(\Auth::id(), $relations); |
|
30 | + foreach ($user->groups()->get() as $group) { |
|
31 | + $group->permissions->each(function ($permission) use (&$permissions) { |
|
32 | + $permissions[$permission->model][$permission->id] = $permission->name; |
|
33 | + }); |
|
34 | + } |
|
35 | + $user->permissions = $permissions; |
|
36 | + |
|
37 | + return $user; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Check if the logged in user or the given user |
|
42 | + * has the given permissions on the given model. |
|
43 | + * |
|
44 | + * @param string $nameOfPermission |
|
45 | + * @param string $model |
|
46 | + * @param mixed $user |
|
47 | + * @return boolean |
|
48 | + */ |
|
49 | + public function can($nameOfPermission, $model, $user = false) |
|
50 | + { |
|
51 | + $user = $user ?: $this->find(\Auth::id(), ['groups.permissions']); |
|
52 | + $permissions = []; |
|
53 | + |
|
54 | + $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model) { |
|
55 | + $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
|
56 | + }); |
|
57 | 57 | |
58 | - return in_array($nameOfPermission, $permissions); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Check if the logged in user has the given group. |
|
63 | - * |
|
64 | - * @param string[] $groups |
|
65 | - * @param mixed $user |
|
66 | - * @return boolean |
|
67 | - */ |
|
68 | - public function hasGroup($groups, $user = false) |
|
69 | - { |
|
70 | - $user = $user ?: $this->find(\Auth::id()); |
|
71 | - return $user->groups->whereIn('name', $groups)->count() ? true : false; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Assign the given group ids to the given user. |
|
76 | - * |
|
77 | - * @param integer $userId |
|
78 | - * @param array $groupIds |
|
79 | - * @return object |
|
80 | - */ |
|
81 | - public function assignGroups($userId, $groupIds) |
|
82 | - { |
|
83 | - \DB::transaction(function () use ($userId, $groupIds) { |
|
84 | - $user = $this->find($userId); |
|
85 | - $user->groups()->detach(); |
|
86 | - $user->groups()->attach($groupIds); |
|
87 | - }); |
|
88 | - |
|
89 | - return $this->find($userId); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Handle a login request to the application. |
|
95 | - * |
|
96 | - * @param array $credentials |
|
97 | - * @param boolean $adminLogin |
|
98 | - * @return object |
|
99 | - */ |
|
100 | - public function login($credentials, $adminLogin = false) |
|
101 | - { |
|
102 | - if (! $user = $this->first(['email' => $credentials['email']])) { |
|
103 | - \ErrorHandler::loginFailed(); |
|
104 | - } elseif ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) { |
|
105 | - \ErrorHandler::loginFailed(); |
|
106 | - } elseif (! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) { |
|
107 | - \ErrorHandler::loginFailed(); |
|
108 | - } elseif ($user->blocked) { |
|
109 | - \ErrorHandler::userIsBlocked(); |
|
110 | - } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
111 | - \ErrorHandler::emailNotConfirmed(); |
|
112 | - } |
|
113 | - |
|
114 | - return $user; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Handle a social login request of the none admin to the application. |
|
119 | - * |
|
120 | - * @param string $authCode |
|
121 | - * @param string $accessToken |
|
122 | - * @param string $type |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public function loginSocial($authCode, $accessToken, $type) |
|
126 | - { |
|
127 | - $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
|
128 | - $user = \Socialite::driver($type)->userFromToken($access_token); |
|
129 | - |
|
130 | - if (! $user->email) { |
|
131 | - \ErrorHandler::noSocialEmail(); |
|
132 | - } |
|
133 | - |
|
134 | - if ( ! $this->model->where('email', $user->email)->first()) { |
|
135 | - $this->register(['email' => $user->email, 'password' => ''], true); |
|
136 | - } |
|
137 | - |
|
138 | - $loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy'); |
|
139 | - return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0); |
|
140 | - } |
|
58 | + return in_array($nameOfPermission, $permissions); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Check if the logged in user has the given group. |
|
63 | + * |
|
64 | + * @param string[] $groups |
|
65 | + * @param mixed $user |
|
66 | + * @return boolean |
|
67 | + */ |
|
68 | + public function hasGroup($groups, $user = false) |
|
69 | + { |
|
70 | + $user = $user ?: $this->find(\Auth::id()); |
|
71 | + return $user->groups->whereIn('name', $groups)->count() ? true : false; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Assign the given group ids to the given user. |
|
76 | + * |
|
77 | + * @param integer $userId |
|
78 | + * @param array $groupIds |
|
79 | + * @return object |
|
80 | + */ |
|
81 | + public function assignGroups($userId, $groupIds) |
|
82 | + { |
|
83 | + \DB::transaction(function () use ($userId, $groupIds) { |
|
84 | + $user = $this->find($userId); |
|
85 | + $user->groups()->detach(); |
|
86 | + $user->groups()->attach($groupIds); |
|
87 | + }); |
|
88 | + |
|
89 | + return $this->find($userId); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Handle a login request to the application. |
|
95 | + * |
|
96 | + * @param array $credentials |
|
97 | + * @param boolean $adminLogin |
|
98 | + * @return object |
|
99 | + */ |
|
100 | + public function login($credentials, $adminLogin = false) |
|
101 | + { |
|
102 | + if (! $user = $this->first(['email' => $credentials['email']])) { |
|
103 | + \ErrorHandler::loginFailed(); |
|
104 | + } elseif ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) { |
|
105 | + \ErrorHandler::loginFailed(); |
|
106 | + } elseif (! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) { |
|
107 | + \ErrorHandler::loginFailed(); |
|
108 | + } elseif ($user->blocked) { |
|
109 | + \ErrorHandler::userIsBlocked(); |
|
110 | + } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
111 | + \ErrorHandler::emailNotConfirmed(); |
|
112 | + } |
|
113 | + |
|
114 | + return $user; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Handle a social login request of the none admin to the application. |
|
119 | + * |
|
120 | + * @param string $authCode |
|
121 | + * @param string $accessToken |
|
122 | + * @param string $type |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public function loginSocial($authCode, $accessToken, $type) |
|
126 | + { |
|
127 | + $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
|
128 | + $user = \Socialite::driver($type)->userFromToken($access_token); |
|
129 | + |
|
130 | + if (! $user->email) { |
|
131 | + \ErrorHandler::noSocialEmail(); |
|
132 | + } |
|
133 | + |
|
134 | + if ( ! $this->model->where('email', $user->email)->first()) { |
|
135 | + $this->register(['email' => $user->email, 'password' => ''], true); |
|
136 | + } |
|
137 | + |
|
138 | + $loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy'); |
|
139 | + return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Handle a registration request. |
|
144 | - * |
|
145 | - * @param array $credentials |
|
146 | - * @param boolean $skipConfirmEmail |
|
147 | - * @return array |
|
148 | - */ |
|
149 | - public function register($credentials, $skipConfirmEmail = false) |
|
150 | - { |
|
151 | - $user = $this->save($credentials); |
|
152 | - |
|
153 | - if ($skipConfirmEmail) { |
|
154 | - $user->confirmed = 1; |
|
155 | - $user->save(); |
|
156 | - } elseif (! config('skeleton.disable_confirm_email')) { |
|
157 | - $this->sendConfirmationEmail($user->email); |
|
158 | - } |
|
159 | - |
|
160 | - return $user; |
|
161 | - } |
|
142 | + /** |
|
143 | + * Handle a registration request. |
|
144 | + * |
|
145 | + * @param array $credentials |
|
146 | + * @param boolean $skipConfirmEmail |
|
147 | + * @return array |
|
148 | + */ |
|
149 | + public function register($credentials, $skipConfirmEmail = false) |
|
150 | + { |
|
151 | + $user = $this->save($credentials); |
|
152 | + |
|
153 | + if ($skipConfirmEmail) { |
|
154 | + $user->confirmed = 1; |
|
155 | + $user->save(); |
|
156 | + } elseif (! config('skeleton.disable_confirm_email')) { |
|
157 | + $this->sendConfirmationEmail($user->email); |
|
158 | + } |
|
159 | + |
|
160 | + return $user; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Block the user. |
|
165 | - * |
|
166 | - * @param integer $userId |
|
167 | - * @return object |
|
168 | - */ |
|
169 | - public function block($userId) |
|
170 | - { |
|
171 | - if (! $user = $this->find($userId)) { |
|
172 | - \ErrorHandler::notFound('user'); |
|
173 | - } |
|
174 | - if (! $this->hasGroup(['Admin'])) { |
|
175 | - \ErrorHandler::noPermissions(); |
|
176 | - } elseif (\Auth::id() == $userId) { |
|
177 | - \ErrorHandler::noPermissions(); |
|
178 | - } elseif ($user->groups->pluck('name')->search('Admin', true) !== false) { |
|
179 | - \ErrorHandler::noPermissions(); |
|
180 | - } |
|
181 | - |
|
182 | - $user->blocked = 1; |
|
183 | - $user->save(); |
|
163 | + /** |
|
164 | + * Block the user. |
|
165 | + * |
|
166 | + * @param integer $userId |
|
167 | + * @return object |
|
168 | + */ |
|
169 | + public function block($userId) |
|
170 | + { |
|
171 | + if (! $user = $this->find($userId)) { |
|
172 | + \ErrorHandler::notFound('user'); |
|
173 | + } |
|
174 | + if (! $this->hasGroup(['Admin'])) { |
|
175 | + \ErrorHandler::noPermissions(); |
|
176 | + } elseif (\Auth::id() == $userId) { |
|
177 | + \ErrorHandler::noPermissions(); |
|
178 | + } elseif ($user->groups->pluck('name')->search('Admin', true) !== false) { |
|
179 | + \ErrorHandler::noPermissions(); |
|
180 | + } |
|
181 | + |
|
182 | + $user->blocked = 1; |
|
183 | + $user->save(); |
|
184 | 184 | |
185 | - return $user; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Unblock the user. |
|
190 | - * |
|
191 | - * @param integer $userId |
|
192 | - * @return object |
|
193 | - */ |
|
194 | - public function unblock($userId) |
|
195 | - { |
|
196 | - if (! $this->hasGroup(['Admin'])) { |
|
197 | - \ErrorHandler::noPermissions(); |
|
198 | - } |
|
199 | - |
|
200 | - $user = $this->find($userId); |
|
201 | - $user->blocked = 0; |
|
202 | - $user->save(); |
|
203 | - |
|
204 | - return $user; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Send a reset link to the given user. |
|
209 | - * |
|
210 | - * @param string $email |
|
211 | - * @return void |
|
212 | - */ |
|
213 | - public function sendReset($email) |
|
214 | - { |
|
215 | - if (! $user = $this->model->where('email', $email)->first()) { |
|
216 | - \ErrorHandler::notFound('email'); |
|
217 | - } |
|
218 | - |
|
219 | - $token = \Password::getRepository()->create($user); |
|
220 | - \Core::notifications()->notify($user, 'ResetPassword', $token); |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Reset the given user's password. |
|
225 | - * |
|
226 | - * @param array $credentials |
|
227 | - * @return string|null |
|
228 | - */ |
|
229 | - public function resetPassword($credentials) |
|
230 | - { |
|
231 | - $response = \Password::reset($credentials, function ($user, $password) { |
|
232 | - $user->password = $password; |
|
233 | - $user->save(); |
|
234 | - }); |
|
235 | - |
|
236 | - switch ($response) { |
|
237 | - case \Password::PASSWORD_RESET: |
|
238 | - return 'success'; |
|
239 | - |
|
240 | - case \Password::INVALID_TOKEN: |
|
241 | - \ErrorHandler::invalidResetToken('token'); |
|
242 | - //no break |
|
243 | - |
|
244 | - case \Password::INVALID_PASSWORD: |
|
245 | - \ErrorHandler::invalidResetPassword('email'); |
|
246 | - //no break |
|
247 | - |
|
248 | - case \Password::INVALID_USER: |
|
249 | - \ErrorHandler::notFound('user'); |
|
250 | - //no break |
|
251 | - |
|
252 | - default: |
|
253 | - \ErrorHandler::generalError(); |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Change the logged in user password. |
|
259 | - * |
|
260 | - * @param array $credentials |
|
261 | - * @return void |
|
262 | - */ |
|
263 | - public function changePassword($credentials) |
|
264 | - { |
|
265 | - $user = \Auth::user(); |
|
266 | - if (! \Hash::check($credentials['old_password'], $user->password)) { |
|
267 | - \ErrorHandler::invalidOldPassword(); |
|
268 | - } |
|
269 | - |
|
270 | - $user->password = $credentials['password']; |
|
271 | - $user->save(); |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Confirm email using the confirmation code. |
|
276 | - * |
|
277 | - * @param string $confirmationCode |
|
278 | - * @return void |
|
279 | - */ |
|
280 | - public function confirmEmail($confirmationCode) |
|
281 | - { |
|
282 | - if (! $user = $this->first(['confirmation_code' => $confirmationCode])) { |
|
283 | - \ErrorHandler::invalidConfirmationCode(); |
|
284 | - } |
|
285 | - |
|
286 | - $user->confirmed = 1; |
|
287 | - $user->confirmation_code = null; |
|
288 | - $user->save(); |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Send the confirmation mail. |
|
293 | - * |
|
294 | - * @param string $email |
|
295 | - * @return void |
|
296 | - */ |
|
297 | - public function sendConfirmationEmail($email) |
|
298 | - { |
|
299 | - $user = $this->first(['email' => $email]); |
|
300 | - if ($user->confirmed) { |
|
301 | - \ErrorHandler::emailAlreadyConfirmed(); |
|
302 | - } |
|
303 | - |
|
304 | - $user->confirmed = 0; |
|
305 | - $user->confirmation_code = sha1(microtime()); |
|
306 | - $user->save(); |
|
307 | - \Core::notifications()->notify($user, 'ConfirmEmail'); |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Paginate all users in the given group based on the given conditions. |
|
312 | - * |
|
313 | - * @param string $groupName |
|
314 | - * @param array $relations |
|
315 | - * @param integer $perPage |
|
316 | - * @param string $sortBy |
|
317 | - * @param boolean $desc |
|
318 | - * @return \Illuminate\Http\Response |
|
319 | - */ |
|
320 | - public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
321 | - { |
|
322 | - unset($conditions['page']); |
|
323 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
324 | - $sort = $desc ? 'desc' : 'asc'; |
|
325 | - $model = $this->model->with($relations); |
|
326 | - |
|
327 | - $model->whereHas('groups', function ($q) use ($groupName) { |
|
328 | - $q->where('name', $groupName); |
|
329 | - }); |
|
185 | + return $user; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Unblock the user. |
|
190 | + * |
|
191 | + * @param integer $userId |
|
192 | + * @return object |
|
193 | + */ |
|
194 | + public function unblock($userId) |
|
195 | + { |
|
196 | + if (! $this->hasGroup(['Admin'])) { |
|
197 | + \ErrorHandler::noPermissions(); |
|
198 | + } |
|
199 | + |
|
200 | + $user = $this->find($userId); |
|
201 | + $user->blocked = 0; |
|
202 | + $user->save(); |
|
203 | + |
|
204 | + return $user; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Send a reset link to the given user. |
|
209 | + * |
|
210 | + * @param string $email |
|
211 | + * @return void |
|
212 | + */ |
|
213 | + public function sendReset($email) |
|
214 | + { |
|
215 | + if (! $user = $this->model->where('email', $email)->first()) { |
|
216 | + \ErrorHandler::notFound('email'); |
|
217 | + } |
|
218 | + |
|
219 | + $token = \Password::getRepository()->create($user); |
|
220 | + \Core::notifications()->notify($user, 'ResetPassword', $token); |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Reset the given user's password. |
|
225 | + * |
|
226 | + * @param array $credentials |
|
227 | + * @return string|null |
|
228 | + */ |
|
229 | + public function resetPassword($credentials) |
|
230 | + { |
|
231 | + $response = \Password::reset($credentials, function ($user, $password) { |
|
232 | + $user->password = $password; |
|
233 | + $user->save(); |
|
234 | + }); |
|
235 | + |
|
236 | + switch ($response) { |
|
237 | + case \Password::PASSWORD_RESET: |
|
238 | + return 'success'; |
|
239 | + |
|
240 | + case \Password::INVALID_TOKEN: |
|
241 | + \ErrorHandler::invalidResetToken('token'); |
|
242 | + //no break |
|
243 | + |
|
244 | + case \Password::INVALID_PASSWORD: |
|
245 | + \ErrorHandler::invalidResetPassword('email'); |
|
246 | + //no break |
|
247 | + |
|
248 | + case \Password::INVALID_USER: |
|
249 | + \ErrorHandler::notFound('user'); |
|
250 | + //no break |
|
251 | + |
|
252 | + default: |
|
253 | + \ErrorHandler::generalError(); |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Change the logged in user password. |
|
259 | + * |
|
260 | + * @param array $credentials |
|
261 | + * @return void |
|
262 | + */ |
|
263 | + public function changePassword($credentials) |
|
264 | + { |
|
265 | + $user = \Auth::user(); |
|
266 | + if (! \Hash::check($credentials['old_password'], $user->password)) { |
|
267 | + \ErrorHandler::invalidOldPassword(); |
|
268 | + } |
|
269 | + |
|
270 | + $user->password = $credentials['password']; |
|
271 | + $user->save(); |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Confirm email using the confirmation code. |
|
276 | + * |
|
277 | + * @param string $confirmationCode |
|
278 | + * @return void |
|
279 | + */ |
|
280 | + public function confirmEmail($confirmationCode) |
|
281 | + { |
|
282 | + if (! $user = $this->first(['confirmation_code' => $confirmationCode])) { |
|
283 | + \ErrorHandler::invalidConfirmationCode(); |
|
284 | + } |
|
285 | + |
|
286 | + $user->confirmed = 1; |
|
287 | + $user->confirmation_code = null; |
|
288 | + $user->save(); |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Send the confirmation mail. |
|
293 | + * |
|
294 | + * @param string $email |
|
295 | + * @return void |
|
296 | + */ |
|
297 | + public function sendConfirmationEmail($email) |
|
298 | + { |
|
299 | + $user = $this->first(['email' => $email]); |
|
300 | + if ($user->confirmed) { |
|
301 | + \ErrorHandler::emailAlreadyConfirmed(); |
|
302 | + } |
|
303 | + |
|
304 | + $user->confirmed = 0; |
|
305 | + $user->confirmation_code = sha1(microtime()); |
|
306 | + $user->save(); |
|
307 | + \Core::notifications()->notify($user, 'ConfirmEmail'); |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Paginate all users in the given group based on the given conditions. |
|
312 | + * |
|
313 | + * @param string $groupName |
|
314 | + * @param array $relations |
|
315 | + * @param integer $perPage |
|
316 | + * @param string $sortBy |
|
317 | + * @param boolean $desc |
|
318 | + * @return \Illuminate\Http\Response |
|
319 | + */ |
|
320 | + public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc) |
|
321 | + { |
|
322 | + unset($conditions['page']); |
|
323 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
324 | + $sort = $desc ? 'desc' : 'asc'; |
|
325 | + $model = $this->model->with($relations); |
|
326 | + |
|
327 | + $model->whereHas('groups', function ($q) use ($groupName) { |
|
328 | + $q->where('name', $groupName); |
|
329 | + }); |
|
330 | 330 | |
331 | 331 | |
332 | - if (count($conditions['conditionValues'])) { |
|
333 | - $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
334 | - } |
|
335 | - |
|
336 | - if ($perPage) { |
|
337 | - return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
338 | - } |
|
339 | - |
|
340 | - return $model->orderBy($sortBy, $sort)->get(); |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * Save the given data to the logged in user. |
|
345 | - * |
|
346 | - * @param array $data |
|
347 | - * @return void |
|
348 | - */ |
|
349 | - public function saveProfile($data) |
|
350 | - { |
|
351 | - if (Arr::has($data, 'profile_picture')) { |
|
352 | - $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures'); |
|
353 | - } |
|
332 | + if (count($conditions['conditionValues'])) { |
|
333 | + $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
334 | + } |
|
335 | + |
|
336 | + if ($perPage) { |
|
337 | + return $model->orderBy($sortBy, $sort)->paginate($perPage); |
|
338 | + } |
|
339 | + |
|
340 | + return $model->orderBy($sortBy, $sort)->get(); |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * Save the given data to the logged in user. |
|
345 | + * |
|
346 | + * @param array $data |
|
347 | + * @return void |
|
348 | + */ |
|
349 | + public function saveProfile($data) |
|
350 | + { |
|
351 | + if (Arr::has($data, 'profile_picture')) { |
|
352 | + $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures'); |
|
353 | + } |
|
354 | 354 | |
355 | - $data['id'] = \Auth::id(); |
|
356 | - return $this->save($data); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Ensure access token hasn't expired or revoked. |
|
361 | - * |
|
362 | - * @param string $accessToken |
|
363 | - * @return boolean |
|
364 | - */ |
|
365 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
366 | - { |
|
367 | - $accessTokenId = json_decode($accessToken, true)['id']; |
|
368 | - $accessToken = \DB::table('oauth_access_tokens') |
|
369 | - ->where('id', $accessTokenId) |
|
370 | - ->first(); |
|
355 | + $data['id'] = \Auth::id(); |
|
356 | + return $this->save($data); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Ensure access token hasn't expired or revoked. |
|
361 | + * |
|
362 | + * @param string $accessToken |
|
363 | + * @return boolean |
|
364 | + */ |
|
365 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
366 | + { |
|
367 | + $accessTokenId = json_decode($accessToken, true)['id']; |
|
368 | + $accessToken = \DB::table('oauth_access_tokens') |
|
369 | + ->where('id', $accessTokenId) |
|
370 | + ->first(); |
|
371 | 371 | |
372 | - if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) { |
|
373 | - return true; |
|
374 | - } |
|
375 | - |
|
376 | - return false; |
|
377 | - } |
|
378 | - |
|
379 | - /** |
|
380 | - * Revoke the given access token and all |
|
381 | - * associated refresh tokens. |
|
382 | - * |
|
383 | - * @param oject $accessToken |
|
384 | - * @return void |
|
385 | - */ |
|
386 | - public function revokeAccessToken($accessToken) |
|
387 | - { |
|
388 | - \DB::table('oauth_refresh_tokens') |
|
389 | - ->where('access_token_id', $accessToken->id) |
|
390 | - ->update([ |
|
391 | - 'revoked' => true |
|
392 | - ]); |
|
393 | - |
|
394 | - $accessToken->revoke(); |
|
395 | - } |
|
372 | + if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) { |
|
373 | + return true; |
|
374 | + } |
|
375 | + |
|
376 | + return false; |
|
377 | + } |
|
378 | + |
|
379 | + /** |
|
380 | + * Revoke the given access token and all |
|
381 | + * associated refresh tokens. |
|
382 | + * |
|
383 | + * @param oject $accessToken |
|
384 | + * @return void |
|
385 | + */ |
|
386 | + public function revokeAccessToken($accessToken) |
|
387 | + { |
|
388 | + \DB::table('oauth_refresh_tokens') |
|
389 | + ->where('access_token_id', $accessToken->id) |
|
390 | + ->update([ |
|
391 | + 'revoked' => true |
|
392 | + ]); |
|
393 | + |
|
394 | + $accessToken->revoke(); |
|
395 | + } |
|
396 | 396 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $permissions = []; |
29 | 29 | $user = $this->find(\Auth::id(), $relations); |
30 | 30 | foreach ($user->groups()->get() as $group) { |
31 | - $group->permissions->each(function ($permission) use (&$permissions) { |
|
31 | + $group->permissions->each(function($permission) use (&$permissions) { |
|
32 | 32 | $permissions[$permission->model][$permission->id] = $permission->name; |
33 | 33 | }); |
34 | 34 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $user = $user ?: $this->find(\Auth::id(), ['groups.permissions']); |
52 | 52 | $permissions = []; |
53 | 53 | |
54 | - $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model) { |
|
54 | + $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model) { |
|
55 | 55 | $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); |
56 | 56 | }); |
57 | 57 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function assignGroups($userId, $groupIds) |
82 | 82 | { |
83 | - \DB::transaction(function () use ($userId, $groupIds) { |
|
83 | + \DB::transaction(function() use ($userId, $groupIds) { |
|
84 | 84 | $user = $this->find($userId); |
85 | 85 | $user->groups()->detach(); |
86 | 86 | $user->groups()->attach($groupIds); |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function login($credentials, $adminLogin = false) |
101 | 101 | { |
102 | - if (! $user = $this->first(['email' => $credentials['email']])) { |
|
102 | + if ( ! $user = $this->first(['email' => $credentials['email']])) { |
|
103 | 103 | \ErrorHandler::loginFailed(); |
104 | 104 | } elseif ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) { |
105 | 105 | \ErrorHandler::loginFailed(); |
106 | - } elseif (! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) { |
|
106 | + } elseif ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) { |
|
107 | 107 | \ErrorHandler::loginFailed(); |
108 | 108 | } elseif ($user->blocked) { |
109 | 109 | \ErrorHandler::userIsBlocked(); |
110 | - } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
110 | + } elseif ( ! config('skeleton.disable_confirm_email') && ! $user->confirmed) { |
|
111 | 111 | \ErrorHandler::emailNotConfirmed(); |
112 | 112 | } |
113 | 113 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken; |
128 | 128 | $user = \Socialite::driver($type)->userFromToken($access_token); |
129 | 129 | |
130 | - if (! $user->email) { |
|
130 | + if ( ! $user->email) { |
|
131 | 131 | \ErrorHandler::noSocialEmail(); |
132 | 132 | } |
133 | 133 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | if ($skipConfirmEmail) { |
154 | 154 | $user->confirmed = 1; |
155 | 155 | $user->save(); |
156 | - } elseif (! config('skeleton.disable_confirm_email')) { |
|
156 | + } elseif ( ! config('skeleton.disable_confirm_email')) { |
|
157 | 157 | $this->sendConfirmationEmail($user->email); |
158 | 158 | } |
159 | 159 | |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function block($userId) |
170 | 170 | { |
171 | - if (! $user = $this->find($userId)) { |
|
171 | + if ( ! $user = $this->find($userId)) { |
|
172 | 172 | \ErrorHandler::notFound('user'); |
173 | 173 | } |
174 | - if (! $this->hasGroup(['Admin'])) { |
|
174 | + if ( ! $this->hasGroup(['Admin'])) { |
|
175 | 175 | \ErrorHandler::noPermissions(); |
176 | 176 | } elseif (\Auth::id() == $userId) { |
177 | 177 | \ErrorHandler::noPermissions(); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function unblock($userId) |
195 | 195 | { |
196 | - if (! $this->hasGroup(['Admin'])) { |
|
196 | + if ( ! $this->hasGroup(['Admin'])) { |
|
197 | 197 | \ErrorHandler::noPermissions(); |
198 | 198 | } |
199 | 199 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | */ |
213 | 213 | public function sendReset($email) |
214 | 214 | { |
215 | - if (! $user = $this->model->where('email', $email)->first()) { |
|
215 | + if ( ! $user = $this->model->where('email', $email)->first()) { |
|
216 | 216 | \ErrorHandler::notFound('email'); |
217 | 217 | } |
218 | 218 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function resetPassword($credentials) |
230 | 230 | { |
231 | - $response = \Password::reset($credentials, function ($user, $password) { |
|
231 | + $response = \Password::reset($credentials, function($user, $password) { |
|
232 | 232 | $user->password = $password; |
233 | 233 | $user->save(); |
234 | 234 | }); |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | public function changePassword($credentials) |
264 | 264 | { |
265 | 265 | $user = \Auth::user(); |
266 | - if (! \Hash::check($credentials['old_password'], $user->password)) { |
|
266 | + if ( ! \Hash::check($credentials['old_password'], $user->password)) { |
|
267 | 267 | \ErrorHandler::invalidOldPassword(); |
268 | 268 | } |
269 | 269 | |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | */ |
280 | 280 | public function confirmEmail($confirmationCode) |
281 | 281 | { |
282 | - if (! $user = $this->first(['confirmation_code' => $confirmationCode])) { |
|
282 | + if ( ! $user = $this->first(['confirmation_code' => $confirmationCode])) { |
|
283 | 283 | \ErrorHandler::invalidConfirmationCode(); |
284 | 284 | } |
285 | 285 | |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | $sort = $desc ? 'desc' : 'asc'; |
325 | 325 | $model = $this->model->with($relations); |
326 | 326 | |
327 | - $model->whereHas('groups', function ($q) use ($groupName) { |
|
327 | + $model->whereHas('groups', function($q) use ($groupName) { |
|
328 | 328 | $q->where('name', $groupName); |
329 | 329 | }); |
330 | 330 |
@@ -5,65 +5,65 @@ |
||
5 | 5 | |
6 | 6 | class ReportRepository extends BaseRepository |
7 | 7 | { |
8 | - /** |
|
9 | - * Init new object. |
|
10 | - * |
|
11 | - * @param Report $model |
|
12 | - * @return void |
|
13 | - */ |
|
14 | - public function __construct(Report $model) |
|
15 | - { |
|
16 | - parent::__construct($model); |
|
17 | - } |
|
8 | + /** |
|
9 | + * Init new object. |
|
10 | + * |
|
11 | + * @param Report $model |
|
12 | + * @return void |
|
13 | + */ |
|
14 | + public function __construct(Report $model) |
|
15 | + { |
|
16 | + parent::__construct($model); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Render the given report db view based on the given |
|
21 | - * condition. |
|
22 | - * |
|
23 | - * @param string $reportName |
|
24 | - * @param array $conditions |
|
25 | - * @param integer $perPage |
|
26 | - * @param array $relations |
|
27 | - * @param boolean $skipPermission |
|
28 | - * @return object |
|
29 | - */ |
|
30 | - public function getReport($reportName, $conditions = [], $perPage = 0, $relations = [], $skipPermission = false) |
|
31 | - { |
|
32 | - /** |
|
33 | - * Fetch the report from db. |
|
34 | - */ |
|
35 | - $reportConditions = $this->constructConditions(['report_name' => $reportName], $this->model); |
|
36 | - $report = $this->model->with($relations) |
|
37 | - ->whereRaw( |
|
38 | - $reportConditions['conditionString'], |
|
39 | - $reportConditions['conditionValues'] |
|
40 | - )->first(); |
|
19 | + /** |
|
20 | + * Render the given report db view based on the given |
|
21 | + * condition. |
|
22 | + * |
|
23 | + * @param string $reportName |
|
24 | + * @param array $conditions |
|
25 | + * @param integer $perPage |
|
26 | + * @param array $relations |
|
27 | + * @param boolean $skipPermission |
|
28 | + * @return object |
|
29 | + */ |
|
30 | + public function getReport($reportName, $conditions = [], $perPage = 0, $relations = [], $skipPermission = false) |
|
31 | + { |
|
32 | + /** |
|
33 | + * Fetch the report from db. |
|
34 | + */ |
|
35 | + $reportConditions = $this->constructConditions(['report_name' => $reportName], $this->model); |
|
36 | + $report = $this->model->with($relations) |
|
37 | + ->whereRaw( |
|
38 | + $reportConditions['conditionString'], |
|
39 | + $reportConditions['conditionValues'] |
|
40 | + )->first(); |
|
41 | 41 | |
42 | - /** |
|
43 | - * Check report existance and permission. |
|
44 | - */ |
|
45 | - if (! $report) { |
|
46 | - \ErrorHandler::notFound('report'); |
|
47 | - } elseif (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports')) { |
|
48 | - \ErrorHandler::noPermissions(); |
|
49 | - } |
|
42 | + /** |
|
43 | + * Check report existance and permission. |
|
44 | + */ |
|
45 | + if (! $report) { |
|
46 | + \ErrorHandler::notFound('report'); |
|
47 | + } elseif (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports')) { |
|
48 | + \ErrorHandler::noPermissions(); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Fetch data from the report based on the given conditions. |
|
53 | - */ |
|
54 | - $report = \DB::table($report->view_name); |
|
55 | - unset($conditions['page']); |
|
56 | - if (count($conditions)) { |
|
57 | - $conditions = $this->constructConditions($conditions, $this->model); |
|
58 | - $report->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
59 | - } |
|
60 | - /** |
|
61 | - * Paginate or all data. |
|
62 | - */ |
|
63 | - if ($perPage) { |
|
64 | - return $report->paginate($perPage); |
|
65 | - } else { |
|
66 | - return $report->get(); |
|
67 | - } |
|
68 | - } |
|
51 | + /** |
|
52 | + * Fetch data from the report based on the given conditions. |
|
53 | + */ |
|
54 | + $report = \DB::table($report->view_name); |
|
55 | + unset($conditions['page']); |
|
56 | + if (count($conditions)) { |
|
57 | + $conditions = $this->constructConditions($conditions, $this->model); |
|
58 | + $report->whereRaw($conditions['conditionString'], $conditions['conditionValues']); |
|
59 | + } |
|
60 | + /** |
|
61 | + * Paginate or all data. |
|
62 | + */ |
|
63 | + if ($perPage) { |
|
64 | + return $report->paginate($perPage); |
|
65 | + } else { |
|
66 | + return $report->get(); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | } |