Completed
Push — master ( 6ad044...8a4f85 )
by Sherif
03:22
created
src/Modules/Acl/Repositories/UserRepository.php 3 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
         $user        = \Core::users()->find(\Auth::id(), $relations);
29 29
         foreach ($user->groups()->get() as $group)
30 30
         {
31
-            $group->permissions->each(function ($permission) use (&$permissions){
31
+            $group->permissions->each(function($permission) use (&$permissions){
32 32
                 $permissions[$permission->model][$permission->id] = $permission->name;
33 33
             });
34 34
         }
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         $user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52 52
         $permissions = [];
53 53
 
54
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
54
+        $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model){
55 55
             $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
56 56
         });
57 57
         
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function assignGroups($user_id, $group_ids)
83 83
     {
84
-        \DB::transaction(function () use ($user_id, $group_ids) {
84
+        \DB::transaction(function() use ($user_id, $group_ids) {
85 85
             $user = $this->find($user_id);
86 86
             $user->groups()->detach();
87 87
             $user->groups()->attach($group_ids);
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
      */
249 249
     public function resetPassword($credentials)
250 250
     {
251
-        $response = \Password::reset($credentials, function ($user, $password) {
251
+        $response = \Password::reset($credentials, function($user, $password) {
252 252
             $user->password = $password;
253 253
             $user->save();
254 254
         });
Please login to merge, or discard this patch.
Indentation   +382 added lines, -382 removed lines patch added patch discarded remove patch
@@ -5,394 +5,394 @@
 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\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\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($groups, $user = false)
69
-    {
70
-        $user = $user ?: $this->find(\Auth::id());
71
-        return $user->groups->whereIn('name', $groups)->count() ? true : false;
72
-    }
73
-
74
-    /**
75
-     * Assign the given group ids to the given user.
76
-     * 
77
-     * @param  integer $user_id    
78
-     * @param  array   $group_ids
79
-     * @return object
80
-     */
81
-    public function assignGroups($user_id, $group_ids)
82
-    {
83
-        \DB::transaction(function () use ($user_id, $group_ids) {
84
-            $user = $this->find($user_id);
85
-            $user->groups()->detach();
86
-            $user->groups()->attach($group_ids);
87
-        });
88
-
89
-        return $this->find($user_id);
90
-    }
91
-
92
-
93
-    /**
94
-     * Handle a login request to the application.
95
-     * 
96
-     * @param  array   $credentials    
97
-     * @param  boolean $adminLogin
98
-     * @return object
99
-     */
100
-    public function login($credentials, $adminLogin = false)
101
-    {
102
-        if ( ! $user = $this->first(['email' => $credentials['email']])) 
103
-        {
104
-            \ErrorHandler::loginFailed();
105
-        }
106
-        else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
107
-        {
108
-            \ErrorHandler::loginFailed();
109
-        }
110
-        else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
111
-        {
112
-            \ErrorHandler::loginFailed();
113
-        }
114
-        else if ($user->blocked)
115
-        {
116
-            \ErrorHandler::userIsBlocked();
117
-        }
118
-        else if ( ! config('disable_confirm_email') && ! $user->confirmed)
119
-        {
120
-            \ErrorHandler::emailNotConfirmed();
121
-        }
122
-
123
-        return $user;
124
-    }
125
-
126
-    /**
127
-     * Handle a social login request of the none admin to the application.
128
-     * 
129
-     * @param  array   $credentials
130
-     * @return array
131
-     */
132
-    public function loginSocial($credentials)
133
-    {
134
-        $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
135
-        $user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
136
-
137
-        if ( ! $user->email)
138
-        {
139
-            \ErrorHandler::noSocialEmail();
140
-        }
141
-
142
-        if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
143
-        {
144
-            $data = ['email' => $user->email, 'password' => ''];
145
-            return $this->register($data);
146
-        }
147
-        else
148
-        {
149
-            if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150
-            {
151
-                \ErrorHandler::userAlreadyRegistered();
152
-            }
153
-
154
-            $loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
155
-            return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0);
156
-        }
157
-    }
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($groups, $user = false)
69
+	{
70
+		$user = $user ?: $this->find(\Auth::id());
71
+		return $user->groups->whereIn('name', $groups)->count() ? true : false;
72
+	}
73
+
74
+	/**
75
+	 * Assign the given group ids to the given user.
76
+	 * 
77
+	 * @param  integer $user_id    
78
+	 * @param  array   $group_ids
79
+	 * @return object
80
+	 */
81
+	public function assignGroups($user_id, $group_ids)
82
+	{
83
+		\DB::transaction(function () use ($user_id, $group_ids) {
84
+			$user = $this->find($user_id);
85
+			$user->groups()->detach();
86
+			$user->groups()->attach($group_ids);
87
+		});
88
+
89
+		return $this->find($user_id);
90
+	}
91
+
92
+
93
+	/**
94
+	 * Handle a login request to the application.
95
+	 * 
96
+	 * @param  array   $credentials    
97
+	 * @param  boolean $adminLogin
98
+	 * @return object
99
+	 */
100
+	public function login($credentials, $adminLogin = false)
101
+	{
102
+		if ( ! $user = $this->first(['email' => $credentials['email']])) 
103
+		{
104
+			\ErrorHandler::loginFailed();
105
+		}
106
+		else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
107
+		{
108
+			\ErrorHandler::loginFailed();
109
+		}
110
+		else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
111
+		{
112
+			\ErrorHandler::loginFailed();
113
+		}
114
+		else if ($user->blocked)
115
+		{
116
+			\ErrorHandler::userIsBlocked();
117
+		}
118
+		else if ( ! config('disable_confirm_email') && ! $user->confirmed)
119
+		{
120
+			\ErrorHandler::emailNotConfirmed();
121
+		}
122
+
123
+		return $user;
124
+	}
125
+
126
+	/**
127
+	 * Handle a social login request of the none admin to the application.
128
+	 * 
129
+	 * @param  array   $credentials
130
+	 * @return array
131
+	 */
132
+	public function loginSocial($credentials)
133
+	{
134
+		$access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
135
+		$user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
136
+
137
+		if ( ! $user->email)
138
+		{
139
+			\ErrorHandler::noSocialEmail();
140
+		}
141
+
142
+		if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
143
+		{
144
+			$data = ['email' => $user->email, 'password' => ''];
145
+			return $this->register($data);
146
+		}
147
+		else
148
+		{
149
+			if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150
+			{
151
+				\ErrorHandler::userAlreadyRegistered();
152
+			}
153
+
154
+			$loginProxy = \App::make('App\Modules\Acl\Proxy\LoginProxy');
155
+			return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0);
156
+		}
157
+	}
158 158
     
159
-    /**
160
-     * Handle a registration request.
161
-     * 
162
-     * @param  array $credentials
163
-     * @return array
164
-     */
165
-    public function register($credentials)
166
-    {
167
-        $user = $this->save($credentials);
168
-
169
-        if ( ! config('disable_confirm_email')) 
170
-        {
171
-            $this->sendConfirmationEmail($user->email);
172
-        }
173
-    }
159
+	/**
160
+	 * Handle a registration request.
161
+	 * 
162
+	 * @param  array $credentials
163
+	 * @return array
164
+	 */
165
+	public function register($credentials)
166
+	{
167
+		$user = $this->save($credentials);
168
+
169
+		if ( ! config('disable_confirm_email')) 
170
+		{
171
+			$this->sendConfirmationEmail($user->email);
172
+		}
173
+	}
174 174
     
175
-    /**
176
-     * Block the user.
177
-     *
178
-     * @param  integer $user_id
179
-     * @return object
180
-     */
181
-    public function block($user_id)
182
-    {
183
-        if ( ! $user = $this->find($user_id)) 
184
-        {
185
-            \ErrorHandler::notFound('user');
186
-        }
187
-        if ( ! $this->hasGroup(['Admin']))
188
-        {
189
-            \ErrorHandler::noPermissions();
190
-        }
191
-        else if (\Auth::id() == $user_id)
192
-        {
193
-            \ErrorHandler::noPermissions();
194
-        }
195
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196
-        {
197
-            \ErrorHandler::noPermissions();
198
-        }
199
-
200
-        $user->blocked = 1;
201
-        $user->save();
175
+	/**
176
+	 * Block the user.
177
+	 *
178
+	 * @param  integer $user_id
179
+	 * @return object
180
+	 */
181
+	public function block($user_id)
182
+	{
183
+		if ( ! $user = $this->find($user_id)) 
184
+		{
185
+			\ErrorHandler::notFound('user');
186
+		}
187
+		if ( ! $this->hasGroup(['Admin']))
188
+		{
189
+			\ErrorHandler::noPermissions();
190
+		}
191
+		else if (\Auth::id() == $user_id)
192
+		{
193
+			\ErrorHandler::noPermissions();
194
+		}
195
+		else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196
+		{
197
+			\ErrorHandler::noPermissions();
198
+		}
199
+
200
+		$user->blocked = 1;
201
+		$user->save();
202 202
         
203
-        return $user;
204
-    }
205
-
206
-    /**
207
-     * Unblock the user.
208
-     *
209
-     * @param  integer $user_id
210
-     * @return object
211
-     */
212
-    public function unblock($user_id)
213
-    {
214
-        if ( ! $this->hasGroup(['Admin']))
215
-        {
216
-            \ErrorHandler::noPermissions();
217
-        }
218
-
219
-        $user          = $this->find($user_id);
220
-        $user->blocked = 0;
221
-        $user->save();
222
-
223
-        return $user;
224
-    }
225
-
226
-    /**
227
-     * Send a reset link to the given user.
228
-     *
229
-     * @param  string  $email
230
-     * @return void
231
-     */
232
-    public function sendReset($email)
233
-    {
234
-        if ( ! $user = $this->model->where('email', $email)->first())
235
-        {
236
-            \ErrorHandler::notFound('email');
237
-        }
238
-
239
-        $token = \Password::getRepository()->create($user);
240
-        \Core::notifications()->notify($user, 'ResetPassword', $token);
241
-    }
242
-
243
-    /**
244
-     * Reset the given user's password.
245
-     *
246
-     * @param  array  $credentials
247
-     * @return array
248
-     */
249
-    public function resetPassword($credentials)
250
-    {
251
-        $response = \Password::reset($credentials, function ($user, $password) {
252
-            $user->password = $password;
253
-            $user->save();
254
-        });
255
-
256
-        switch ($response) {
257
-            case \Password::PASSWORD_RESET:
258
-                return 'success';
203
+		return $user;
204
+	}
205
+
206
+	/**
207
+	 * Unblock the user.
208
+	 *
209
+	 * @param  integer $user_id
210
+	 * @return object
211
+	 */
212
+	public function unblock($user_id)
213
+	{
214
+		if ( ! $this->hasGroup(['Admin']))
215
+		{
216
+			\ErrorHandler::noPermissions();
217
+		}
218
+
219
+		$user          = $this->find($user_id);
220
+		$user->blocked = 0;
221
+		$user->save();
222
+
223
+		return $user;
224
+	}
225
+
226
+	/**
227
+	 * Send a reset link to the given user.
228
+	 *
229
+	 * @param  string  $email
230
+	 * @return void
231
+	 */
232
+	public function sendReset($email)
233
+	{
234
+		if ( ! $user = $this->model->where('email', $email)->first())
235
+		{
236
+			\ErrorHandler::notFound('email');
237
+		}
238
+
239
+		$token = \Password::getRepository()->create($user);
240
+		\Core::notifications()->notify($user, 'ResetPassword', $token);
241
+	}
242
+
243
+	/**
244
+	 * Reset the given user's password.
245
+	 *
246
+	 * @param  array  $credentials
247
+	 * @return array
248
+	 */
249
+	public function resetPassword($credentials)
250
+	{
251
+		$response = \Password::reset($credentials, function ($user, $password) {
252
+			$user->password = $password;
253
+			$user->save();
254
+		});
255
+
256
+		switch ($response) {
257
+			case \Password::PASSWORD_RESET:
258
+				return 'success';
259 259
                 
260
-            case \Password::INVALID_TOKEN:
261
-                \ErrorHandler::invalidResetToken('token');
262
-
263
-            case \Password::INVALID_PASSWORD:
264
-                \ErrorHandler::invalidResetPassword('email');
265
-
266
-            case \Password::INVALID_USER:
267
-                \ErrorHandler::notFound('user');
268
-
269
-            default:
270
-                \ErrorHandler::generalError();
271
-        }
272
-    }
273
-
274
-    /**
275
-     * Change the logged in user password.
276
-     *
277
-     * @param  array  $credentials
278
-     * @return void
279
-     */
280
-    public function changePassword($credentials)
281
-    {
282
-        $user = \Auth::user();
283
-        if ( ! \Hash::check($credentials['old_password'], $user->password)) 
284
-        {
285
-            \ErrorHandler::invalidOldPassword();
286
-        }
287
-
288
-        $user->password = $credentials['password'];
289
-        $user->save();
290
-    }
291
-
292
-    /**
293
-     * Confirm email using the confirmation code.
294
-     *
295
-     * @param  string $confirmationCode
296
-     * @return void
297
-     */
298
-    public function confirmEmail($confirmationCode)
299
-    {
300
-        $user                    = $this->first(['confirmation_code' => $confirmationCode]);
301
-        $user->confirmed         = 1;
302
-        $user->confirmation_code = null;
303
-        $user->save();
304
-    }
305
-
306
-    /**
307
-     * Send the confirmation mail.
308
-     *
309
-     * @param  string $email
310
-     * @return void
311
-     */
312
-    public function sendConfirmationEmail($email)
313
-    {
314
-        $user = $this->first(['email' => $email]);
315
-        if ($user->confirmed) 
316
-        {
317
-            \ErrorHandler::emailAlreadyConfirmed();
318
-        }
319
-
320
-        $user->confirmed         = 0;
321
-        $user->confirmation_code = sha1(microtime());
322
-        $user->save();
323
-        \Core::notifications()->notify($user, 'ConfirmEmail');
324
-    }
325
-
326
-    /**
327
-     * Paginate all users in the given group based on the given conditions.
328
-     * 
329
-     * @param  string  $groupName
330
-     * @param  array   $relations
331
-     * @param  integer $perPage
332
-     * @param  string  $sortBy
333
-     * @param  boolean $desc
334
-     * @return \Illuminate\Http\Response
335
-     */
336
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
337
-    {   
338
-        unset($conditions['page']);
339
-        $conditions = $this->constructConditions($conditions, $this->model);
340
-        $sort       = $desc ? 'desc' : 'asc';
341
-        $model      = call_user_func_array("{$this->getModel()}::with", array($relations));
342
-
343
-        $model->whereHas('groups', function($q) use ($groupName){
344
-            $q->where('name', $groupName);
345
-        });
260
+			case \Password::INVALID_TOKEN:
261
+				\ErrorHandler::invalidResetToken('token');
262
+
263
+			case \Password::INVALID_PASSWORD:
264
+				\ErrorHandler::invalidResetPassword('email');
265
+
266
+			case \Password::INVALID_USER:
267
+				\ErrorHandler::notFound('user');
268
+
269
+			default:
270
+				\ErrorHandler::generalError();
271
+		}
272
+	}
273
+
274
+	/**
275
+	 * Change the logged in user password.
276
+	 *
277
+	 * @param  array  $credentials
278
+	 * @return void
279
+	 */
280
+	public function changePassword($credentials)
281
+	{
282
+		$user = \Auth::user();
283
+		if ( ! \Hash::check($credentials['old_password'], $user->password)) 
284
+		{
285
+			\ErrorHandler::invalidOldPassword();
286
+		}
287
+
288
+		$user->password = $credentials['password'];
289
+		$user->save();
290
+	}
291
+
292
+	/**
293
+	 * Confirm email using the confirmation code.
294
+	 *
295
+	 * @param  string $confirmationCode
296
+	 * @return void
297
+	 */
298
+	public function confirmEmail($confirmationCode)
299
+	{
300
+		$user                    = $this->first(['confirmation_code' => $confirmationCode]);
301
+		$user->confirmed         = 1;
302
+		$user->confirmation_code = null;
303
+		$user->save();
304
+	}
305
+
306
+	/**
307
+	 * Send the confirmation mail.
308
+	 *
309
+	 * @param  string $email
310
+	 * @return void
311
+	 */
312
+	public function sendConfirmationEmail($email)
313
+	{
314
+		$user = $this->first(['email' => $email]);
315
+		if ($user->confirmed) 
316
+		{
317
+			\ErrorHandler::emailAlreadyConfirmed();
318
+		}
319
+
320
+		$user->confirmed         = 0;
321
+		$user->confirmation_code = sha1(microtime());
322
+		$user->save();
323
+		\Core::notifications()->notify($user, 'ConfirmEmail');
324
+	}
325
+
326
+	/**
327
+	 * Paginate all users in the given group based on the given conditions.
328
+	 * 
329
+	 * @param  string  $groupName
330
+	 * @param  array   $relations
331
+	 * @param  integer $perPage
332
+	 * @param  string  $sortBy
333
+	 * @param  boolean $desc
334
+	 * @return \Illuminate\Http\Response
335
+	 */
336
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
337
+	{   
338
+		unset($conditions['page']);
339
+		$conditions = $this->constructConditions($conditions, $this->model);
340
+		$sort       = $desc ? 'desc' : 'asc';
341
+		$model      = call_user_func_array("{$this->getModel()}::with", array($relations));
342
+
343
+		$model->whereHas('groups', function($q) use ($groupName){
344
+			$q->where('name', $groupName);
345
+		});
346 346
 
347 347
         
348
-        if (count($conditions['conditionValues']))
349
-        {
350
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
351
-        }
352
-
353
-        if ($perPage) 
354
-        {
355
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
356
-        }
357
-
358
-        return $model->orderBy($sortBy, $sort)->get();
359
-    }
360
-
361
-    /**
362
-     * Save the given data to the logged in user.
363
-     *
364
-     * @param  array $credentials
365
-     * @return void
366
-     */
367
-    public function saveProfile($data) 
368
-    {
369
-        if (array_key_exists('profile_picture', $data)) 
370
-        {
371
-            $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
372
-        }
348
+		if (count($conditions['conditionValues']))
349
+		{
350
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
351
+		}
352
+
353
+		if ($perPage) 
354
+		{
355
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
356
+		}
357
+
358
+		return $model->orderBy($sortBy, $sort)->get();
359
+	}
360
+
361
+	/**
362
+	 * Save the given data to the logged in user.
363
+	 *
364
+	 * @param  array $credentials
365
+	 * @return void
366
+	 */
367
+	public function saveProfile($data) 
368
+	{
369
+		if (array_key_exists('profile_picture', $data)) 
370
+		{
371
+			$data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
372
+		}
373 373
         
374
-        $data['id'] = \Auth::id();
375
-        $this->save($data);
376
-    }
377
-
378
-    /**
379
-     * Ensure access token hasn't expired or revoked.
380
-     * 
381
-     * @param  string $accessToken
382
-     * @return boolean
383
-     */
384
-    public function accessTokenExpiredOrRevoked($accessToken)
385
-    {
386
-
387
-        $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
388
-        $data = new ValidationData();
389
-        $data->setCurrentTime(time());
390
-
391
-        if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
392
-        {
393
-            return true;
394
-        }
395
-
396
-        return false;
397
-    }
374
+		$data['id'] = \Auth::id();
375
+		$this->save($data);
376
+	}
377
+
378
+	/**
379
+	 * Ensure access token hasn't expired or revoked.
380
+	 * 
381
+	 * @param  string $accessToken
382
+	 * @return boolean
383
+	 */
384
+	public function accessTokenExpiredOrRevoked($accessToken)
385
+	{
386
+
387
+		$accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
388
+		$data = new ValidationData();
389
+		$data->setCurrentTime(time());
390
+
391
+		if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
392
+		{
393
+			return true;
394
+		}
395
+
396
+		return false;
397
+	}
398 398
 }
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -102,20 +102,16 @@  discard block
 block discarded – undo
102 102
         if ( ! $user = $this->first(['email' => $credentials['email']])) 
103 103
         {
104 104
             \ErrorHandler::loginFailed();
105
-        }
106
-        else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
105
+        } else if ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) 
107 106
         {
108 107
             \ErrorHandler::loginFailed();
109
-        }
110
-        else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
108
+        } else if ( ! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) 
111 109
         {
112 110
             \ErrorHandler::loginFailed();
113
-        }
114
-        else if ($user->blocked)
111
+        } else if ($user->blocked)
115 112
         {
116 113
             \ErrorHandler::userIsBlocked();
117
-        }
118
-        else if ( ! config('disable_confirm_email') && ! $user->confirmed)
114
+        } else if ( ! config('disable_confirm_email') && ! $user->confirmed)
119 115
         {
120 116
             \ErrorHandler::emailNotConfirmed();
121 117
         }
