Completed
Push — master ( 7fd3dc...2f5e5e )
by Sherif
10:09
created
src/Modules/V1/Acl/Repositories/UserRepository.php 4 patches
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -122,16 +122,13 @@  discard block
 block discarded – undo
122 122
         if ( ! $user = $this->first(['email' => $credentials['email']])) 
123 123
         {
124 124
             \ErrorHandler::loginFailed();
125
-        }
126
-        else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
125
+        } else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
127 126
         {
128 127
             \ErrorHandler::loginFailed();
129
-        }
130
-        else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
128
+        } else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
131 129
         {
132 130
             \ErrorHandler::loginFailed();
133
-        }
134
-        else if ($user->blocked)
131
+        } else if ($user->blocked)
135 132
         {
136 133
             \ErrorHandler::userIsBlocked();
137 134
         }
@@ -159,8 +156,7 @@  discard block
 block discarded – undo
159 156
         {
160 157
             $data = ['email' => $user->email, 'password' => ''];
161 158
             return $this->register($data);
162
-        }
163
-        else
159
+        } else
164 160
         {
165 161
             if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
166 162
             {
@@ -198,12 +194,10 @@  discard block
 block discarded – undo
198 194
         if ( ! $this->hasGroup('Admin'))
199 195
         {
200 196
             \ErrorHandler::noPermissions();
201
-        }
202
-        else if (\Auth::id() == $user_id)
197
+        } else if (\Auth::id() == $user_id)
203 198
         {
204 199
             \ErrorHandler::noPermissions();
205
-        }
206
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
200
+        } else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
207 201
         {
208 202
             \ErrorHandler::noPermissions();
209 203
         }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
         $user        = \Core::users()->find(\Auth::id(), $relations);
50 50
         foreach ($user->groups()->get() as $group)
51 51
         {
52
-            $group->permissions->each(function ($permission) use (&$permissions){
52
+            $group->permissions->each(function($permission) use (&$permissions){
53 53
                 $permissions[$permission->model][$permission->id] = $permission->name;
54 54
             });
55 55
         }
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         $user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
73 73
         $permissions = [];
74 74
 
75
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
75
+        $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model){
76 76
             $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
77 77
         });
78 78
         
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      */
103 103
     public function assignGroups($user_id, $group_ids)
