Completed
Push — master ( cd8f65...e1eb39 )
by Sherif
27:44
created
src/Modules/V1/Acl/Repositories/UserRepository.php 2 patches
Indentation   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -4,316 +4,316 @@
 block discarded – undo
4 4
 
5 5
 class UserRepository extends AbstractRepository
6 6
 {
7
-    /**
8
-     * Return the model full namespace.
9
-     * 
10
-     * @return string
11
-     */
12
-    protected function getModel()
13
-    {
14
-        return 'App\Modules\V1\Acl\AclUser';
15
-    }
16
-
17
-    /**
18
-     * Return the logged in user account.
19
-     *
20
-     * @param  array   $relations
21
-     * @return boolean
22
-     */
23
-    public function account($relations = [])
24
-    {
25
-        $permissions = [];
26
-        $user        = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations);
27
-        foreach ($user->groups()->get() as $group)
28
-        {
29
-            $group->permissions->each(function ($permission) use (&$permissions){
30
-                $permissions[$permission->model][$permission->id] = $permission->name;
31
-            });
32
-        }
33
-        $user->permissions = $permissions;
34
-
35
-       return $user;
36
-    }
37
-
38
-    /**
39
-     * Check if the logged in user or the given user 
40
-     * has the given permissions on the given model.
41
-     * 
42
-     * @param  string  $nameOfPermission
43
-     * @param  string  $model            
44
-     * @param  boolean $user
45
-     * @return boolean
46
-     */
47
-    public function can($nameOfPermission, $model, $user = false )
48
-    {      
49
-        $user        = $user ?: \JWTAuth::parseToken()->authenticate();
50
-        $permissions = [];
51
-
52
-        if ( ! $user = $this->find($user->id, ['groups.permissions'])) 
53
-        {
54
-            \ErrorHandler::tokenExpired();
55
-        }
56
-
57
-        $user->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
58
-            $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
59
-        });
7
+	/**
8
+	 * Return the model full namespace.
9
+	 * 
10
+	 * @return string
11
+	 */
12
+	protected function getModel()
13
+	{
14
+		return 'App\Modules\V1\Acl\AclUser';
15
+	}
16
+
17
+	/**
18
+	 * Return the logged in user account.
19
+	 *
20
+	 * @param  array   $relations
21
+	 * @return boolean
22
+	 */
23
+	public function account($relations = [])
24
+	{
25
+		$permissions = [];
26
+		$user        = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations);
27
+		foreach ($user->groups()->get() as $group)
28
+		{
29
+			$group->permissions->each(function ($permission) use (&$permissions){
30
+				$permissions[$permission->model][$permission->id] = $permission->name;
31
+			});
32
+		}
33
+		$user->permissions = $permissions;
34
+
35
+	   return $user;
36
+	}
37
+
38
+	/**
39
+	 * Check if the logged in user or the given user 
40
+	 * has the given permissions on the given model.
41
+	 * 
42
+	 * @param  string  $nameOfPermission
43
+	 * @param  string  $model            
44
+	 * @param  boolean $user
45
+	 * @return boolean
46
+	 */
47
+	public function can($nameOfPermission, $model, $user = false )
48
+	{      
49
+		$user        = $user ?: \JWTAuth::parseToken()->authenticate();
50
+		$permissions = [];
51
+
52
+		if ( ! $user = $this->find($user->id, ['groups.permissions'])) 
53
+		{
54
+			\ErrorHandler::tokenExpired();
55
+		}
56
+
57
+		$user->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
58
+			$permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
59
+		});
60 60
         
61
-        return in_array($nameOfPermission, $permissions);
62
-    }
63
-
64
-    /**
65
-     * Check if the logged in user has the given group.
66
-     * 
67
-     * @param  string  $groupName
68
-     * @return boolean
69
-     */
70
-    public function hasGroup($groupName)
71
-    {
72
-        $groups = $this->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
73
-        return $groups->lists('name')->search($groupName, true) === false ? false : true;
74
-    }
75
-
76
-    /**
77
-     * Assign the given group ids to the given user.
78
-     * 
79
-     * @param  integer $user_id    
80
-     * @param  array   $group_ids
81
-     * @return object
82
-     */
83
-    public function assignGroups($user_id, $group_ids)
84
-    {
85
-        \DB::transaction(function () use ($user_id, $group_ids) {
86
-            $user = $this->find($user_id);
87
-            $user->groups()->detach();
88
-            $user->groups()->attach($group_ids);
89
-        });
90
-
91
-        return $this->find($user_id);
92
-    }
93
-
94
-    /**
95
-     * Handle a login request to the application.
96
-     * 
97
-     * @param  array   $credentials    
98
-     * @param  boolean $adminLogin
99
-     * @return array
100
-     */
101
-    public function login($credentials, $adminLogin = false)
102
-    {
103
-        if ( ! $user = $this->first(['email' => $credentials['email']])) 
104
-        {
105
-            \ErrorHandler::loginFailed();
106
-        }
107
-        else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) 
108
-        {
109
-            \ErrorHandler::loginFailed();
110
-        }
111
-        else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) 
112
-        {
113
-            \ErrorHandler::loginFailed();
114
-        }
115
-        else if ($user->blocked)
116
-        {
117
-            \ErrorHandler::userIsBlocked();
118
-        }
119
-        else if ($token = \JWTAuth::attempt($credentials))
120
-        {
121
-            return ['token' => $token];
122
-        }
123
-        else
124
-        {
125
-            \ErrorHandler::loginFailed();
126
-        }
127
-    }
128
-
129
-    /**
130
-     * Handle a social login request of the none admin to the application.
131
-     * 
132
-     * @param  array   $credentials
133
-     * @return array
134
-     */
135
-    public function loginSocial($credentials)
136
-    {
137
-        $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];   
138
-        $user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
139
-
140
-        if ( ! $user->email)
141
-        {
142
-            \ErrorHandler::noSocialEmail();
143
-        }
144
-
145
-        if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
146
-        {
147
-            $data = ['email' => $user->email, 'password' => ''];
148
-            return $this->register($data);
149
-        }
150
-        else
151
-        {
152
-            if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
153
-            {
154
-                \ErrorHandler::userAlreadyRegistered();
155
-            }
156
-            return $this->login(['email' => $registeredUser->email, 'password' => ''], false);
157
-        }
158
-    }
61
+		return in_array($nameOfPermission, $permissions);
62
+	}
63
+
64
+	/**
65
+	 * Check if the logged in user has the given group.
66
+	 * 
67
+	 * @param  string  $groupName
68
+	 * @return boolean
69
+	 */
70
+	public function hasGroup($groupName)
71
+	{
72
+		$groups = $this->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
73
+		return $groups->lists('name')->search($groupName, true) === false ? false : true;
74
+	}
75
+
76
+	/**
77
+	 * Assign the given group ids to the given user.
78
+	 * 
79
+	 * @param  integer $user_id    
80
+	 * @param  array   $group_ids
81
+	 * @return object
82
+	 */
83
+	public function assignGroups($user_id, $group_ids)
84
+	{
85
+		\DB::transaction(function () use ($user_id, $group_ids) {
86
+			$user = $this->find($user_id);
87
+			$user->groups()->detach();
88
+			$user->groups()->attach($group_ids);
89
+		});
90
+
91
+		return $this->find($user_id);
92
+	}
93
+
94
+	/**
95
+	 * Handle a login request to the application.
96
+	 * 
97
+	 * @param  array   $credentials    
98
+	 * @param  boolean $adminLogin
99
+	 * @return array
100
+	 */
101
+	public function login($credentials, $adminLogin = false)
102
+	{
103
+		if ( ! $user = $this->first(['email' => $credentials['email']])) 
104
+		{
105
+			\ErrorHandler::loginFailed();
106
+		}
107
+		else if ($adminLogin && $user->groups->lists('name')->search('Admin', true) === false) 
108
+		{
109
+			\ErrorHandler::loginFailed();
110
+		}
111
+		else if ( ! $adminLogin && $user->groups->lists('name')->search('Admin', true) !== false) 
112
+		{
113
+			\ErrorHandler::loginFailed();
114
+		}
115
+		else if ($user->blocked)
116
+		{
117
+			\ErrorHandler::userIsBlocked();
118
+		}
119
+		else if ($token = \JWTAuth::attempt($credentials))
120
+		{
121
+			return ['token' => $token];
122
+		}
123
+		else
124
+		{
125
+			\ErrorHandler::loginFailed();
126
+		}
127
+	}
128
+
129
+	/**
130
+	 * Handle a social login request of the none admin to the application.
131
+	 * 
132
+	 * @param  array   $credentials
133
+	 * @return array
134
+	 */
135
+	public function loginSocial($credentials)
136
+	{
137
+		$access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];   
138
+		$user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
139
+
140
+		if ( ! $user->email)
141
+		{
142
+			\ErrorHandler::noSocialEmail();
143
+		}
144
+
145
+		if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
146
+		{
147
+			$data = ['email' => $user->email, 'password' => ''];
148
+			return $this->register($data);
149
+		}
150
+		else
151
+		{
152
+			if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
153
+			{
154
+				\ErrorHandler::userAlreadyRegistered();
155
+			}
156
+			return $this->login(['email' => $registeredUser->email, 'password' => ''], false);
157
+		}
158
+	}
159 159
     