@@ -143,8 +139,7 @@  discard block
 block discarded – undo
143 139
         {
144 140
             $data = ['email' => $user->email, 'password' => ''];
145 141
             return $this->register($data);
146
-        }
147
-        else
142
+        } else
148 143
         {
149 144
             if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150 145
             {
@@ -187,12 +182,10 @@  discard block
 block discarded – undo
187 182
         if ( ! $this->hasGroup(['Admin']))
188 183
         {
189 184
             \ErrorHandler::noPermissions();
190
-        }
191
-        else if (\Auth::id() == $user_id)
185
+        } else if (\Auth::id() == $user_id)
192 186
         {
193 187
             \ErrorHandler::noPermissions();
194
-        }
195
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
188
+        } else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196 189
         {
197 190
             \ErrorHandler::noPermissions();
198 191
         }
Please login to merge, or discard this patch.
config/skeleton.php 1 patch
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 return [
4 4
 
5
-    /*
5
+	/*
6 6
     |--------------------------------------------------------------------------
7 7
     | Disable Confirm Email
8 8
     |--------------------------------------------------------------------------
@@ -11,9 +11,9 @@  discard block
 block discarded – undo
11 11
     |
12 12
     */
13 13
 
14
-    'disable_confirm_email' => env('DISABLE_CONFIRM_EMAIL', false),
14
+	'disable_confirm_email' => env('DISABLE_CONFIRM_EMAIL', false),
15 15
 
16
-    /*
16
+	/*
17 17
     |--------------------------------------------------------------------------
18 18
     | Confirm Email URL
19 19
     |--------------------------------------------------------------------------
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
     |
23 23
     */
24 24
    
25
-    'confrim_email_url' => env('CONFIRM_EMAIL_URL'),
25
+	'confrim_email_url' => env('CONFIRM_EMAIL_URL'),
26 26
 
27
-    /*
27
+	/*
28 28
     |--------------------------------------------------------------------------
29 29
     | Reset Password URL
30 30
     |--------------------------------------------------------------------------
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
     |
34 34
     */
35 35
    
36
-    'reset_password_url' => env('RESET_PASSWORD_URL'),
36
+	'reset_password_url' => env('RESET_PASSWORD_URL'),
37 37
 
38
-    /*
38
+	/*
39 39
     |--------------------------------------------------------------------------
40 40
     | Passport Client Id
41 41
     |--------------------------------------------------------------------------
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
     |
45 45
     */
46 46
    
47
-    'passport_client_id' => env('PASSWORD_CLIENT_ID'),
47
+	'passport_client_id' => env('PASSWORD_CLIENT_ID'),
48 48
 
49
-    /*
49
+	/*
50 50
     |--------------------------------------------------------------------------
51 51
     | Passport Client Secret
52 52
     |--------------------------------------------------------------------------
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
     |
56 56
     */
57 57
    
58
-    'passport_client_secret' => env('PASSWORD_CLIENT_SECRET'),
58
+	'passport_client_secret' => env('PASSWORD_CLIENT_SECRET'),
59 59
 
60
-    /*
60
+	/*
61 61
     |--------------------------------------------------------------------------
62 62
     | Relations Between Models
63 63
     |--------------------------------------------------------------------------
@@ -66,88 +66,88 @@  discard block
 block discarded – undo
66 66
     |
67 67
     */
68 68
     
69
-    'relations' => [
70
-        'users' => [
71
-            'list'       => [],
72
-            'find'       => [],
73
-            'findby'     => [],
74
-            'paginate'   => [],
75
-            'paginateby' => [],
76
-            'first'      => [],
77
-            'search'     => [],
78
-            'account'    => [],
79
-            'group'      => [],
80
-            'deleted'    => [],
81
-        ],
82
-        'permissions' => [
83
-            'list'       => [],
84
-            'find'       => [],
85
-            'findby'     => [],
86
-            'paginate'   => [],
87
-            'paginateby' => [],
88
-            'first'      => [],
89
-            'search'     => [],
90
-            'deleted'    => [],
91
-        ],
92
-        'groups' => [
93
-            'list'       => [],
94
-            'find'       => [],
95
-            'findby'     => [],
96
-            'paginate'   => [],
97
-            'paginateby' => [],
98
-            'first'      => [],
99
-            'search'     => [],
100
-            'deleted'    => [],
101
-        ],
102
-        'oauthClients' => [
103
-            'list'       => [],
104
-            'find'       => [],
105
-            'findby'     => [],
106
-            'paginate'   => [],
107
-            'paginateby' => [],
108
-            'first'      => [],
109
-            'search'     => [],
110
-            'account'    => [],
111
-            'group'      => [],
112
-            'deleted'    => [],
113
-        ],
114
-        'notifications' => [
115
-            'list'   => [],
116
-            'unread' => [],
117
-        ],
118
-        'pushNotificationDevices' => [
119
-            'list'       => [],
120
-            'find'       => [],
121
-            'findby'     => [],
122
-            'paginate'   => [],
123
-            'paginateby' => [],
124
-            'first'      => [],
125
-            'search'     => [],
126
-            'deleted'    => [],
127
-        ],
128
-        'reports' => [
129
-            'list'       => [],
130
-            'find'       => [],
131
-            'findby'     => [],
132
-            'paginate'   => [],
133
-            'paginateby' => [],
134
-            'first'      => [],
135
-            'search'     => [],
136
-            'deleted'    => [],
137
-        ],
138
-        'settings' => [
139
-            'list'       => [],
140
-            'find'       => [],
141
-            'findby'     => [],
142
-            'paginate'   => [],
143
-            'paginateby' => [],
144
-            'first'      => [],
145
-            'search'     => [],
146
-            'deleted'    => [],
147
-        ]
148
-    ],
69
+	'relations' => [
70
+		'users' => [
71
+			'list'       => [],
72
+			'find'       => [],
73
+			'findby'     => [],
74
+			'paginate'   => [],
75
+			'paginateby' => [],
76
+			'first'      => [],
77
+			'search'     => [],
78
+			'account'    => [],
79
+			'group'      => [],
80
+			'deleted'    => [],
81
+		],
82
+		'permissions' => [
83
+			'list'       => [],
84
+			'find'       => [],
85
+			'findby'     => [],
86
+			'paginate'   => [],
87
+			'paginateby' => [],
88
+			'first'      => [],
89
+			'search'     => [],
90
+			'deleted'    => [],
91
+		],
92
+		'groups' => [
93
+			'list'       => [],
94
+			'find'       => [],
95
+			'findby'     => [],
96
+			'paginate'   => [],
97
+			'paginateby' => [],
98
+			'first'      => [],
99
+			'search'     => [],
100
+			'deleted'    => [],
101
+		],
102
+		'oauthClients' => [
103
+			'list'       => [],
104
+			'find'       => [],
105
+			'findby'     => [],
106
+			'paginate'   => [],
107
+			'paginateby' => [],
108
+			'first'      => [],
109
+			'search'     => [],
110
+			'account'    => [],
111
+			'group'      => [],
112
+			'deleted'    => [],
113
+		],
114
+		'notifications' => [
115
+			'list'   => [],
116
+			'unread' => [],
117
+		],
118
+		'pushNotificationDevices' => [
119
+			'list'       => [],
120
+			'find'       => [],
121
+			'findby'     => [],
122
+			'paginate'   => [],
123
+			'paginateby' => [],
124
+			'first'      => [],
125
+			'search'     => [],
126
+			'deleted'    => [],
127
+		],
128
+		'reports' => [
129
+			'list'       => [],
130
+			'find'       => [],
131
+			'findby'     => [],
132
+			'paginate'   => [],
133
+			'paginateby' => [],
134
+			'first'      => [],
135
+			'search'     => [],
136
+			'deleted'    => [],
137
+		],
138
+		'settings' => [
139
+			'list'       => [],
140
+			'find'       => [],
141
+			'findby'     => [],
142
+			'paginate'   => [],
143
+			'paginateby' => [],
144
+			'first'      => [],
145
+			'search'     => [],
146
+			'deleted'    => [],
147
+		]
148
+	],
149 149
 
150
-    /*
150
+	/*
151 151
     |--------------------------------------------------------------------------
152 152
     | Cache Configurations
153 153
     |--------------------------------------------------------------------------
@@ -156,46 +156,46 @@  discard block
 block discarded – undo
156 156
     |
157 157
     */
158 158
 
159
-    'cache_config' => [
160
-        'oauthClients' => [
161
-            'cache' => [
162
-                'all',
163
-                'find',
164
-                'findBy',
165
-                'paginate',
166
-                'paginateBy',
167
-                'first',
168
-                'search',
169
-                'deleted'
170
-            ],
171
-            'clear' => [
172
-                'update'           => ['oauthClients', 'users', 'groups'],
173
-                'save'             => ['oauthClients', 'users', 'groups'],
174
-                'delete'           => ['oauthClients', 'users', 'groups'],
175
-                'restore'          => ['oauthClients', 'users', 'groups'],
176
-                'revoke'           => ['oauthClients', 'users', 'groups'],
177
-                'ubRevoke'         => ['oauthClients', 'users', 'groups'],
178
-                'regenerateSecret' => ['oauthClients', 'users', 'groups'],
179
-            ],
180
-        ],
181
-        'settings' => [
182
-            'cache' => [
183
-                'all',
184
-                'find',
185
-                'findBy',
186
-                'paginate',
187
-                'paginateBy',
188
-                'first',
189
-                'search',
190
-                'deleted'
191
-            ],
192
-            'clear' => [
193
-                'update'   => ['settings'],
194
-                'save'     => ['settings'],
195
-                'delete'   => ['settings'],
196
-                'restore'  => ['settings'],
197
-                'saveMany' => ['settings'],
198
-            ]
199
-        ]
200
-    ]
159
+	'cache_config' => [
160
+		'oauthClients' => [
161
+			'cache' => [
162
+				'all',
163
+				'find',
164
+				'findBy',
165
+				'paginate',
166
+				'paginateBy',
167
+				'first',
168
+				'search',
169
+				'deleted'
170
+			],
171
+			'clear' => [
172
+				'update'           => ['oauthClients', 'users', 'groups'],
173
+				'save'             => ['oauthClients', 'users', 'groups'],
174
+				'delete'           => ['oauthClients', 'users', 'groups'],
175
+				'restore'          => ['oauthClients', 'users', 'groups'],
176
+				'revoke'           => ['oauthClients', 'users', 'groups'],
177
+				'ubRevoke'         => ['oauthClients', 'users', 'groups'],
178
+				'regenerateSecret' => ['oauthClients', 'users', 'groups'],
179
+			],
180
+		],
181
+		'settings' => [
182
+			'cache' => [
183
+				'all',
184
+				'find',
185
+				'findBy',
186
+				'paginate',
187
+				'paginateBy',
188
+				'first',
189
+				'search',
190
+				'deleted'
191
+			],
192
+			'clear' => [
193
+				'update'   => ['settings'],
194
+				'save'     => ['settings'],
195
+				'delete'   => ['settings'],
196
+				'restore'  => ['settings'],
197
+				'saveMany' => ['settings'],
198
+			]
199
+		]
200
+	]
201 201
 ];