104 104
     {
105
-        \DB::transaction(function () use ($user_id, $group_ids) {
105
+        \DB::transaction(function() use ($user_id, $group_ids) {
106 106
             $user = $this->find($user_id);
107 107
             $user->groups()->detach();
108 108
             $user->groups()->attach($group_ids);
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
         $url   = $this->config['resetLink'];
252 252
         $token = \Password::getRepository()->create($user);
253 253
         
254
-        \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) {
254
+        \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function($m) use ($user) {
255 255
             $m->to($user->email, $user->name)->subject('Your Password Reset Link');
256 256
         });
257 257
     }
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
      */
265 265
     public function resetPassword($credentials)
266 266
     {
267
-        $response = \Password::reset($credentials, function ($user, $password) {
267
+        $response = \Password::reset($credentials, function($user, $password) {
268 268
             $user->password = $password;
269 269
             $user->save();
270 270
         });
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
      * Reset the given user's password.
240 240
      *
241 241
      * @param  array  $credentials
242
-     * @return array
242
+     * @return string|null
243 243
      */
244 244
     public function resetPassword($credentials)
245 245
     {
@@ -322,7 +322,6 @@  discard block
 block discarded – undo
322 322
     /**
323 323
      * Save the given data to the logged in user.
324 324
      *
325
-     * @param  array $credentials
326 325
      * @return void
327 326
      */
328 327
     public function saveProfile($data) 
Please login to merge, or discard this patch.
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -5,350 +5,350 @@
 block discarded – undo
5 5
 
6 6
 class UserRepository extends AbstractRepository
7 7
 {
8
-    /**
9
-     * Return the model full namespace.
10
-     * 
11
-     * @return string
12
-     */
13
-    protected function getModel()
14
-    {
15
-        return 'App\Modules\V1\Acl\AclUser';
16
-    }
17
-
18
-
19
-    /**
20
-     * Return the logged in user account.
21
-     *
22
-     * @param  array   $relations
23
-     * @return boolean
24
-     */
25
-    public function account($relations = [])
26
-    {
27
-        $permissions = [];
28
-        $user        = \Core::users()->find(\Auth::id(), $relations);
29
-        foreach ($user->groups()->get() as $group)
30
-        {
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  boolean $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
-        });
8
+	/**
9
+	 * Return the model full namespace.
10
+	 * 
11
+	 * @return string
12
+	 */
13
+	protected function getModel()
14
+	{
15
+		return 'App\Modules\V1\Acl\AclUser';
16
+	}
17
+
18
+
19
+	/**
20
+	 * Return the logged in user account.
21
+	 *
22
+	 * @param  array   $relations
23
+	 * @return boolean
24
+	 */
25
+	public function account($relations = [])
26
+	{
27
+		$permissions = [];
28
+		$user        = \Core::users()->find(\Auth::id(), $relations);
29
+		foreach ($user->groups()->get() as $group)
30
+		{
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  boolean $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  $groupName
65
-     * @param  integer $userId
66
-     * @return boolean
67
-     */
68
-    public function hasGroup($groupName, $userId = false)
69
-    {
70
-        $userId = $userId ?: \Auth::id();
71
-        $groups = $this->find($userId)->groups;
72
-        return $groups->pluck('name')->search($groupName, true) === false ? false : true;
73
-    }
74
-
75
-    /**
76
-     * Assign the given group ids to the given user.
77
-     * 
78
-     * @param  integer $user_id    
79
-     * @param  array   $group_ids
80
-     * @return object
81
-     */
82
-    public function assignGroups($user_id, $group_ids)
83
-    {
84
-        \DB::transaction(function () use ($user_id, $group_ids) {
85
-            $user = $this->find($user_id);
86
-            $user->groups()->detach();
87
-            $user->groups()->attach($group_ids);
88
-        });
89
-
90
-        return $this->find($user_id);
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
-        {
104
-            \ErrorHandler::loginFailed();
105
-        }
106
-        else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
107
-        {
108
-            \ErrorHandler::loginFailed();
109
-        }
110
-        else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
111
-        {
112
-            \ErrorHandler::loginFailed();
113
-        }
114
-        else if ($user->blocked)
115
-        {
116
-            \ErrorHandler::userIsBlocked();
117
-        }
118
-
119
-        return $user;
120
-    }
121
-
122
-    /**
123
-     * Handle a social login request of the none admin to the application.
124
-     * 
125
-     * @param  array   $credentials
126
-     * @return array
127
-     */
128
-    public function loginSocial($credentials)
129
-    {
130
-        $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
131
-        $user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
132
-
133
-        if ( ! $user->email)
134
-        {
135
-            \ErrorHandler::noSocialEmail();
136
-        }
137
-
138
-        if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
139
-        {
140
-            $data = ['email' => $user->email, 'password' => ''];
141
-            return $this->register($data);
142
-        }
143
-        else
144
-        {
145
-            if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
146
-            {
147
-                \ErrorHandler::userAlreadyRegistered();
148
-            }
149
-
150
-            $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy');
151
-            return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0);
152
-        }
153
-    }
58
+		return in_array($nameOfPermission, $permissions);
59
+	}
60
+
61
+	/**
62
+	 * Check if the logged in user has the given group.
63
+	 * 
64
+	 * @param  string  $groupName
65
+	 * @param  integer $userId
66
+	 * @return boolean
67
+	 */
68
+	public function hasGroup($groupName, $userId = false)
69
+	{
70
+		$userId = $userId ?: \Auth::id();
71
+		$groups = $this->find($userId)->groups;
72
+		return $groups->pluck('name')->search($groupName, true) === false ? false : true;
73
+	}
74
+
75
+	/**
76
+	 * Assign the given group ids to the given user.
77
+	 * 
78
+	 * @param  integer $user_id    
79
+	 * @param  array   $group_ids
80
+	 * @return object
81
+	 */
82
+	public function assignGroups($user_id, $group_ids)
83
+	{
84
+		\DB::transaction(function () use ($user_id, $group_ids) {
85
+			$user = $this->find($user_id);
86
+			$user->groups()->detach();
87
+			$user->groups()->attach($group_ids);
88
+		});
89
+
90
+		return $this->find($user_id);
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
+		{
104
+			\ErrorHandler::loginFailed();
105
+		}
106
+		else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
107
+		{
108
+			\ErrorHandler::loginFailed();
109
+		}
110
+		else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
111
+		{
112
+			\ErrorHandler::loginFailed();
113
+		}
114
+		else if ($user->blocked)
115
+		{
116
+			\ErrorHandler::userIsBlocked();
117
+		}
118
+
119
+		return $user;
120
+	}
121
+
122
+	/**
123
+	 * Handle a social login request of the none admin to the application.
124
+	 * 
125
+	 * @param  array   $credentials
126
+	 * @return array
127
+	 */
128
+	public function loginSocial($credentials)
129
+	{
130
+		$access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
131
+		$user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
132
+
133
+		if ( ! $user->email)
134
+		{
135
+			\ErrorHandler::noSocialEmail();
136
+		}
137
+
138
+		if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
139
+		{
140
+			$data = ['email' => $user->email, 'password' => ''];
141
+			return $this->register($data);
142
+		}
143
+		else
144
+		{
145
+			if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
146
+			{
147
+				\ErrorHandler::userAlreadyRegistered();
148
+			}
149
+
150
+			$loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy');
151
+			return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0);
152
+		}
153
+	}
154 154
     
155
-    /**
156
-     * Handle a registration request.
157
-     * 
158
-     * @param  array $credentials
159
-     * @return array
160
-     */
161
-    public function register($credentials)
162
-    {
163
-        $this->model->create($credentials);
164
-    }
165
-
166
-    /**
167
-     * Block the user.
168
-     *
169
-     * @param  integer $user_id
170
-     * @return object
171
-     */
172
-    public function block($user_id)
173
-    {
174
-        if ( ! $user = $this->find($user_id)) 
175
-        {
176
-            \ErrorHandler::notFound('user');
177
-        }
178
-        if ( ! $this->hasGroup('Admin'))
179
-        {
180
-            \ErrorHandler::noPermissions();
181
-        }
182
-        else if (\Auth::id() == $user_id)
183
-        {
184
-            \ErrorHandler::noPermissions();
185
-        }
186
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
187
-        {
188
-            \ErrorHandler::noPermissions();
189
-        }
190
-
191
-        $user->blocked = 1;
192
-        $user->save();
155
+	/**
156
+	 * Handle a registration request.
157
+	 * 
158
+	 * @param  array $credentials
159
+	 * @return array
160
+	 */
161
+	public function register($credentials)
162
+	{
163
+		$this->model->create($credentials);
164
+	}
165
+
166
+	/**
167
+	 * Block the user.
168
+	 *
169
+	 * @param  integer $user_id
170
+	 * @return object
171
+	 */
172
+	public function block($user_id)
173
+	{
174
+		if ( ! $user = $this->find($user_id)) 
175
+		{
176
+			\ErrorHandler::notFound('user');
177
+		}
178
+		if ( ! $this->hasGroup('Admin'))
179
+		{
180
+			\ErrorHandler::noPermissions();
181
+		}
182
+		else if (\Auth::id() == $user_id)
183
+		{
184
+			\ErrorHandler::noPermissions();
185
+		}
186
+		else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
187
+		{
188
+			\ErrorHandler::noPermissions();
189
+		}
190
+
191
+		$user->blocked = 1;
192
+		$user->save();
193 193
         
194
-        return $user;
195
-    }
196
-
197
-    /**
198
-     * Unblock the user.
199
-     *
200
-     * @param  integer $user_id
201
-     * @return object
202
-     */
203
-    public function unblock($user_id)
204
-    {
205
-        if ( ! $this->hasGroup('Admin'))
206
-        {
207
-            \ErrorHandler::noPermissions();
208
-        }
209
-
210
-        $user          = $this->find($user_id);
211
-        $user->blocked = 0;
212
-        $user->save();
213
-
214
-        return $user;
215
-    }
216
-
217
-    /**
218
-     * Send a reset link to the given user.
219
-     *
220
-     * @param  string  $email
221
-     * @return void
222
-     */
223
-    public function sendReset($email)
224
-    {
225
-        if ( ! $user = $this->model->where('email', $email)->first())
226
-        {
227
-            \ErrorHandler::notFound('email');
228
-        }
229
-
230
-        $url   = $this->config['resetLink'];
231
-        $token = \Password::getRepository()->create($user);
194
+		return $user;
195
+	}
196
+
197
+	/**
198
+	 * Unblock the user.
199
+	 *
200
+	 * @param  integer $user_id
201
+	 * @return object
202
+	 */
203
+	public function unblock($user_id)
204
+	{
205
+		if ( ! $this->hasGroup('Admin'))
206
+		{
207
+			\ErrorHandler::noPermissions();
208
+		}
209
+
210
+		$user          = $this->find($user_id);
211
+		$user->blocked = 0;
212
+		$user->save();
213
+
214
+		return $user;
215
+	}
216
+
217
+	/**
218
+	 * Send a reset link to the given user.
219
+	 *
220
+	 * @param  string  $email
221
+	 * @return void
222
+	 */
223
+	public function sendReset($email)
224
+	{
225
+		if ( ! $user = $this->model->where('email', $email)->first())
226
+		{
227
+			\ErrorHandler::notFound('email');
228
+		}
229
+
230
+		$url   = $this->config['resetLink'];
231
+		$token = \Password::getRepository()->create($user);
232 232
         
233
-        \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) {
234
-            $m->to($user->email, $user->name)->subject('Your Password Reset Link');
235
-        });
236
-    }
237
-
238
-    /**
239
-     * Reset the given user's password.
240
-     *
241
-     * @param  array  $credentials
242
-     * @return array
243
-     */
244
-    public function resetPassword($credentials)
245
-    {
246
-        $response = \Password::reset($credentials, function ($user, $password) {
247
-            $user->password = $password;
248
-            $user->save();
249
-        });
250
-
251
-        switch ($response) {
252
-            case \Password::PASSWORD_RESET:
253
-                return 'success';
233
+		\Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) {
234
+			$m->to($user->email, $user->name)->subject('Your Password Reset Link');
235
+		});
236
+	}
237
+
238
+	/**
239
+	 * Reset the given user's password.
240
+	 *
241
+	 * @param  array  $credentials
242
+	 * @return array
243
+	 */
244
+	public function resetPassword($credentials)
245
+	{
246
+		$response = \Password::reset($credentials, function ($user, $password) {
247
+			$user->password = $password;
248
+			$user->save();
249
+		});
250
+
251
+		switch ($response) {
252
+			case \Password::PASSWORD_RESET:
253
+				return 'success';
254 254
                 
255
-            case \Password::INVALID_TOKEN:
256
-                \ErrorHandler::invalidResetToken('token');
257
-
258
-            case \Password::INVALID_PASSWORD:
259
-                \ErrorHandler::invalidResetPassword('email');
260
-
261
-            case \Password::INVALID_USER:
262
-                \ErrorHandler::notFound('user');
263
-
264
-            default:
265
-                \ErrorHandler::generalError();
266
-        }
267
-    }
268
-
269
-    /**
270
-     * Change the logged in user password.
271
-     *
272
-     * @param  array  $credentials
273
-     * @return void
274
-     */
275
-    public function changePassword($credentials)
276
-    {
277
-        $user = \Auth::user();
278
-        if ( ! \Hash::check($credentials['old_password'], $user->password)) 
279
-        {
280
-            \ErrorHandler::invalidOldPassword();
281
-        }
282
-
283
-        $user->password = $credentials['password'];
284
-        $user->save();
285
-    }
286
-
287
-    /**
288
-     * Paginate all users in the given group based on the given conditions.
289
-     * 
290
-     * @param  string  $groupName
291
-     * @param  array   $relations
292
-     * @param  integer $perPage
293
-     * @param  string  $sortBy
294
-     * @param  boolean $desc
295
-     * @return \Illuminate\Http\Response
296
-     */
297
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
298
-    {   
299
-        unset($conditions['page']);
300
-        $conditions = $this->constructConditions($conditions, $this->model);
301
-        $sort       = $desc ? 'desc' : 'asc';
302
-        $model      = call_user_func_array("{$this->getModel()}::with", array($relations));
303
-
304
-        $model->whereHas('groups', function($q) use ($groupName){
305
-            $q->where('name', $groupName);
306
-        });
255
+			case \Password::INVALID_TOKEN:
256
+				\ErrorHandler::invalidResetToken('token');
257
+
258
+			case \Password::INVALID_PASSWORD:
259
+				\ErrorHandler::invalidResetPassword('email');
260
+
261
+			case \Password::INVALID_USER:
262
+				\ErrorHandler::notFound('user');
263
+
264
+			default:
265
+				\ErrorHandler::generalError();
266
+		}
267
+	}
268
+
269
+	/**
270
+	 * Change the logged in user password.
271
+	 *
272
+	 * @param  array  $credentials
273
+	 * @return void
274
+	 */
275
+	public function changePassword($credentials)
276
+	{
277
+		$user = \Auth::user();
278
+		if ( ! \Hash::check($credentials['old_password'], $user->password)) 
279
+		{
280
+			\ErrorHandler::invalidOldPassword();
281
+		}
282
+
283
+		$user->password = $credentials['password'];
284
+		$user->save();
285
+	}
286
+
287
+	/**
288
+	 * Paginate all users in the given group based on the given conditions.
289
+	 * 
290
+	 * @param  string  $groupName
291
+	 * @param  array   $relations
292
+	 * @param  integer $perPage
293
+	 * @param  string  $sortBy
294
+	 * @param  boolean $desc
295
+	 * @return \Illuminate\Http\Response
296
+	 */
297
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
298
+	{   
299
+		unset($conditions['page']);
300
+		$conditions = $this->constructConditions($conditions, $this->model);
301
+		$sort       = $desc ? 'desc' : 'asc';
302
+		$model      = call_user_func_array("{$this->getModel()}::with", array($relations));
303
+
304
+		$model->whereHas('groups', function($q) use ($groupName){
305
+			$q->where('name', $groupName);
306
+		});
307 307
 
308 308
         
309
-        if (count($conditions['conditionValues']))
310
-        {
311
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
312
-        }
313
-
314
-        if ($perPage) 
315
-        {
316
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
317
-        }
318
-
319
-        return $model->orderBy($sortBy, $sort)->get();
320
-    }
321
-
322
-    /**
323
-     * Save the given data to the logged in user.
324
-     *
325
-     * @param  array $credentials
326
-     * @return void
327
-     */
328
-    public function saveProfile($data) 
329
-    {
330
-        $data['id'] = \Auth::id();
331
-        $this->save($data);
332
-    }
333
-
334
-    /**
335
-     * Ensure access token hasn't expired or revoked.
336
-     * 
337
-     * @param  string $accessToken
338
-     * @return boolean
339
-     */
340
-    public function accessTokenExpiredOrRevoked($accessToken)
341
-    {
342
-
343
-        $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
344
-        $data = new ValidationData();
345
-        $data->setCurrentTime(time());
346
-
347
-        if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
348
-        {
349
-            return true;
350
-        }
351
-
352
-        return false;
353
-    }
309
+		if (count($conditions['conditionValues']))
310
+		{
311
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
312
+		}
313
+
314
+		if ($perPage) 
315
+		{
316
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
317
+		}
318
+
319
+		return $model->orderBy($sortBy, $sort)->get();
320
+	}
321
+
322
+	/**
323
+	 * Save the given data to the logged in user.
324
+	 *
325
+	 * @param  array $credentials
326
+	 * @return void
327
+	 */
328
+	public function saveProfile($data) 
329
+	{
330
+		$data['id'] = \Auth::id();
331
+		$this->save($data);
332
+	}
333
+
334
+	/**
335
+	 * Ensure access token hasn't expired or revoked.
336
+	 * 
337
+	 * @param  string $accessToken
338
+	 * @return boolean
339
+	 */
340
+	public function accessTokenExpiredOrRevoked($accessToken)
341
+	{
342
+
343
+		$accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
344
+		$data = new ValidationData();
345
+		$data->setCurrentTime(time());
346
+
347
+		if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
348
+		{
349
+			return true;
350
+		}
351
+
352
+		return false;
353
+	}
354 354
 }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/OauthClient.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -6,23 +6,23 @@
 block discarded – undo
6 6
 
7 7
 class OauthClient extends Client
8 8
 {
9
-    protected $dates    = ['created_at', 'updated_at'];
10
-    protected $fillable = ['name', 'redirect', 'user_id', 'personal_access_client', 'password_client', 'revoked'];
11
-    public $searchable  = ['name'];
9
+	protected $dates    = ['created_at', 'updated_at'];
10
+	protected $fillable = ['name', 'redirect', 'user_id', 'personal_access_client', 'password_client', 'revoked'];
11
+	public $searchable  = ['name'];
12 12
     
13
-    public function getCreatedAtAttribute($value)
14
-    {
15
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
16
-    }
13
+	public function getCreatedAtAttribute($value)
14
+	{
15
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
16
+	}
17 17
 
18
-    public function getUpdatedAtAttribute($value)
19
-    {
20
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
21
-    }
18
+	public function getUpdatedAtAttribute($value)
19
+	{
20
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
21
+	}
22 22
     
23
-    public static function boot()
24
-    {
25
-        parent::boot();
26
-        parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\OauthClientObserver'));
27
-    }
23
+	public static function boot()
24
+	{
25
+		parent::boot();
26
+		parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\OauthClientObserver'));
27
+	}
28 28
 }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/ModelObservers/OauthClientObserver.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -5,53 +5,53 @@
 block discarded – undo
5 5
  */
6 6
 class OauthClientObserver {
7 7
 
8
-    public function saving($model)
9
-    {
10
-        //
11
-    }
12
-
13
-    public function saved($model)
14
-    {
15
-        //
16
-    }
17
-
18
-    public function creating($model)
19
-    {
20
-        $model->secret = str_random(40);
21
-    }
22
-
23
-    public function created($model)
24
-    {
25
-        //
26
-    }
27
-
28
-    public function updating($model)
29
-    {
30
-        //
31
-    }
32
-
33
-    public function updated($model)
34
-    {
35
-        //
36
-    }
37
-
38
-    public function deleting($model)
39
-    {
40
-        //
41
-    }
42
-
43
-    public function deleted($model)
44
-    {
45
-        //
46
-    }
47
-
48
-    public function restoring($model)
49
-    {
50
-        //
51
-    }
52
-
53
-    public function restored($model)
54
-    {
55
-        //
56
-    }
8
+	public function saving($model)
9
+	{
10
+		//
11
+	}
12
+
13
+	public function saved($model)
14
+	{
15
+		//
16
+	}
17
+
18
+	public function creating($model)
19
+	{
20
+		$model->secret = str_random(40);
21
+	}
22
+
23
+	public function created($model)
24
+	{
25
+		//
26
+	}
27
+
28
+	public function updating($model)
29
+	{
30
+		//
31
+	}
32
+
33
+	public function updated($model)
34
+	{
35
+		//
36
+	}
37
+
38
+	public function deleting($model)
39
+	{
40
+		//
41
+	}
42
+
43
+	public function deleted($model)
44
+	{
45
+		//
46
+	}
47
+
48
+	public function restoring($model)
49
+	{
50
+		//
51
+	}
52
+
53
+	public function restored($model)
54
+	{
55
+		//
56
+	}
57 57
 }
58 58
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Database/Seeds/AclDatabaseSeeder.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -6,18 +6,18 @@
 block discarded – undo
6 6
 
7 7
 class AclDatabaseSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $this->call(ClearDataSeeder::class);
17
-    	$this->call(UsersTableSeeder::class);
18
-    	$this->call(GroupsTableSeeder::class);
19
-    	$this->call(PermissionsTableSeeder::class);
20
-        $this->call(OauthClientsTableSeeder::class);
21
-    	$this->call(AssignRelationsSeeder::class);
22
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$this->call(ClearDataSeeder::class);
17
+		$this->call(UsersTableSeeder::class);
18
+		$this->call(GroupsTableSeeder::class);
19
+		$this->call(PermissionsTableSeeder::class);
20
+		$this->call(OauthClientsTableSeeder::class);
21
+		$this->call(AssignRelationsSeeder::class);
22
+	}
23 23
 }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Database/Factories/OauthClientFactory.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 $factory->define(App\Modules\V1\Acl\OauthClient::class, function (Faker\Generator $faker) {
4
-    return [
5
-    	'user_id'                => $faker->randomDigit(),
4
+	return [
5
+		'user_id'                => $faker->randomDigit(),
6 6
 		'name'                   => $faker->name(),
7 7
 		'secret'                 => str_random(40),
8 8
 		'redirect'               => $faker->url(),
@@ -11,5 +11,5 @@  discard block
 block discarded – undo
11 11
 		'revoked'                => $faker->boolean(),
12 12
 		'created_at'             => $faker->dateTimeBetween('-1 years', 'now'),
13 13
 		'updated_at'             => $faker->dateTimeBetween('-1 years', 'now')
14
-    ];
14
+	];
15 15
 });
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-$factory->define(App\Modules\V1\Acl\OauthClient::class, function (Faker\Generator $faker) {
3
+$factory->define(App\Modules\V1\Acl\OauthClient::class, function(Faker\Generator $faker) {
4 4
     return [
5 5
     	'user_id'                => $faker->randomDigit(),
6 6
 		'name'                   => $faker->name(),
Please login to merge, or discard this patch.
Database/Migrations/2016_06_01_000002_create_oauth_access_tokens_table.php 2 patches
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -6,32 +6,32 @@
 block discarded – undo
6 6
 
7 7
 class CreateOauthAccessTokensTable extends Migration
8 8
 {
9
-    /**
10
-     * Run the migrations.
11
-     *
12
-     * @return void
13
-     */
14
-    public function up()
15
-    {
16
-        Schema::create('oauth_access_tokens', function (Blueprint $table) {
17
-            $table->string('id', 100)->primary();
18
-            $table->integer('user_id')->index()->nullable();
19
-            $table->integer('client_id');
20
-            $table->string('name')->nullable();
21
-            $table->text('scopes')->nullable();
22
-            $table->boolean('revoked');
23
-            $table->timestamps();
24
-            $table->dateTime('expires_at')->nullable();
25
-        });
26
-    }
9
+	/**
10
+	 * Run the migrations.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function up()
15
+	{
16
+		Schema::create('oauth_access_tokens', function (Blueprint $table) {
17
+			$table->string('id', 100)->primary();
18
+			$table->integer('user_id')->index()->nullable();
19
+			$table->integer('client_id');
20
+			$table->string('name')->nullable();
21
+			$table->text('scopes')->nullable();
22
+			$table->boolean('revoked');
23
+			$table->timestamps();
24
+			$table->dateTime('expires_at')->nullable();
25
+		});
26
+	}
27 27
 
28
-    /**
29
-     * Reverse the migrations.
30
-     *
31
-     * @return void
32
-     */
33
-    public function down()
34
-    {
35
-        Schema::drop('oauth_access_tokens');
36
-    }
28
+	/**
29
+	 * Reverse the migrations.
30
+	 *
31
+	 * @return void
32
+	 */
33
+	public function down()
34
+	{
35
+		Schema::drop('oauth_access_tokens');
36
+	}
37 37
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
      */
14 14
     public function up()
15 15
     {
16
-        Schema::create('oauth_access_tokens', function (Blueprint $table) {
16
+        Schema::create('oauth_access_tokens', function(Blueprint $table) {
17 17
             $table->string('id', 100)->primary();
18 18
             $table->integer('user_id')->index()->nullable();
19 19
             $table->integer('client_id');
Please login to merge, or discard this patch.
Migrations/2016_06_01_000005_create_oauth_personal_access_clients_table.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -6,27 +6,27 @@
 block discarded – undo
6 6
 
7 7
 class CreateOauthPersonalAccessClientsTable extends Migration
8 8
 {
9
-    /**
10
-     * Run the migrations.
11
-     *
12
-     * @return void
13
-     */
14
-    public function up()
15
-    {
16
-        Schema::create('oauth_personal_access_clients', function (Blueprint $table) {
17
-            $table->increments('id');
18
-            $table->integer('client_id')->index();
19
-            $table->timestamps();
20
-        });
21
-    }
9
+	/**
10
+	 * Run the migrations.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function up()
15
+	{
16
+		Schema::create('oauth_personal_access_clients', function (Blueprint $table) {
17
+			$table->increments('id');
18
+			$table->integer('client_id')->index();
19
+			$table->timestamps();
20
+		});
21
+	}
22 22
 
23
-    /**
24
-     * Reverse the migrations.
25
-     *
26
-     * @return void
27
-     */
28
-    public function down()
29
-    {
30
-        Schema::drop('oauth_personal_access_clients');
31
-    }
23
+	/**
24
+	 * Reverse the migrations.
25
+	 *
26
+	 * @return void
27
+	 */
28
+	public function down()
29
+	{
30
+		Schema::drop('oauth_personal_access_clients');
31
+	}
32 32
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
      */
14 14
     public function up()
15 15
     {
16
-        Schema::create('oauth_personal_access_clients', function (Blueprint $table) {
16
+        Schema::create('oauth_personal_access_clients', function(Blueprint $table) {
17 17
             $table->increments('id');
18 18
             $table->integer('client_id')->index();
19 19
             $table->timestamps();
Please login to merge, or discard this patch.
Database/Migrations/2016_06_01_000003_create_oauth_refresh_tokens_table.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -6,28 +6,28 @@
 block discarded – undo
6 6
 
7 7
 class CreateOauthRefreshTokensTable extends Migration
8 8
 {
9
-    /**
10
-     * Run the migrations.
11
-     *
12
-     * @return void
13
-     */
14
-    public function up()
15
-    {
16
-        Schema::create('oauth_refresh_tokens', function (Blueprint $table) {
17
-            $table->string('id', 100)->primary();
18
-            $table->string('access_token_id', 100)->index();
19
-            $table->boolean('revoked');
20
-            $table->dateTime('expires_at')->nullable();
21
-        });
22
-    }
9
+	/**
10
+	 * Run the migrations.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function up()
15
+	{
16
+		Schema::create('oauth_refresh_tokens', function (Blueprint $table) {
17
+			$table->string('id', 100)->primary();
18
+			$table->string('access_token_id', 100)->index();
19
+			$table->boolean('revoked');
20
+			$table->dateTime('expires_at')->nullable();
21
+		});
22
+	}
23 23
 
24
-    /**
25
-     * Reverse the migrations.
26
-     *
27
-     * @return void
28
-     */
29
-    public function down()
30
-    {
31
-        Schema::drop('oauth_refresh_tokens');
32
-    }
24
+	/**
25
+	 * Reverse the migrations.
26
+	 *
27
+	 * @return void
28
+	 */
29
+	public function down()
30
+	{
31
+		Schema::drop('oauth_refresh_tokens');
32
+	}
33 33
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
      */
14 14
     public function up()
15 15
     {
16
-        Schema::create('oauth_refresh_tokens', function (Blueprint $table) {
16
+        Schema::create('oauth_refresh_tokens', function(Blueprint $table) {
17 17
             $table->string('id', 100)->primary();
18 18
             $table->string('access_token_id', 100)->index();
19 19
             $table->boolean('revoked');
Please login to merge, or discard this patch.
V1/Acl/Database/Migrations/2016_06_01_000004_create_oauth_clients_table.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
      */
14 14
     public function up()
15 15
     {
16
-        Schema::create('oauth_clients', function (Blueprint $table) {
16
+        Schema::create('oauth_clients', function(Blueprint $table) {
17 17
             $table->increments('id');
18 18
             $table->integer('user_id')->index()->nullable();
19 19
             $table->string('name');
Please login to merge, or discard this patch.
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -6,33 +6,33 @@
 block discarded – undo
6 6
 
7 7
 class CreateOauthClientsTable extends Migration
8 8
 {
9
-    /**
10
-     * Run the migrations.
11
-     *
12
-     * @return void
13
-     */
14
-    public function up()
15
-    {
16
-        Schema::create('oauth_clients', function (Blueprint $table) {
17
-            $table->increments('id');
18
-            $table->integer('user_id')->index()->nullable();
19
-            $table->string('name');
20
-            $table->string('secret', 100);
21
-            $table->text('redirect');
22
-            $table->boolean('personal_access_client')->default(0);
23
-            $table->boolean('password_client')->default(0);
24
-            $table->boolean('revoked')->default(0);
25
-            $table->timestamps();
26
-        });
27
-    }
9
+	/**
10
+	 * Run the migrations.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function up()
15
+	{
16
+		Schema::create('oauth_clients', function (Blueprint $table) {
17
+			$table->increments('id');
18
+			$table->integer('user_id')->index()->nullable();
19
+			$table->string('name');
20
+			$table->string('secret', 100);
21
+			$table->text('redirect');
22
+			$table->boolean('personal_access_client')->default(0);
23
+			$table->boolean('password_client')->default(0);
24
+			$table->boolean('revoked')->default(0);
25
+			$table->timestamps();
26
+		});
27
+	}
28 28
 
29
-    /**
30
-     * Reverse the migrations.
31
-     *
32
-     * @return void
33
-     */
34
-    public function down()
35
-    {
36
-        Schema::drop('oauth_clients');
37
-    }
29
+	/**
30
+	 * Reverse the migrations.
31
+	 *
32
+	 * @return void
33
+	 */
34
+	public function down()
35
+	{
36
+		Schema::drop('oauth_clients');
37
+	}
38 38
 }
Please login to merge, or discard this patch.