160
-    /**
161
-     * Handle a registration request.
162
-     * 
163
-     * @param  array $credentials
164
-     * @return array
165
-     */
166
-    public function register($credentials)
167
-    {
168
-        return ['token' => \JWTAuth::fromUser($this->model->create($credentials))];
169
-    }
170
-
171
-    /**
172
-     * Logout the user.
173
-     * 
174
-     * @return boolean
175
-     */
176
-    public function logout()
177
-    {
178
-        return \JWTAuth::invalidate(\JWTAuth::getToken());
179
-    }
180
-
181
-    /**
182
-     * Block the user.
183
-     *
184
-     * @param  integer $user_id
185
-     * @return object
186
-     */
187
-    public function block($user_id)
188
-    {
189
-        if ( ! $user = $this->find($user_id)) 
190
-        {
191
-            \ErrorHandler::notFound('user');
192
-        }
193
-        if ( ! $this->hasGroup('Admin'))
194
-        {
195
-            \ErrorHandler::noPermissions();
196
-        }
197
-        else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
198
-        {
199
-            \ErrorHandler::noPermissions();
200
-        }
201
-        else if ($user->groups->lists('name')->search('Admin', true) !== false) 
202
-        {
203
-            \ErrorHandler::noPermissions();
204
-        }
205
-
206
-        $user->blocked = 1;
207
-        $user->save();
160
+	/**
161
+	 * Handle a registration request.
162
+	 * 
163
+	 * @param  array $credentials
164
+	 * @return array
165
+	 */
166
+	public function register($credentials)
167
+	{
168
+		return ['token' => \JWTAuth::fromUser($this->model->create($credentials))];
169
+	}
170
+
171
+	/**
172
+	 * Logout the user.
173
+	 * 
174
+	 * @return boolean
175
+	 */
176
+	public function logout()
177
+	{
178
+		return \JWTAuth::invalidate(\JWTAuth::getToken());
179
+	}
180
+
181
+	/**
182
+	 * Block the user.
183
+	 *
184
+	 * @param  integer $user_id
185
+	 * @return object
186
+	 */
187
+	public function block($user_id)
188
+	{
189
+		if ( ! $user = $this->find($user_id)) 
190
+		{
191
+			\ErrorHandler::notFound('user');
192
+		}
193
+		if ( ! $this->hasGroup('Admin'))
194
+		{
195
+			\ErrorHandler::noPermissions();
196
+		}
197
+		else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
198
+		{
199
+			\ErrorHandler::noPermissions();
200
+		}
201
+		else if ($user->groups->lists('name')->search('Admin', true) !== false) 
202
+		{
203
+			\ErrorHandler::noPermissions();
204
+		}
205
+
206
+		$user->blocked = 1;
207
+		$user->save();
208 208
         
209
-        return $user;
210
-    }
211
-
212
-    /**
213
-     * Unblock the user.
214
-     *
215
-     * @param  integer $user_id
216
-     * @return object
217
-     */
218
-    public function unblock($user_id)
219
-    {
220
-        if ( ! $this->hasGroup('Admin'))
221
-        {
222
-            \ErrorHandler::noPermissions();
223
-        }
224
-
225
-        $user          = $this->find($user_id);
226
-        $user->blocked = 0;
227
-        $user->save();
228
-
229
-        return $user;
230
-    }
231
-
232
-    /**
233
-     * Send a reset link to the given user.
234
-     *
235
-     * @param  string  $url
236
-     * @param  string  $email
237
-     * @return void
238
-     */
239
-    public function sendReset($email, $url)
240
-    {
241
-        view()->composer('auth.emails.password', function($view) use ($url) {
242
-            $view->with(['url' => $url]);
243
-        });
244
-
245
-        $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
246
-            $message->subject('Your Password Reset Link');
247
-        });
248
-
249
-        switch ($response) 
250
-        {
251
-            case \Password::INVALID_USER:
252
-                \ErrorHandler::notFound('email');
253
-        }
254
-    }
255
-
256
-    /**
257
-     * Reset the given user's password.
258
-     *
259
-     * @param  array  $credentials
260
-     * @return array
261
-     */
262
-    public function resetPassword($credentials)
263
-    {
264
-        $token    = false;
265
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
266
-            $user->password = bcrypt($password);
267
-            $user->save();
268
-
269
-            $token = \JWTAuth::fromUser($user);
270
-        });
271
-
272
-        switch ($response) {
273
-            case \Password::PASSWORD_RESET:
274
-                return ['token' => $token];
209
+		return $user;
210
+	}
211
+
212
+	/**
213
+	 * Unblock the user.
214
+	 *
215
+	 * @param  integer $user_id
216
+	 * @return object
217
+	 */
218
+	public function unblock($user_id)
219
+	{
220
+		if ( ! $this->hasGroup('Admin'))
221
+		{
222
+			\ErrorHandler::noPermissions();
223
+		}
224
+
225
+		$user          = $this->find($user_id);
226
+		$user->blocked = 0;
227
+		$user->save();
228
+
229
+		return $user;
230
+	}
231
+
232
+	/**
233
+	 * Send a reset link to the given user.
234
+	 *
235
+	 * @param  string  $url
236
+	 * @param  string  $email
237
+	 * @return void
238
+	 */
239
+	public function sendReset($email, $url)
240
+	{
241
+		view()->composer('auth.emails.password', function($view) use ($url) {
242
+			$view->with(['url' => $url]);
243
+		});
244
+
245
+		$response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
246
+			$message->subject('Your Password Reset Link');
247
+		});
248
+
249
+		switch ($response) 
250
+		{
251
+			case \Password::INVALID_USER:
252
+				\ErrorHandler::notFound('email');
253
+		}
254
+	}
255
+
256
+	/**
257
+	 * Reset the given user's password.
258
+	 *
259
+	 * @param  array  $credentials
260
+	 * @return array
261
+	 */
262
+	public function resetPassword($credentials)
263
+	{
264
+		$token    = false;
265
+		$response = \Password::reset($credentials, function ($user, $password) use (&$token) {
266
+			$user->password = bcrypt($password);
267
+			$user->save();
268
+
269
+			$token = \JWTAuth::fromUser($user);
270
+		});
271
+
272
+		switch ($response) {
273
+			case \Password::PASSWORD_RESET:
274
+				return ['token' => $token];
275 275
                 
276
-            case \Password::INVALID_TOKEN:
277
-                \ErrorHandler::invalidResetToken('token');
278
-
279
-            case \Password::INVALID_PASSWORD:
280
-                \ErrorHandler::invalidResetPassword('email');
281
-
282
-            case \Password::INVALID_USER:
283
-                \ErrorHandler::notFound('user');
284
-
285
-            default:
286
-                \ErrorHandler::generalError();
287
-        }
288
-    }
289
-
290
-    /**
291
-     * Change the logged in user password.
292
-     *
293
-     * @param  array  $credentials
294
-     * @return void
295
-     */
296
-    public function changePassword($credentials)
297
-    {
298
-        $user = $this->find(\JWTAuth::parseToken()->authenticate()->id, $relations);
299
-        if ( ! \Hash::check($credentials['old_password'], $user->password)) 
300
-        {
301
-            \ErrorHandler::invalidOldPassword();
302
-        }
303
-
304
-        $user->password = $credentials['password'];
305
-        $user->save();
306
-    }
307
-
308
-    /**
309
-     * Refresh the expired login token.
310
-     *
311
-     * @return array
312
-     */
313
-    public function refreshtoken()
314
-    {
315
-        $token = \JWTAuth::parseToken()->refresh();
316
-
317
-        return ['token' => $token];
318
-    }
276
+			case \Password::INVALID_TOKEN:
277
+				\ErrorHandler::invalidResetToken('token');
278
+
279
+			case \Password::INVALID_PASSWORD:
280
+				\ErrorHandler::invalidResetPassword('email');
281
+
282
+			case \Password::INVALID_USER:
283
+				\ErrorHandler::notFound('user');
284
+
285
+			default:
286
+				\ErrorHandler::generalError();
287
+		}
288
+	}
289
+
290
+	/**
291
+	 * Change the logged in user password.
292
+	 *
293
+	 * @param  array  $credentials
294
+	 * @return void
295
+	 */
296
+	public function changePassword($credentials)
297
+	{
298
+		$user = $this->find(\JWTAuth::parseToken()->authenticate()->id, $relations);
299
+		if ( ! \Hash::check($credentials['old_password'], $user->password)) 
300
+		{
301
+			\ErrorHandler::invalidOldPassword();
302
+		}
303
+
304
+		$user->password = $credentials['password'];
305
+		$user->save();
306
+	}
307
+
308
+	/**
309
+	 * Refresh the expired login token.
310
+	 *
311
+	 * @return array
312
+	 */
313
+	public function refreshtoken()
314
+	{
315
+		$token = \JWTAuth::parseToken()->refresh();
316
+
317
+		return ['token' => $token];
318
+	}
319 319
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         $user        = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations);
27 27
         foreach ($user->groups()->get() as $group)