Please login to merge, or discard this patch.
src/Modules/Core/Utl/CoreConfig.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,9 +2,9 @@  discard block
 block discarded – undo
2 2
 
3 3
 class CoreConfig
4 4
 {
5
-    public function getConfig()
6
-    {
7
-        return [
5
+	public function getConfig()
6
+	{
7
+		return [
8 8
 			/**
9 9
 			 * Specify what relations should be used for every model.
10 10
 			 */
@@ -14,5 +14,5 @@  discard block
 block discarded – undo
14 14
 			 */
15 15
 			'cacheConfig' =>  config('cache_config'),
16 16
 		];
17
-    }
17
+	}
18 18
 }
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/Notifications/Notifications/ResetPassword.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -10,43 +10,43 @@
 block discarded – undo
10 10
 
11 11
 class ResetPassword extends Notification implements ShouldQueue
12 12
 {
13
-    use Queueable;
13
+	use Queueable;
14 14
 
15
-    protected $token;
15
+	protected $token;
16 16
 
17
-    /**
18
-     * Create a new notification instance.
19
-     *
20
-     * @return void
21
-     */
22
-    public function __construct($token)
23
-    {
24
-        $this->token = $token;
25
-    }
17
+	/**
18
+	 * Create a new notification instance.
19
+	 *
20
+	 * @return void
21
+	 */
22
+	public function __construct($token)
23
+	{
24
+		$this->token = $token;
25
+	}
26 26
 
27
-    /**
28
-     * Get the notification's delivery channels.
29
-     *
30
-     * @param  mixed  $notifiable
31
-     * @return array
32
-     */
33
-    public function via($notifiable)
34
-    {
35
-        return ['mail'];
36
-    }
27
+	/**
28
+	 * Get the notification's delivery channels.
29
+	 *
30
+	 * @param  mixed  $notifiable
31
+	 * @return array
32
+	 */
33
+	public function via($notifiable)
34
+	{
35
+		return ['mail'];
36
+	}
37 37
 
38
-    /**
39
-     * Get the mail representation of the notification.
40
-     *
41
-     * @param  mixed  $notifiable
42
-     * @return \Illuminate\Notifications\Messages\MailMessage
43
-     */
44
-    public function toMail($notifiable)
45
-    {
46
-        return (new MailMessage)
47
-            ->subject('Reset passowrd')
48
-            ->line('Reset passowrd')
49
-            ->line('To reset your password click on the button below')
50
-            ->action('Reset password', config('reset_password_url') . '/' . $this->token);
51
-    }
38
+	/**
39
+	 * Get the mail representation of the notification.
40
+	 *
41
+	 * @param  mixed  $notifiable
42
+	 * @return \Illuminate\Notifications\Messages\MailMessage
43
+	 */
44
+	public function toMail($notifiable)
45
+	{
46
+		return (new MailMessage)
47
+			->subject('Reset passowrd')
48
+			->line('Reset passowrd')
49
+			->line('To reset your password click on the button below')
50
+			->action('Reset password', config('reset_password_url') . '/' . $this->token);
51
+	}
52 52
 }
53 53
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,6 +47,6 @@
 block discarded – undo
47 47
             ->subject('Reset passowrd')
48 48
             ->line('Reset passowrd')
49 49
             ->line('To reset your password click on the button below')
50
-            ->action('Reset password', config('reset_password_url') . '/' . $this->token);
50
+            ->action('Reset password', config('reset_password_url').'/'.$this->token);
51 51
     }
52 52
 }
53 53
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/Notifications/Notifications/ConfirmEmail.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -10,41 +10,41 @@
 block discarded – undo
10 10
 
11 11
 class ConfirmEmail extends Notification implements ShouldQueue
12 12
 {
13
-    use Queueable;
13
+	use Queueable;
14 14
 
15
-    /**
16
-     * Create a new notification instance.
17
-     *
18
-     * @return void
19
-     */
20
-    public function __construct()
21
-    {
22
-        //
23
-    }
15
+	/**
16
+	 * Create a new notification instance.
17
+	 *
18
+	 * @return void
19
+	 */
20
+	public function __construct()
21
+	{
22
+		//
23
+	}
24 24
 
25
-    /**
26
-     * Get the notification's delivery channels.
27
-     *
28
-     * @param  mixed  $notifiable
29
-     * @return array
30
-     */
31
-    public function via($notifiable)
32
-    {
33
-        return ['mail'];
34
-    }
25
+	/**
26
+	 * Get the notification's delivery channels.
27
+	 *
28
+	 * @param  mixed  $notifiable
29
+	 * @return array
30
+	 */
31
+	public function via($notifiable)
32
+	{
33
+		return ['mail'];
34
+	}
35 35
 
36
-    /**
37
-     * Get the mail representation of the notification.
38
-     *
39
-     * @param  mixed  $notifiable
40
-     * @return \Illuminate\Notifications\Messages\MailMessage
41
-     */
42
-    public function toMail($notifiable)
43
-    {
44
-        return (new MailMessage)
45
-            ->subject('Email verification')
46
-            ->line('Email verification')
47
-            ->line('To validate your email click on the button below')
48
-            ->action('Verify your email', config('confrim_email_url') . '/' . $notifiable->confirmation_code));
49
-    }
36
+	/**
37
+	 * Get the mail representation of the notification.
38
+	 *
39
+	 * @param  mixed  $notifiable
40
+	 * @return \Illuminate\Notifications\Messages\MailMessage
41
+	 */
42
+	public function toMail($notifiable)
43
+	{
44
+		return (new MailMessage)
45
+			->subject('Email verification')
46
+			->line('Email verification')
47
+			->line('To validate your email click on the button below')
48
+			->action('Verify your email', config('confrim_email_url') . '/' . $notifiable->confirmation_code));
49
+	}
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,6 +45,6 @@
 block discarded – undo