28 28
         {
29
-            $group->permissions->each(function ($permission) use (&$permissions){
29
+            $group->permissions->each(function($permission) use (&$permissions){
30 30
                 $permissions[$permission->model][$permission->id] = $permission->name;
31 31
             });
32 32
         }
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      * @param  boolean $user
45 45
      * @return boolean
46 46
      */
47
-    public function can($nameOfPermission, $model, $user = false )
47
+    public function can($nameOfPermission, $model, $user = false)
48 48
     {      
49 49
         $user        = $user ?: \JWTAuth::parseToken()->authenticate();
50 50
         $permissions = [];
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             \ErrorHandler::tokenExpired();
55 55
         }
56 56
 
57
-        $user->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
57
+        $user->groups->lists('permissions')->each(function($permission) use (&$permissions, $model){
58 58
             $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
59 59
         });
60 60
         
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function assignGroups($user_id, $group_ids)
84 84
     {
85
-        \DB::transaction(function () use ($user_id, $group_ids) {
85
+        \DB::transaction(function() use ($user_id, $group_ids) {
86 86
             $user = $this->find($user_id);
87 87
             $user->groups()->detach();
88 88
             $user->groups()->attach($group_ids);
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
             $view->with(['url' => $url]);
243 243
         });
244 244
 
245
-        $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
245
+        $response = \Password::sendResetLink($email, function(\Illuminate\Mail\Message $message) {
246 246
             $message->subject('Your Password Reset Link');
247 247
         });
248 248
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
     public function resetPassword($credentials)
263 263
     {
264 264
         $token    = false;
265
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
265
+        $response = \Password::reset($credentials, function($user, $password) use (&$token) {
266 266
             $user->password = bcrypt($password);
267 267
             $user->save();
268 268
 
Please login to merge, or discard this patch.
src/Modules/V1/Acl/ModelObservers/AclGroupObserver.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -5,62 +5,62 @@
 block discarded – undo
5 5
  */
6 6
 class AclGroupObserver {
7 7
 
8
-    public function saving($model)
9
-    {
10
-        //
11
-    }
8
+	public function saving($model)
9
+	{
10
+		//
11
+	}
12 12
 
13
-    public function saved($model)
14
-    {
15
-        //
16
-    }
13
+	public function saved($model)
14
+	{
15
+		//
16
+	}
17 17
 
18
-    public function creating($model)
19
-    {
20
-        //
21
-    }
18
+	public function creating($model)
19
+	{
20
+		//
21
+	}
22 22
 
23
-    public function created($model)
24
-    {
25
-        //
26
-    }
23
+	public function created($model)
24
+	{
25
+		//
26
+	}
27 27
 
28
-    /**
29
-     * Prevent updating of the admin group.
30
-     * 
31
-     * @param  object $model the model beign updated.
32
-     * @return void
33
-     */
34
-    public function updating($model)
35
-    {
36
-        if ($model->getOriginal('name') == 'Admin') 
37
-        {
38
-            \ErrorHandler::noPermissions();
39
-        }
40
-    }
28
+	/**
29
+	 * Prevent updating of the admin group.
30
+	 * 
31
+	 * @param  object $model the model beign updated.
32
+	 * @return void
33
+	 */
34
+	public function updating($model)
35
+	{
36
+		if ($model->getOriginal('name') == 'Admin') 
37
+		{
38
+			\ErrorHandler::noPermissions();
39
+		}
40
+	}
41 41
 
42
-    public function updated($model)
43
-    {
44
-        //
45
-    }
42
+	public function updated($model)
43
+	{
44
+		//
45
+	}
46 46
 
47
-    /**
48
-     * Prevent deleting the admin group.
49
-     * 
50
-     * @param  object $model the delted model.
51
-     * @return void
52
-     */
53
-    public function deleting($model)
54
-    {
55
-        if ($model->getOriginal('name') == 'Admin') 
56
-        {
57
-            \ErrorHandler::noPermissions();
58
-        }
59
-    }
47
+	/**
48
+	 * Prevent deleting the admin group.
49
+	 * 
50
+	 * @param  object $model the delted model.
51
+	 * @return void
52
+	 */
53
+	public function deleting($model)
54
+	{
55
+		if ($model->getOriginal('name') == 'Admin') 
56
+		{
57
+			\ErrorHandler::noPermissions();
58
+		}
59
+	}
60 60
 
61
-    public function deleted($model)
62
-    {
63
-        //
64
-    }
61
+	public function deleted($model)
62
+	{
63
+		//
64
+	}
65 65
 
66 66
 }
67 67
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Acl/ModelObservers/AclUserObserver.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -5,54 +5,54 @@
 block discarded – undo
5 5
  */
6 6
 class AclUserObserver {
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
-        //
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
-    /**
39
-     * Soft delete user logs.
40
-     * 
41
-     * @param  object $model the delted model.
42
-     * @return void
43
-     */
44
-    public function deleting($model)
45
-    {
46
-        if ($model->getOriginal('id') == \JWTAuth::parseToken()->authenticate()->id) 
47
-        {
48
-            \ErrorHandler::noPermissions();
49
-        }
50
-        $model->logs()->delete();
51
-    }
52
-
53
-    public function deleted($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
+		//
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
+	/**
39
+	 * Soft delete user logs.
40
+	 * 
41
+	 * @param  object $model the delted model.
42
+	 * @return void
43
+	 */
44
+	public function deleting($model)
45
+	{
46
+		if ($model->getOriginal('id') == \JWTAuth::parseToken()->authenticate()->id) 
47
+		{
48
+			\ErrorHandler::noPermissions();
49
+		}
50
+		$model->logs()->delete();
51
+	}
52
+
53
+	public function deleted($model)
54
+	{
55
+		//
56
+	}
57 57
 
58 58
 }
59 59
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Database/Migrations/2016_01_05_130507_initialize_acl.php 1 patch
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -13,203 +13,203 @@  discard block
 block discarded – undo
13 13
 	public function up()
14 14
 	{
15 15
 		/**
16
-         * Insert the permissions related to this module.
17
-         */
18
-        DB::table('permissions')->insert(
19
-        	[
20
-        		/**
21
-        		 * Users model permissions.
22
-        		 */
23
-	        	[
24
-	        	'name'       => 'save',
25
-	        	'model'      => 'users',
26
-	        	'created_at' => \DB::raw('NOW()'),
27
-	        	'updated_at' => \DB::raw('NOW()')
28
-	        	],
29
-	        	[
30
-	        	'name'       => 'delete',
31
-	        	'model'      => 'users',
32
-	        	'created_at' => \DB::raw('NOW()'),
33
-	        	'updated_at' => \DB::raw('NOW()')
34
-	        	],
35
-	        	[
36
-	        	'name'       => 'find',
37
-	        	'model'      => 'users',
38
-	        	'created_at' => \DB::raw('NOW()'),
39
-	        	'updated_at' => \DB::raw('NOW()')
40
-	        	],
41
-	        	[
42
-	        	'name'       => 'list',
43
-	        	'model'      => 'users',
44
-	        	'created_at' => \DB::raw('NOW()'),
45
-	        	'updated_at' => \DB::raw('NOW()')
46
-	        	],
47
-	        	[
48
-	        	'name'       => 'search',
49
-	        	'model'      => 'users',
50
-	        	'created_at' => \DB::raw('NOW()'),
51
-	        	'updated_at' => \DB::raw('NOW()')
52
-	        	],
53
-	        	[
54
-	        	'name'       => 'findby',
55
-	        	'model'      => 'users',
56
-	        	'created_at' => \DB::raw('NOW()'),
57
-	        	'updated_at' => \DB::raw('NOW()')
58
-	        	],
59
-	        	[
60
-	        	'name'       => 'first',
61
-	        	'model'      => 'users',
62
-	        	'created_at' => \DB::raw('NOW()'),
63
-	        	'updated_at' => \DB::raw('NOW()')
64
-	        	],
65
-	        	[
66
-	        	'name'       => 'paginate',
67
-	        	'model'      => 'users',
68
-	        	'created_at' => \DB::raw('NOW()'),
69
-	        	'updated_at' => \DB::raw('NOW()')
70
-	        	],
71
-	        	[
72
-	        	'name'       => 'paginateby',
73
-	        	'model'      => 'users',
74
-	        	'created_at' => \DB::raw('NOW()'),
75
-	        	'updated_at' => \DB::raw('NOW()')
76
-	        	],
77
-	        	[
78
-	        	'name'       => 'assigngroups',
79
-	        	'model'      => 'users',
80
-	        	'created_at' => \DB::raw('NOW()'),
81
-	        	'updated_at' => \DB::raw('NOW()')
82
-	        	],
83
-	        	[
84
-	        	'name'       => 'block',
85
-	        	'model'      => 'users',
86
-	        	'created_at' => \DB::raw('NOW()'),
87
-	        	'updated_at' => \DB::raw('NOW()')
88
-	        	],
89
-	        	[
90
-	        	'name'       => 'unblock',
91
-	        	'model'      => 'users',
92
-	        	'created_at' => \DB::raw('NOW()'),
93
-	        	'updated_at' => \DB::raw('NOW()')
94
-	        	],
16
+		 * Insert the permissions related to this module.
17
+		 */
18
+		DB::table('permissions')->insert(
19
+			[
20
+				/**
21
+				 * Users model permissions.
22
+				 */
23
+				[
24
+				'name'       => 'save',
25
+				'model'      => 'users',
26
+				'created_at' => \DB::raw('NOW()'),
27
+				'updated_at' => \DB::raw('NOW()')
28
+				],
29
+				[
30
+				'name'       => 'delete',
31
+				'model'      => 'users',
32
+				'created_at' => \DB::raw('NOW()'),
33
+				'updated_at' => \DB::raw('NOW()')
34
+				],
35
+				[
36
+				'name'       => 'find',
37
+				'model'      => 'users',
38
+				'created_at' => \DB::raw('NOW()'),
39
+				'updated_at' => \DB::raw('NOW()')
40
+				],
41
+				[
42
+				'name'       => 'list',
43
+				'model'      => 'users',
44
+				'created_at' => \DB::raw('NOW()'),
45
+				'updated_at' => \DB::raw('NOW()')
46
+				],
47
+				[
48
+				'name'       => 'search',
49
+				'model'      => 'users',
50
+				'created_at' => \DB::raw('NOW()'),
51
+				'updated_at' => \DB::raw('NOW()')
52
+				],
53
+				[
54
+				'name'       => 'findby',
55
+				'model'      => 'users',
56
+				'created_at' => \DB::raw('NOW()'),
57
+				'updated_at' => \DB::raw('NOW()')
58
+				],
59
+				[
60
+				'name'       => 'first',
61
+				'model'      => 'users',
62
+				'created_at' => \DB::raw('NOW()'),
63
+				'updated_at' => \DB::raw('NOW()')
64
+				],
65
+				[
66
+				'name'       => 'paginate',
67
+				'model'      => 'users',
68
+				'created_at' => \DB::raw('NOW()'),
69
+				'updated_at' => \DB::raw('NOW()')
70
+				],
71
+				[
72
+				'name'       => 'paginateby',
73
+				'model'      => 'users',
74
+				'created_at' => \DB::raw('NOW()'),
75
+				'updated_at' => \DB::raw('NOW()')
76
+				],
77
+				[
78
+				'name'       => 'assigngroups',
79
+				'model'      => 'users',
80
+				'created_at' => \DB::raw('NOW()'),
81
+				'updated_at' => \DB::raw('NOW()')
82
+				],
83
+				[
84
+				'name'       => 'block',
85
+				'model'      => 'users',
86
+				'created_at' => \DB::raw('NOW()'),
87
+				'updated_at' => \DB::raw('NOW()')
88
+				],
89
+				[
90
+				'name'       => 'unblock',
91
+				'model'      => 'users',
92
+				'created_at' => \DB::raw('NOW()'),
93
+				'updated_at' => \DB::raw('NOW()')
94
+				],
95 95
 
96
-	        	/**
97
-        		 * Permissions model permissions.
98
-        		 */
99
-        		[
100
-	        	'name'       => 'find',
101
-	        	'model'      => 'permissions',
102
-	        	'created_at' => \DB::raw('NOW()'),
103
-	        	'updated_at' => \DB::raw('NOW()')
104
-	        	],
105
-	        	[
106
-	        	'name'       => 'search',
107
-	        	'model'      => 'permissions',
108
-	        	'created_at' => \DB::raw('NOW()'),
109
-	        	'updated_at' => \DB::raw('NOW()')
110
-	        	],
111
-	        	[
112
-	        	'name'       => 'list',
113
-	        	'model'      => 'permissions',
114
-	        	'created_at' => \DB::raw('NOW()'),
115
-	        	'updated_at' => \DB::raw('NOW()')
116
-	        	],
117
-	        	[
118
-	        	'name'       => 'findby',
119
-	        	'model'      => 'permissions',
120
-	        	'created_at' => \DB::raw('NOW()'),
121
-	        	'updated_at' => \DB::raw('NOW()')
122
-	        	],
123
-	        	[
124
-	        	'name'       => 'first',
125
-	        	'model'      => 'permissions',
126
-	        	'created_at' => \DB::raw('NOW()'),
127
-	        	'updated_at' => \DB::raw('NOW()')
128
-	        	],
129
-	        	[
130
-	        	'name'       => 'paginate',
131
-	        	'model'      => 'permissions',
132
-	        	'created_at' => \DB::raw('NOW()'),
133
-	        	'updated_at' => \DB::raw('NOW()')
134
-	        	],
135
-	        	[
136
-	        	'name'       => 'paginateby',
137
-	        	'model'      => 'permissions',
138
-	        	'created_at' => \DB::raw('NOW()'),
139
-	        	'updated_at' => \DB::raw('NOW()')
140
-	        	],
96
+				/**
97
+				 * Permissions model permissions.
98
+				 */
99
+				[
100
+				'name'       => 'find',
101
+				'model'      => 'permissions',
102
+				'created_at' => \DB::raw('NOW()'),
103
+				'updated_at' => \DB::raw('NOW()')
104
+				],
105
+				[
106
+				'name'       => 'search',
107
+				'model'      => 'permissions',
108
+				'created_at' => \DB::raw('NOW()'),
109
+				'updated_at' => \DB::raw('NOW()')
110
+				],
111
+				[
112
+				'name'       => 'list',
113
+				'model'      => 'permissions',
114
+				'created_at' => \DB::raw('NOW()'),
115
+				'updated_at' => \DB::raw('NOW()')
116
+				],
117
+				[
118
+				'name'       => 'findby',
119
+				'model'      => 'permissions',
120
+				'created_at' => \DB::raw('NOW()'),
121
+				'updated_at' => \DB::raw('NOW()')
122
+				],
123
+				[
124
+				'name'       => 'first',
125
+				'model'      => 'permissions',
126
+				'created_at' => \DB::raw('NOW()'),
127
+				'updated_at' => \DB::raw('NOW()')
128
+				],
129
+				[
130
+				'name'       => 'paginate',
131
+				'model'      => 'permissions',
132
+				'created_at' => \DB::raw('NOW()'),
133
+				'updated_at' => \DB::raw('NOW()')
134
+				],
135
+				[
136
+				'name'       => 'paginateby',
137
+				'model'      => 'permissions',
138
+				'created_at' => \DB::raw('NOW()'),
139
+				'updated_at' => \DB::raw('NOW()')
140
+				],
141 141
 
142
-	        	/**
143
-        		 * Groups model permissions.
144
-        		 */
145
-	        	[
146
-	        	'name'       => 'save',
147
-	        	'model'      => 'groups',
148
-	        	'created_at' => \DB::raw('NOW()'),
149
-	        	'updated_at' => \DB::raw('NOW()')
150
-	        	],
151
-	        	[
152
-	        	'name'       => 'delete',
153
-	        	'model'      => 'groups',
154
-	        	'created_at' => \DB::raw('NOW()'),
155
-	        	'updated_at' => \DB::raw('NOW()')
156
-	        	],
157
-	        	[
158
-	        	'name'       => 'find',
159
-	        	'model'      => 'groups',
160
-	        	'created_at' => \DB::raw('NOW()'),
161
-	        	'updated_at' => \DB::raw('NOW()')
162
-	        	],
163
-	        	[
164
-	        	'name'       => 'search',
165
-	        	'model'      => 'groups',
166
-	        	'created_at' => \DB::raw('NOW()'),
167
-	        	'updated_at' => \DB::raw('NOW()')
168
-	        	],
169
-	        	[
170
-	        	'name'       => 'list',
171
-	        	'model'      => 'groups',
172
-	        	'created_at' => \DB::raw('NOW()'),
173
-	        	'updated_at' => \DB::raw('NOW()')
174
-	        	],
175
-	        	[
176
-	        	'name'       => 'findby',
177
-	        	'model'      => 'groups',
178
-	        	'created_at' => \DB::raw('NOW()'),
179
-	        	'updated_at' => \DB::raw('NOW()')
180
-	        	],
181
-	        	[
182
-	        	'name'       => 'first',
183
-	        	'model'      => 'groups',
184
-	        	'created_at' => \DB::raw('NOW()'),
185
-	        	'updated_at' => \DB::raw('NOW()')
186
-	        	],
187
-	        	[
188
-	        	'name'       => 'paginate',
189
-	        	'model'      => 'groups',
190
-	        	'created_at' => \DB::raw('NOW()'),
191
-	        	'updated_at' => \DB::raw('NOW()')
192
-	        	],
193
-	        	[
194
-	        	'name'       => 'paginateby',
195
-	        	'model'      => 'groups',
196
-	        	'created_at' => \DB::raw('NOW()'),
197
-	        	'updated_at' => \DB::raw('NOW()')
198
-	        	],
199
-	        	[
200
-	        	'name'       => 'assignpermissions',
201
-	        	'model'      => 'groups',
202
-	        	'created_at' => \DB::raw('NOW()'),
203
-	        	'updated_at' => \DB::raw('NOW()')
204
-	        	],
205
-	        	[
206
-	        	'name'       => 'users',
207
-	        	'model'      => 'groups',
208
-	        	'created_at' => \DB::raw('NOW()'),
209
-	        	'updated_at' => \DB::raw('NOW()')
210
-	        	],
211
-        	]
212
-        );
142
+				/**
143
+				 * Groups model permissions.
144
+				 */
145
+				[
146
+				'name'       => 'save',
147
+				'model'      => 'groups',
148
+				'created_at' => \DB::raw('NOW()'),
149
+				'updated_at' => \DB::raw('NOW()')
150
+				],
151
+				[
152
+				'name'       => 'delete',
153
+				'model'      => 'groups',
154
+				'created_at' => \DB::raw('NOW()'),
155
+				'updated_at' => \DB::raw('NOW()')
156
+				],
157
+				[
158
+				'name'       => 'find',
159
+				'model'      => 'groups',
160
+				'created_at' => \DB::raw('NOW()'),
161
+				'updated_at' => \DB::raw('NOW()')
162
+				],
163
+				[
164
+				'name'       => 'search',
165
+				'model'      => 'groups',
166
+				'created_at' => \DB::raw('NOW()'),
167
+				'updated_at' => \DB::raw('NOW()')
168
+				],
169
+				[
170
+				'name'       => 'list',
171
+				'model'      => 'groups',
172
+				'created_at' => \DB::raw('NOW()'),
173
+				'updated_at' => \DB::raw('NOW()')
174
+				],
175
+				[
176
+				'name'       => 'findby',
177
+				'model'      => 'groups',
178
+				'created_at' => \DB::raw('NOW()'),
179
+				'updated_at' => \DB::raw('NOW()')
180
+				],
181
+				[
182
+				'name'       => 'first',
183
+				'model'      => 'groups',
184
+				'created_at' => \DB::raw('NOW()'),
185
+				'updated_at' => \DB::raw('NOW()')
186
+				],
187
+				[
188
+				'name'       => 'paginate',
189
+				'model'      => 'groups',
190
+				'created_at' => \DB::raw('NOW()'),
191
+				'updated_at' => \DB::raw('NOW()')
192
+				],
193
+				[
194
+				'name'       => 'paginateby',
195
+				'model'      => 'groups',
196
+				'created_at' => \DB::raw('NOW()'),
197
+				'updated_at' => \DB::raw('NOW()')
198
+				],
199
+				[
200
+				'name'       => 'assignpermissions',
201
+				'model'      => 'groups',
202
+				'created_at' => \DB::raw('NOW()'),
203
+				'updated_at' => \DB::raw('NOW()')
204
+				],
205
+				[
206
+				'name'       => 'users',
207
+				'model'      => 'groups',
208
+				'created_at' => \DB::raw('NOW()'),
209
+				'updated_at' => \DB::raw('NOW()')
210
+				],
211
+			]
212
+		);
213 213
 
214 214
 		/**
215 215
 		 * Delete previous data.
@@ -237,29 +237,29 @@  discard block
 block discarded – undo
237 237
 		 * Create Default users.
238 238
 		 */
239 239
 		$adminUserId = DB::table('users')->insertGetId(
240
-            [
240
+			[
241 241
 			'email'      => '[email protected]',
242 242
 			'password'   => bcrypt('123456'),
243 243
 			'created_at' => \DB::raw('NOW()'),
244 244
 			'updated_at' => \DB::raw('NOW()')
245 245
 			]
246
-        );
246
+		);
247 247
 
248 248
 		/**
249 249
 		 * Assign users to groups.
250 250
 		 */
251 251
 		DB::table('users_groups')->insert(
252
-        	[
253
-	            [
252
+			[
253
+				[
254 254
 				'user_id'    => $adminUserId,
255 255
 				'group_id'   => $adminGroupId,
256 256
 				'created_at' => \DB::raw('NOW()'),
257 257
 				'updated_at' => \DB::raw('NOW()')
258
-	            ]
259
-        	]
260
-        );
258
+				]
259
+			]
260
+		);
261 261
 
262
-        /**
262
+		/**
263 263
 		 * Assign the permissions to the admin group.
264 264
 		 */
265 265
 		$permissionIds = DB::table('permissions')->whereIn('model', ['users', 'permissions', 'groups'])->select('id')->lists('id');
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Database/Migrations/2015_12_20_124153_users.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@
 block discarded – undo
13 13
 	public function up()
14 14
 	{
15 15
 		Schema::create('users', function (Blueprint $table) {
16
-            $table->increments('id');
17
-            $table->string('name',100);
18
-            $table->string('email')->unique();
19
-            $table->string('password', 60);
20
-            $table->boolean('blocked', 0);
21
-            $table->softDeletes();
22
-            $table->rememberToken();
23
-            $table->timestamps();
24
-        });
16
+			$table->increments('id');
17
+			$table->string('name',100);
18
+			$table->string('email')->unique();
19
+			$table->string('password', 60);
20
+			$table->boolean('blocked', 0);
21
+			$table->softDeletes();
22
+			$table->rememberToken();
23
+			$table->timestamps();
24
+		});
25 25
 	}
26 26
 
27 27
 	/**
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@
 block discarded – undo
12 12
 	 */
13 13
 	public function up()
14 14
 	{
15
-		Schema::create('users', function (Blueprint $table) {
15
+		Schema::create('users', function(Blueprint $table) {
16 16
             $table->increments('id');
17
-            $table->string('name',100);
17
+            $table->string('name', 100);
18 18
             $table->string('email')->unique();
19 19
             $table->string('password', 60);
20 20
             $table->boolean('blocked', 0);
Please login to merge, or discard this patch.
src/Modules/V1/Acl/AclUser.php 2 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -6,53 +6,53 @@
 block discarded – undo
6 6
 
7 7
 class AclUser extends User {
8 8
 
9
-    use SoftDeletes;
10
-    protected $table    = 'users';
11
-    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
-    protected $hidden   = ['password', 'remember_token','deleted_at'];
13
-    protected $guarded  = ['id'];
14
-    protected $fillable = ['name', 'email', 'password'];
15
-    public $searchable  = ['name', 'email'];
9
+	use SoftDeletes;
10
+	protected $table    = 'users';
11
+	protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
+	protected $hidden   = ['password', 'remember_token','deleted_at'];
13
+	protected $guarded  = ['id'];
14
+	protected $fillable = ['name', 'email', 'password'];
15
+	public $searchable  = ['name', 'email'];
16 16
     
17
-    public function getCreatedAtAttribute($value)
18
-    {
19
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
20
-    }
21
-
22
-    public function getUpdatedAtAttribute($value)
23
-    {
24
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
25
-    }
26
-
27
-    public function getDeletedAtAttribute($value)
28
-    {
29
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
30
-    }
31
-
32
-    /**
33
-     * Encrypt the password attribute before
34
-     * saving it in the storage.
35
-     * 
36
-     * @param string $value 
37
-     */
38
-    public function setPasswordAttribute($value)
39
-    {
40
-        $this->attributes['password'] = bcrypt($value);
41
-    }
42
-
43
-    public function logs()
44
-    {
45
-        return $this->hasMany('App\Modules\V1\Core\Log', 'user_id');
46
-    }
47
-
48
-    public function groups()
49
-    {
50
-        return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
51
-    }
17
+	public function getCreatedAtAttribute($value)
18
+	{
19
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
20
+	}
21
+
22
+	public function getUpdatedAtAttribute($value)
23
+	{
24
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
25
+	}
26
+
27
+	public function getDeletedAtAttribute($value)
28
+	{
29
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
30
+	}
31
+
32
+	/**
33
+	 * Encrypt the password attribute before
34
+	 * saving it in the storage.
35
+	 * 
36
+	 * @param string $value 
37
+	 */
38
+	public function setPasswordAttribute($value)
39
+	{
40
+		$this->attributes['password'] = bcrypt($value);
41
+	}
42
+
43
+	public function logs()
44
+	{
45
+		return $this->hasMany('App\Modules\V1\Core\Log', 'user_id');
46
+	}
47
+
48
+	public function groups()
49
+	{
50
+		return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
51
+	}
52 52
     
53
-    public static function boot()
54
-    {
55
-        parent::boot();
56
-        parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver'));
57
-    }
53
+	public static function boot()
54
+	{
55
+		parent::boot();
56
+		parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver'));
57
+	}
58 58
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     use SoftDeletes;
10 10
     protected $table    = 'users';
11 11
     protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
-    protected $hidden   = ['password', 'remember_token','deleted_at'];
12
+    protected $hidden   = ['password', 'remember_token', 'deleted_at'];
13 13
     protected $guarded  = ['id'];
14 14
     protected $fillable = ['name', 'email', 'password'];
15 15
     public $searchable  = ['name', 'email'];
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 
48 48
     public function groups()
49 49
     {
50
-        return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
50
+        return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup', 'users_groups', 'user_id', 'group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
51 51
     }
52 52
     
53 53
     public static function boot()
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Http/Controllers/UsersController.php 1 patch
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -7,201 +7,201 @@
 block discarded – undo
7 7
 
8 8
 class UsersController extends BaseApiController
9 9
 {
10
-    /**
11
-     * The name of the model that is used by the base api controller 
12
-     * to preform actions like (add, edit ... etc).
13
-     * @var string
14
-     */
15
-    protected $model               = 'users';
16
-
17
-    /**
18
-     * List of all route actions that the base api controller
19
-     * will skip permissions check for them.
20
-     * @var array
21
-     */
22
-    protected $skipPermissionCheck = ['account', 'logout', 'sendreset'];
23
-
24
-    /**
25
-     * List of all route actions that the base api controller
26
-     * will skip login check for them.
27
-     * @var array
28
-     */
29
-    protected $skipLoginCheck      = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken'];
30
-
31
-    /**
32
-     * The validations rules used by the base api controller
33
-     * to check before add.
34
-     * @var array
35
-     */
36
-    protected $validationRules     = [
37
-    'email'    => 'required|email|unique:users,email,{id}',
38
-    'password' => 'min:6'
39
-    ];
40
-
41
-    /**
42
-     * Return the logged in user account.
43
-     * 
44
-     * @return \Illuminate\Http\Response
45
-     */
46
-    public function account()
47
-    {
48
-        $relations = $this->relations && $this->relations['account'] ? $this->relations['account'] : [];
49
-        return \Response::json(\Core::users()->account($relations), 200);
50
-    }
51
-
52
-    /**
53
-     * Block the user.
54
-     *
55
-     * @param  integer  $id
56
-     * @return \Illuminate\Http\Response
57
-     */
58
-    public function block($id)
59
-    {
60
-        return \Response::json(\Core::users()->block($id), 200);
61
-    }
62
-
63
-    /**
64
-     * Unblock the user.
65
-     *
66
-     * @param  integer  $id
67
-     * @return \Illuminate\Http\Response
68
-     */
69
-    public function unblock($id)
70
-    {
71
-        return \Response::json(\Core::users()->unblock($id), 200);
72
-    }
73
-
74
-    /**
75
-     * Logout the user.
76
-     * 
77
-     * @return \Illuminate\Http\Response
78
-     */
79
-    public function logout()
80
-    {
81
-        return \Response::json(\Core::users()->logout(), 200);
82
-    }
83
-
84
-    /**
85
-     * Handle a registration request.
86
-     *
87
-     * @param  \Illuminate\Http\Request  $request
88
-     * @return \Illuminate\Http\Response
89
-     */
90
-    public function register(Request $request)
91
-    {
92
-        $this->validate($request, [
93
-            'email'    => 'required|email|unique:users,email,{id}', 
94
-            'password' => 'required|min:6'
95
-            ]);
96
-
97
-        return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
98
-    }
99
-
100
-    /**
101
-     * Handle a login request of the none admin to the application.
102
-     *
103
-     * @param  \Illuminate\Http\Request  $request
104
-     * @return \Illuminate\Http\Response
105
-     */
106
-    public function login(Request $request)
107
-    {
108
-        $this->validate($request, [
109
-            'email'    => 'required|email', 
110
-            'password' => 'required|min:6',
111
-            'admin'    => 'boolean'
112
-            ]);
113
-
114
-        return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
115
-    }
116
-
117
-    /**
118
-     * Handle a social login request of the none admin to the application.
119
-     *
120
-     * @param  \Illuminate\Http\Request  $request
121
-     * @return \Illuminate\Http\Response
122
-     */
123
-    public function loginSocial(Request $request)
124
-    {
125
-        $this->validate($request, [
126
-            'auth_code'    => 'required_without:access_token',
127
-            'access_token' => 'required_without:auth_code',
128
-            'type'         => 'required|in:facebook,google'
129
-            ]);
130
-
131
-        return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200);
132
-    }
133
-
134
-    /**
135
-     * Handle an assign groups to user request.
136
-     *
137
-     * @param  \Illuminate\Http\Request  $request
138
-     * @return \Illuminate\Http\Response
139
-     */
140
-    public function assigngroups(Request $request)
141
-    {
142
-        $this->validate($request, [
143
-            'group_ids' => 'required|exists:groups,id', 
144
-            'user_id'   => 'required|exists:users,id'
145
-            ]);
146
-
147
-        return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
148
-    }
149
-
150
-    /**
151
-     * Send a reset link to the given user.
152
-     *
153
-     * @param  \Illuminate\Http\Request  $request
154
-     * @return \Illuminate\Http\Response
155
-     */
156
-    public function sendreset(Request $request)
157
-    {
158
-        $this->validate($request, ['email' => 'required|email', 'url' => 'required|url']);
159
-
160
-        return \Response::json(\Core::users()->sendReset($request->only('email'), $request->get('url')), 200);
161
-    }
162
-
163
-    /**
164
-     * Reset the given user's password.
165
-     *
166
-     * @param  \Illuminate\Http\Request  $request
167
-     * @return \Illuminate\Http\Response
168
-     */
169
-    public function resetpassword(Request $request)
170
-    {
171
-        $this->validate($request, [
172
-            'token'                 => 'required',
173
-            'email'                 => 'required|email',
174
-            'password'              => 'required|confirmed|min:6',
175
-            'password_confirmation' => 'required',
176
-        ]);
177
-
178
-        return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
179
-    }
180
-
181
-    /**
182
-     * Change the logged in user password.
183
-     *
184
-     * @param  \Illuminate\Http\Request  $request
185
-     * @return \Illuminate\Http\Response
186
-     */
187
-    public function changePassword(Request $request)
188
-    {
189
-        $this->validate($request, [
190
-            'old_password'          => 'required',
191
-            'password'              => 'required|confirmed|min:6',
192
-            'password_confirmation' => 'required',
193
-        ]);
194
-
195
-        return \Response::json(\Core::users()->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
196
-    }
197
-
198
-    /**
199
-     * Refresh the expired login token.
200
-     *
201
-     * @return \Illuminate\Http\Response
202
-     */
203
-    public function refreshtoken()
204
-    {
205
-        return \Response::json(\Core::users()->refreshtoken(), 200);
206
-    }
10
+	/**
11
+	 * The name of the model that is used by the base api controller 
12
+	 * to preform actions like (add, edit ... etc).
13
+	 * @var string
14
+	 */
15
+	protected $model               = 'users';
16
+
17
+	/**
18
+	 * List of all route actions that the base api controller
19
+	 * will skip permissions check for them.
20
+	 * @var array
21
+	 */
22
+	protected $skipPermissionCheck = ['account', 'logout', 'sendreset'];
23
+
24
+	/**
25
+	 * List of all route actions that the base api controller
26
+	 * will skip login check for them.
27
+	 * @var array
28
+	 */
29
+	protected $skipLoginCheck      = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken'];
30
+
31
+	/**
32
+	 * The validations rules used by the base api controller
33
+	 * to check before add.
34
+	 * @var array
35
+	 */
36
+	protected $validationRules     = [
37
+	'email'    => 'required|email|unique:users,email,{id}',
38
+	'password' => 'min:6'
39
+	];
40
+
41
+	/**
42
+	 * Return the logged in user account.
43
+	 * 
44
+	 * @return \Illuminate\Http\Response
45
+	 */
46
+	public function account()
47
+	{
48
+		$relations = $this->relations && $this->relations['account'] ? $this->relations['account'] : [];
49
+		return \Response::json(\Core::users()->account($relations), 200);
50
+	}
51
+
52
+	/**
53
+	 * Block the user.
54
+	 *
55
+	 * @param  integer  $id
56
+	 * @return \Illuminate\Http\Response
57
+	 */
58
+	public function block($id)
59
+	{
60
+		return \Response::json(\Core::users()->block($id), 200);
61
+	}
62
+
63
+	/**
64
+	 * Unblock the user.
65
+	 *
66
+	 * @param  integer  $id
67
+	 * @return \Illuminate\Http\Response
68
+	 */
69
+	public function unblock($id)
70
+	{
71
+		return \Response::json(\Core::users()->unblock($id), 200);
72
+	}
73
+
74
+	/**
75
+	 * Logout the user.
76
+	 * 
77
+	 * @return \Illuminate\Http\Response
78
+	 */
79
+	public function logout()
80
+	{
81
+		return \Response::json(\Core::users()->logout(), 200);
82
+	}
83
+
84
+	/**
85
+	 * Handle a registration request.
86
+	 *
87
+	 * @param  \Illuminate\Http\Request  $request
88
+	 * @return \Illuminate\Http\Response
89
+	 */
90
+	public function register(Request $request)
91
+	{
92
+		$this->validate($request, [
93
+			'email'    => 'required|email|unique:users,email,{id}', 
94
+			'password' => 'required|min:6'
95
+			]);
96
+
97
+		return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
98
+	}
99
+
100
+	/**
101
+	 * Handle a login request of the none admin to the application.
102
+	 *
103
+	 * @param  \Illuminate\Http\Request  $request
104
+	 * @return \Illuminate\Http\Response
105
+	 */
106
+	public function login(Request $request)
107
+	{
108
+		$this->validate($request, [
109
+			'email'    => 'required|email', 
110
+			'password' => 'required|min:6',
111
+			'admin'    => 'boolean'
112
+			]);
113
+
114
+		return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
115
+	}
116
+
117
+	/**
118
+	 * Handle a social login request of the none admin to the application.
119
+	 *
120
+	 * @param  \Illuminate\Http\Request  $request
121
+	 * @return \Illuminate\Http\Response
122
+	 */
123
+	public function loginSocial(Request $request)
124
+	{
125
+		$this->validate($request, [
126
+			'auth_code'    => 'required_without:access_token',
127
+			'access_token' => 'required_without:auth_code',
128
+			'type'         => 'required|in:facebook,google'
129
+			]);
130
+
131
+		return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200);
132
+	}
133
+
134
+	/**
135
+	 * Handle an assign groups to user request.
136
+	 *
137
+	 * @param  \Illuminate\Http\Request  $request
138
+	 * @return \Illuminate\Http\Response
139
+	 */
140
+	public function assigngroups(Request $request)
141
+	{
142
+		$this->validate($request, [
143
+			'group_ids' => 'required|exists:groups,id', 
144
+			'user_id'   => 'required|exists:users,id'
145
+			]);
146
+
147
+		return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
148
+	}
149
+
150
+	/**
151
+	 * Send a reset link to the given user.
152
+	 *
153
+	 * @param  \Illuminate\Http\Request  $request
154
+	 * @return \Illuminate\Http\Response
155
+	 */
156
+	public function sendreset(Request $request)
157
+	{
158
+		$this->validate($request, ['email' => 'required|email', 'url' => 'required|url']);
159
+
160
+		return \Response::json(\Core::users()->sendReset($request->only('email'), $request->get('url')), 200);
161
+	}
162
+
163
+	/**
164
+	 * Reset the given user's password.
165
+	 *
166
+	 * @param  \Illuminate\Http\Request  $request
167
+	 * @return \Illuminate\Http\Response
168
+	 */
169
+	public function resetpassword(Request $request)
170
+	{
171
+		$this->validate($request, [
172
+			'token'                 => 'required',
173
+			'email'                 => 'required|email',
174
+			'password'              => 'required|confirmed|min:6',
175
+			'password_confirmation' => 'required',
176
+		]);
177
+
178
+		return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
179
+	}
180
+
181
+	/**
182
+	 * Change the logged in user password.
183
+	 *
184
+	 * @param  \Illuminate\Http\Request  $request
185
+	 * @return \Illuminate\Http\Response
186
+	 */
187
+	public function changePassword(Request $request)
188
+	{
189
+		$this->validate($request, [
190
+			'old_password'          => 'required',
191
+			'password'              => 'required|confirmed|min:6',
192
+			'password_confirmation' => 'required',
193
+		]);
194
+
195
+		return \Response::json(\Core::users()->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
196
+	}
197
+
198
+	/**
199
+	 * Refresh the expired login token.
200
+	 *
201
+	 * @return \Illuminate\Http\Response
202
+	 */
203
+	public function refreshtoken()
204
+	{
205
+		return \Response::json(\Core::users()->refreshtoken(), 200);
206
+	}
207 207
 }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Http/Controllers/GroupsController.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -8,53 +8,53 @@
 block discarded – undo
8 8
 
9 9
 class GroupsController extends BaseApiController
10 10
 {
11
-    /**
12
-     * The name of the model that is used by the base api controller 
13
-     * to preform actions like (add, edit ... etc).
14
-     * @var string
15
-     */
16
-    protected $model               = 'groups';
11
+	/**
12
+	 * The name of the model that is used by the base api controller 
13
+	 * to preform actions like (add, edit ... etc).
14
+	 * @var string
15
+	 */
16
+	protected $model               = 'groups';
17 17
 
18
-    /**
19
-     * The validations rules used by the base api controller
20
-     * to check before add.
21
-     * @var array
22
-     */
23
-    protected $validationRules  = [
24
-    'name' => 'required|string|max:100|unique:groups,name,{id}'
25
-    ];
18
+	/**
19
+	 * The validations rules used by the base api controller
20
+	 * to check before add.
21
+	 * @var array
22
+	 */
23
+	protected $validationRules  = [
24
+	'name' => 'required|string|max:100|unique:groups,name,{id}'
25
+	];
26 26
 
27
-    /**
28
-     * Handle an assign permissions to group request.
29
-     *
30
-     * @param  \Illuminate\Http\Request  $request
31
-     * @return \Illuminate\Http\Response
32
-     */
33
-    public function assignpermissions(Request $request)
34
-    {
35
-        $this->validate($request, [
36
-            'permission_ids' => 'required|exists:permissions,id', 
37
-            'group_id'       => 'required|array|exists:groups,id'
38
-            ]);
27
+	/**
28
+	 * Handle an assign permissions to group request.
29
+	 *
30
+	 * @param  \Illuminate\Http\Request  $request
31
+	 * @return \Illuminate\Http\Response
32
+	 */
33
+	public function assignpermissions(Request $request)
34
+	{
35
+		$this->validate($request, [
36
+			'permission_ids' => 'required|exists:permissions,id', 
37
+			'group_id'       => 'required|array|exists:groups,id'
38
+			]);
39 39
 
40
-        return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200);
41
-    }
40
+		return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200);
41
+	}
42 42
 
43
-     /**
44
-     *  Return the users in the given group in pages.
45
-     * 
46
-     * @param  integer $groupId
47
-     * @param  integer $perPage
48
-     * @param  string  $sortBy
49
-     * @param  boolean $desc
50
-     * @return \Illuminate\Http\Response
51
-     */
52
-    public function users($groupId, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
53
-    {
54
-        if ($this->model) 
55
-        {
56
-            $relations = $this->relations && $this->relations['users'] ? $this->relations['users'] : [];
57
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->users($groupId, $perPage, $relations, $sortBy, $desc), 200);
58
-        }
59
-    }
43
+	 /**
44
+	  *  Return the users in the given group in pages.
45
+	  * 
46
+	  * @param  integer $groupId
47
+	  * @param  integer $perPage
48
+	  * @param  string  $sortBy
49
+	  * @param  boolean $desc
50
+	  * @return \Illuminate\Http\Response
51
+	  */
52
+	public function users($groupId, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
53
+	{
54
+		if ($this->model) 
55
+		{
56
+			$relations = $this->relations && $this->relations['users'] ? $this->relations['users'] : [];
57
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->users($groupId, $perPage, $relations, $sortBy, $desc), 200);
58
+		}
59
+	}
60 60
 }
Please login to merge, or discard this patch.
src/lang/ar/notifications.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@
 block discarded – undo
2 2
 
3 3
 return [
4 4
     
5
-    /**
6
-     * Here goes your notification messages.
7
-     */
5
+	/**
6
+	 * Here goes your notification messages.
7
+	 */
8 8
 
9 9
 ];
10 10
\ No newline at end of file
Please login to merge, or discard this patch.