45 45
             ->subject('Email verification')
46 46
             ->line('Email verification')
47 47
             ->line('To validate your email click on the button below')
48
-            ->action('Verify your email', config('confrim_email_url') . '/' . $notifiable->confirmation_code));
48
+            ->action('Verify your email', config('confrim_email_url').'/'.$notifiable->confirmation_code));
49 49
     }
50 50
 }
51 51
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/Acl/Proxy/LoginProxy.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -5,105 +5,105 @@
 block discarded – undo
5 5
 
6 6
 class LoginProxy
7 7
 {
8
-    private $apiConsumer;
9
-
10
-    private $auth;
11
-
12
-    private $db;
13
-
14
-    private $request;
15
-
16
-    private $userRepository;
17
-
18
-    public function __construct(Application $app) 
19
-    {
20
-
21
-        $this->userRepository = $app->make('App\Modules\Acl\Repositories\UserRepository');
22
-        $this->apiConsumer    = $app->make('apiconsumer');
23
-        $this->auth           = $app->make('auth');
24
-        $this->db             = $app->make('db');
25
-        $this->request        = $app->make('request');
26
-    }
27
-
28
-    /**
29
-     * Attempt to create an access token using user credentials.
30
-     *
31
-     * @param  array   $credentials
32
-     * @param  boolean $adminLogin
33
-     * @return array
34
-     */
35
-    public function login($credentials, $adminLogin = false)
36
-    {
37
-        $this->userRepository->login($credentials, $adminLogin);
38
-
39
-        return $this->proxy('password', [
40
-            'username' => $credentials['email'],
41
-            'password' => $credentials['password']
42
-        ]);
43
-    }
44
-
45
-    /**
46
-     * Attempt to refresh the access token useing the given refresh token.
47
-     * 
48
-     * @param  string $refreshToken
49
-     * @return array
50
-     */
51
-    public function refreshtoken($refreshToken)
52
-    {
53
-        return $this->proxy('refresh_token', [
54
-            'refresh_token' => $refreshToken
55
-        ]);
56
-    }
57
-
58
-    /**
59
-     * Proxy a request to the OAuth server.
60
-     *
61
-     * @param string $grantType what type of grant type should be proxied
62
-     * @param array 
63
-     */
64
-    public function proxy($grantType, array $data = [])
65
-    {
66
-        $data = array_merge($data, [
67
-            'client_id'     => config('passport_client_id'),
68
-            'client_secret' => config('passport_client_secret'),
69
-            'grant_type'    => $grantType
70
-        ]);
71
-
72
-        $response = $this->apiConsumer->post('/oauth/token', $data);
73
-
74
-        if ( ! $response->isSuccessful()) 
75
-        {
76
-            if ($grantType == 'refresh_token') 
77
-            {
78
-                \ErrorHandler::invalidRefreshToken();
79
-            }
80
-
81
-            \ErrorHandler::loginFailed();
82
-        }
83
-
84
-        $data = json_decode($response->getContent());
85
-
86
-        return [
87
-            'access_token'  => $data->access_token,
88
-            'refresh_token' => $data->refresh_token,
89
-            'expires_in'    => $data->expires_in
90
-        ];
91
-    }
92
-
93
-    /**
94
-     * Logs out the user. We revoke access token and refresh token.
95
-     */
96
-    public function logout()
97
-    {
98
-        $accessToken = $this->auth->user()->token();
99
-
100
-        $this->db
101
-            ->table('oauth_refresh_tokens')
102
-            ->where('access_token_id', $accessToken->id)
103
-            ->update([
104
-                'revoked' => true
105
-            ]);
106
-
107
-        $accessToken->revoke();
108
-    }
8
+	private $apiConsumer;
9
+
10
+	private $auth;
11
+
12
+	private $db;
13
+
14
+	private $request;
15
+
16
+	private $userRepository;
17
+
18
+	public function __construct(Application $app) 
19
+	{
20
+
21
+		$this->userRepository = $app->make('App\Modules\Acl\Repositories\UserRepository');
22
+		$this->apiConsumer    = $app->make('apiconsumer');
23
+		$this->auth           = $app->make('auth');
24
+		$this->db             = $app->make('db');
25
+		$this->request        = $app->make('request');
26
+	}
27
+
28
+	/**
29
+	 * Attempt to create an access token using user credentials.
30
+	 *
31
+	 * @param  array   $credentials
32
+	 * @param  boolean $adminLogin
33
+	 * @return array
34
+	 */
35
+	public function login($credentials, $adminLogin = false)
36
+	{
37
+		$this->userRepository->login($credentials, $adminLogin);
38
+
39
+		return $this->proxy('password', [
40
+			'username' => $credentials['email'],
41
+			'password' => $credentials['password']
42
+		]);
43
+	}
44
+
45
+	/**
46
+	 * Attempt to refresh the access token useing the given refresh token.
47
+	 * 
48
+	 * @param  string $refreshToken
49
+	 * @return array
50
+	 */
51
+	public function refreshtoken($refreshToken)
52
+	{
53
+		return $this->proxy('refresh_token', [
54
+			'refresh_token' => $refreshToken
55
+		]);
56
+	}
57
+
58
+	/**
59
+	 * Proxy a request to the OAuth server.
60
+	 *
61
+	 * @param string $grantType what type of grant type should be proxied
62
+	 * @param array 
63
+	 */
64
+	public function proxy($grantType, array $data = [])
65
+	{
66
+		$data = array_merge($data, [
67
+			'client_id'     => config('passport_client_id'),
68
+			'client_secret' => config('passport_client_secret'),
69
+			'grant_type'    => $grantType
70
+		]);
71
+
72
+		$response = $this->apiConsumer->post('/oauth/token', $data);
73
+
74
+		if ( ! $response->isSuccessful()) 
75
+		{
76
+			if ($grantType == 'refresh_token') 
77
+			{
78
+				\ErrorHandler::invalidRefreshToken();
79
+			}
80
+
81
+			\ErrorHandler::loginFailed();
82
+		}
83
+
84
+		$data = json_decode($response->getContent());
85
+
86
+		return [
87
+			'access_token'  => $data->access_token,
88
+			'refresh_token' => $data->refresh_token,
89
+			'expires_in'    => $data->expires_in
90
+		];
91
+	}
92
+
93
+	/**
94
+	 * Logs out the user. We revoke access token and refresh token.
95
+	 */
96
+	public function logout()
97
+	{
98
+		$accessToken = $this->auth->user()->token();
99
+
100
+		$this->db
101
+			->table('oauth_refresh_tokens')
102
+			->where('access_token_id', $accessToken->id)
103
+			->update([
104
+				'revoked' => true
105
+			]);
106
+
107
+		$accessToken->revoke();
108
+	}
109 109
 }
110 110
\ No newline at end of file
Please login to merge, or discard this patch.
src/ApiSkeletonServiceProvider.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -6,35 +6,35 @@
 block discarded – undo
6 6
 
7 7
 class ApiSkeletonServiceProvider extends ServiceProvider
8 8
 {
9
-    /**
10
-     * Perform post-registration booting of services.
11
-     *
12
-     * @return void
13
-     */
14
-    public function boot()
15
-    {
16
-        $this->publishes([
17
-            __DIR__.'/../Modules'                            => app_path('Modules'),
18
-            __DIR__.'/../lang'                               => base_path('resources/lang'),
19
-            __DIR__.'/../files/Handler.php'                  => base_path('app/Exceptions/Handler.php'),
20
-            __DIR__.'/../files/auth.php'                     => base_path('config/auth.php'),
21
-            __DIR__.'/../files/AuthServiceProvider.php'      => base_path('app/Providers/AuthServiceProvider.php'),
22
-            __DIR__.'/../files/BroadcastServiceProvider.php' => base_path('app/Providers/BroadcastServiceProvider.php'),
23
-            __DIR__.'/../files/Kernel.php'                   => base_path('app/Console/Kernel.php'),
24
-        ]);
9
+	/**
10
+	 * Perform post-registration booting of services.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function boot()
15
+	{
16
+		$this->publishes([
17
+			__DIR__.'/../Modules'                            => app_path('Modules'),
18
+			__DIR__.'/../lang'                               => base_path('resources/lang'),
19
+			__DIR__.'/../files/Handler.php'                  => base_path('app/Exceptions/Handler.php'),
20
+			__DIR__.'/../files/auth.php'                     => base_path('config/auth.php'),
21
+			__DIR__.'/../files/AuthServiceProvider.php'      => base_path('app/Providers/AuthServiceProvider.php'),
22
+			__DIR__.'/../files/BroadcastServiceProvider.php' => base_path('app/Providers/BroadcastServiceProvider.php'),
23
+			__DIR__.'/../files/Kernel.php'                   => base_path('app/Console/Kernel.php'),
24
+		]);
25 25
 
26
-        $this->publishes([
27
-            __DIR__.'/../config/skeleton.php' => config_path('skeleton.php'),
28
-        ], 'config');
29
-    }
26
+		$this->publishes([
27
+			__DIR__.'/../config/skeleton.php' => config_path('skeleton.php'),
28
+		], 'config');
29
+	}
30 30
 
31
-    /**
32
-     * Register any package services.
33
-     *
34
-     * @return void
35
-     */
36
-    public function register()
37
-    {
38
-        //
39
-    }
31
+	/**
32
+	 * Register any package services.
33
+	 *
34
+	 * @return void
35
+	 */
36
+	public function register()
37
+	{
38
+		//
39
+	}
40 40
 }
41 41
\ No newline at end of file
Please login to merge, or discard this patch.
files/AuthServiceProvider.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -8,31 +8,31 @@
 block discarded – undo
8 8
 
9 9
 class AuthServiceProvider extends ServiceProvider
10 10
 {
11
-    /**
12
-     * The policy mappings for the application.
13
-     *
14
-     * @var array
15
-     */
16
-    protected $policies = [
17
-        'App\Model' => 'App\Policies\ModelPolicy',
18
-    ];
11
+	/**
12
+	 * The policy mappings for the application.
13
+	 *
14
+	 * @var array
15
+	 */
16
+	protected $policies = [
17
+		'App\Model' => 'App\Policies\ModelPolicy',
18
+	];
19 19
 
20
-    /**
21
-     * Register any authentication / authorization services.
22
-     *
23
-     * @return void
24
-     */
25
-    public function boot()
26
-    {
27
-        $this->registerPolicies();
20
+	/**
21
+	 * Register any authentication / authorization services.
22
+	 *
23
+	 * @return void
24
+	 */
25
+	public function boot()
26
+	{
27
+		$this->registerPolicies();
28 28
 
29
-        Passport::routes(function ($router) {
30
-            $router->forAuthorization();
31
-            $router->forAccessTokens();
32
-            $router->forPersonalAccessTokens();
33
-            $router->forTransientTokens();
34
-        });
35
-        Passport::tokensExpireIn(\Carbon\Carbon::now()->addMinutes(10));
36
-        Passport::refreshTokensExpireIn(\Carbon\Carbon::now()->addDays(10));
37
-    }
29
+		Passport::routes(function ($router) {
30
+			$router->forAuthorization();
31
+			$router->forAccessTokens();
32
+			$router->forPersonalAccessTokens();
33
+			$router->forTransientTokens();
34
+		});
35
+		Passport::tokensExpireIn(\Carbon\Carbon::now()->addMinutes(10));
36
+		Passport::refreshTokensExpireIn(\Carbon\Carbon::now()->addDays(10));
37
+	}
38 38
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
     {
27 27
         $this->registerPolicies();
28 28
 
29
-        Passport::routes(function ($router) {
29
+        Passport::routes(function($router) {
30 30
             $router->forAuthorization();
31 31
             $router->forAccessTokens();
32 32
             $router->forPersonalAccessTokens();
Please login to merge, or discard this patch.
files/auth.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 return [
4 4
 
5
-    /*
5
+	/*
6 6
     |--------------------------------------------------------------------------
7 7
     | Authentication Defaults
8 8
     |--------------------------------------------------------------------------
@@ -13,12 +13,12 @@  discard block
 block discarded – undo
13 13
     |
14 14
     */
15 15
 
16
-    'defaults' => [
17
-        'guard' => 'web',
18
-        'passwords' => 'users',
19
-    ],
16
+	'defaults' => [
17
+		'guard' => 'web',
18
+		'passwords' => 'users',
19
+	],
20 20
 
21
-    /*
21
+	/*
22 22
     |--------------------------------------------------------------------------
23 23
     | Authentication Guards
24 24
     |--------------------------------------------------------------------------
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
     |
36 36
     */
37 37
 
38
-    'guards' => [
39
-        'web' => [
40
-            'driver' => 'session',
41
-            'provider' => 'users',
42
-        ],
38
+	'guards' => [
39
+		'web' => [
40
+			'driver' => 'session',
41
+			'provider' => 'users',
42
+		],
43 43
 
44
-        'api' => [
45
-            'driver' => 'passport',
46
-            'provider' => 'users',
47
-        ],
48
-    ],
44
+		'api' => [
45
+			'driver' => 'passport',
46
+			'provider' => 'users',
47
+		],
48
+	],
49 49
 
50
-    /*
50
+	/*
51 51
     |--------------------------------------------------------------------------
52 52
     | User Providers
53 53
     |--------------------------------------------------------------------------
@@ -64,19 +64,19 @@  discard block
 block discarded – undo
64 64
     |
65 65
     */
66 66
 
67
-    'providers' => [
68
-        'users' => [
69
-            'driver' => 'eloquent',
70
-            'model' => App\Modules\Acl\AclUser::class,
71
-        ],
67
+	'providers' => [
68
+		'users' => [
69
+			'driver' => 'eloquent',
70
+			'model' => App\Modules\Acl\AclUser::class,
71
+		],
72 72
 
73
-        // 'users' => [
74
-        //     'driver' => 'database',
75
-        //     'table' => 'users',
76
-        // ],
77
-    ],
73
+		// 'users' => [
74
+		//     'driver' => 'database',
75
+		//     'table' => 'users',
76
+		// ],
77
+	],
78 78
 
79
-    /*
79
+	/*
80 80
     |--------------------------------------------------------------------------
81 81
     | Resetting Passwords
82 82
     |--------------------------------------------------------------------------
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
     |
92 92
     */
93 93
 
94
-    'passwords' => [
95
-        'users' => [
96
-            'provider' => 'users',
97
-            'table' => 'password_resets',
98
-            'expire' => 60,
99
-        ],
100
-    ],
94
+	'passwords' => [
95
+		'users' => [
96
+			'provider' => 'users',
97
+			'table' => 'password_resets',
98
+			'expire' => 60,
99
+		],
100
+	],
101 101
 
102 102
 ];
Please login to merge, or discard this patch.