Completed
Push — master ( a0772e...0d52ea )
by Sherif
01:55
created
src/Modules/Users/Reppsitories/UserRepository.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php namespace App\Modules\Users\Repositories;
2 2
 
3 3
 use App\Modules\Core\BaseClasses\BaseRepository;
4
-use Illuminate\Support\Arr;
5 4
 use App\Modules\Users\AclUser;
6 5
 
7 6
 class UserRepository extends BaseRepository
Please login to merge, or discard this patch.
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -6,52 +6,52 @@
 block discarded – undo
6 6
 
7 7
 class UserRepository extends BaseRepository
8 8
 {
9
-    /**
10
-     * Init new object.
11
-     *
12
-     * @param   AclUser $model
13
-     * @return  void
14
-     */
15
-    public function __construct(AclUser $model)
16
-    {
17
-        parent::__construct($model);
18
-    }
9
+	/**
10
+	 * Init new object.
11
+	 *
12
+	 * @param   AclUser $model
13
+	 * @return  void
14
+	 */
15
+	public function __construct(AclUser $model)
16
+	{
17
+		parent::__construct($model);
18
+	}
19 19
 
20
-    /**
21
-     * Detach all roles from the given role.
22
-     *
23
-     * @param  mixed $role
24
-     * @return object
25
-     */
26
-    public function detachRoles($role)
27
-    {
28
-        $role = ! is_int($role) ? $role : $this->find($role);
29
-        $role->roles()->detach();
30
-    }
20
+	/**
21
+	 * Detach all roles from the given role.
22
+	 *
23
+	 * @param  mixed $role
24
+	 * @return object
25
+	 */
26
+	public function detachRoles($role)
27
+	{
28
+		$role = ! is_int($role) ? $role : $this->find($role);
29
+		$role->roles()->detach();
30
+	}
31 31
 
32
-    /**
33
-     * Attach role ids to the given role.
34
-     *
35
-     * @param  mixed $role
36
-     * @param  array $roleIds
37
-     * @return object
38
-     */
39
-    public function attachRoles($role, $roleIds)
40
-    {
41
-        $role = ! is_int($role) ? $role : $this->find($role);
42
-        $role->roles()->attach($roleIds);
43
-    }
32
+	/**
33
+	 * Attach role ids to the given role.
34
+	 *
35
+	 * @param  mixed $role
36
+	 * @param  array $roleIds
37
+	 * @return object
38
+	 */
39
+	public function attachRoles($role, $roleIds)
40
+	{
41
+		$role = ! is_int($role) ? $role : $this->find($role);
42
+		$role->roles()->attach($roleIds);
43
+	}
44 44
 
45
-    /**
46
-     * Count the given user the given roles.
47
-     *
48
-     * @param  mixed    $user
49
-     * @param  string[] $roles
50
-     * @return boolean
51
-     */
52
-    public function countRoles($user, $roles)
53
-    {
54
-        $user = ! is_int($user) ? $user : $this->find($user);
55
-        return $user->roles()->whereIn('name', $roles)->count();
56
-    }
45
+	/**
46
+	 * Count the given user the given roles.
47
+	 *
48
+	 * @param  mixed    $user
49
+	 * @param  string[] $roles
50
+	 * @return boolean
51
+	 */
52
+	public function countRoles($user, $roles)
53
+	{
54
+		$user = ! is_int($user) ? $user : $this->find($user);
55
+		return $user->roles()->whereIn('name', $roles)->count();
56
+	}
57 57
 }
Please login to merge, or discard this patch.
src/Modules/Users/Services/UserService.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@
 block discarded – undo
132 132
      *
133 133
      * @param  integer $userId
134 134
      * @param  array   $roleIds
135
-     * @return object
135
+     * @return boolean
136 136
      */
137 137
     public function assignRoles($userId, $roleIds)
138 138
     {
Please login to merge, or discard this patch.
Indentation   +374 added lines, -374 removed lines patch added patch discarded remove patch
@@ -10,382 +10,382 @@
 block discarded – undo
10 10
 
11 11
 class UserService extends BaseService
12 12
 {
13
-    /**
14
-     * @var PermissionService
15
-     */
16
-    protected $permissionService;
17
-
18
-    /**
19
-     * @var LoginProxy
20
-     */
21
-    protected $loginProxy;
22
-
23
-    /**
24
-     * @var NotificationService
25
-     */
26
-    protected $notificationService;
27
-
28
-    /**
29
-     * @var OauthClientService
30
-     */
31
-    protected $oauthClientService;
32
-
33
-    /**
34
-     * Init new object.
35
-     *
36
-     * @param   UserRepository       $repo
37
-     * @param   PermissionService    $permissionService
38
-     * @param   LoginProxy           $loginProxy
39
-     * @param   NotificationService  $notificationService
40
-     * @param   OauthClientService   $oauthClientService
41
-     * @return  void
42
-     */
43
-    public function __construct(
44
-        UserRepository $repo, 
45
-        PermissionService $permissionService, 
46
-        LoginProxy $loginProxy, 
47
-        NotificationService $notificationService,
48
-        OauthClientService $oauthClientService)
49
-    {
50
-        $this->permissionService   = $permissionService;
51
-        $this->loginProxy          = $loginProxy;
52
-        $this->notificationService = $notificationService;
53
-        $this->oauthClientService  = $oauthClientService;
54
-        parent::__construct($repo);
55
-    }
56
-
57
-    /**
58
-     * Return the logged in user account.
59
-     *
60
-     * @param  array   $relations
61
-     * @return boolean
62
-     */
63
-    public function account($relations = ['roles.permissions'])
64
-    {
65
-        $permissions = [];
66
-        $user        = $this->repo->find(\Auth::id(), $relations);
67
-        foreach ($user->roles as $role) {
68
-            $role->permissions->each(function ($permission) use (&$permissions) {
69
-                $permissions[$permission->repo][$permission->id] = $permission->name;
70
-            });
71
-        }
72
-        $user->permissions = $permissions;
73
-
74
-        return $user;
75
-    }
76
-
77
-    /**
78
-     * Check if the logged in user or the given user
79
-     * has the given permissions on the given model.
80
-     *
81
-     * @param  string $permissionName
82
-     * @param  string $model
83
-     * @param  mixed  $userId
84
-     * @return boolean
85
-     */
86
-    public function can($permissionName, $model, $userId = false)
87
-    {
88
-        $permission = $this->permissionService->first([
89
-            'and' => [
90
-                'model' => $model,
91
-                'name'  => $permissionName,
92
-                'roles' => [
93
-                    'op' => 'has',
94
-                    'val' => [
95
-                        'users' => [
96
-                            'op' => 'has',
97
-                            'val' => [
98
-                                'users.id' => $userId ?: \Auth::id()
99
-                            ]
100
-                        ]
101
-                    ]
102
-                ]
103
-            ]
104
-        ]);
105
-
106
-        return $permission ? true : false;
107
-    }
108
-
109
-    /**
110
-     * Check if the logged in or the given user has the given role.
111
-     *
112
-     * @param  string[] $roles
113
-     * @param  mixed    $user
114
-     * @return boolean
115
-     */
116
-    public function hasRoles($roles, $user = false)
117
-    {
118
-        return $this->repo->countRoles($user ?: \Auth::id(), $roles) ? true : false;
119
-    }
120
-
121
-    /**
122
-     * Assign the given role ids to the given user.
123
-     *
124
-     * @param  integer $userId
125
-     * @param  array   $roleIds
126
-     * @return object
127
-     */
128
-    public function assignRoles($userId, $roleIds)
129
-    {
130
-        $user = false;
131
-        \DB::transaction(function () use ($userId, $permissionIds, &$user) {
132
-            $user = $this->repo->find($userId);
133
-            $this->repo->detachPermissions($userId);
134
-            $this->repo->attachPermissions($userId, $roleIds);
135
-        });
136
-
137
-        return $user;
138
-    }
139
-
140
-    /**
141
-     * Handle a login request to the application.
142
-     *
143
-     * @param  string  $email
144
-     * @param  string  $password
145
-     * @param  boolean $adminLogin
146
-     * @return object
147
-     */
148
-    public function login($email, $password, $adminLogin = false)
149
-    {
150
-        if (! $user = $this->repo->first(['email' => $email])) {
151
-            \Errors::loginFailed();
152
-        } elseif ($adminLogin && ! $this->hasRoles(['Admin'], $user)) {
153
-            \Errors::loginFailed();
154
-        } elseif (! $adminLogin && $this->hasRoles(['Admin'], $user)) {
155
-            \Errors::loginFailed();
156
-        } elseif ($user->blocked) {
157
-            \Errors::userIsBlocked();
158
-        } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
159
-            \Errors::emailNotConfirmed();
160
-        }
161
-
162
-        return ['user' => $user, 'tokens' => $this->loginProxy->login($user->email, $password)];
163
-    }
164
-
165
-    /**
166
-     * Handle a social login request of the none admin to the application.
167
-     *
168
-     * @param  string $authCode
169
-     * @param  string $accessToken
170
-     * @param  string $type
171
-     * @return array
172
-     */
173
-    public function loginSocial($authCode, $accessToken, $type)
174
-    {
175
-        $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
176
-        $user         = \Socialite::driver($type)->userFromToken($access_token);
177
-
178
-        if (! $user->email) {
179
-            \Errors::noSocialEmail();
180
-        }
181
-
182
-        if (! $this->repo->first(['email' => $user->email])) {
183
-            $this->register(['email' => $user->email, 'password' => ''], true);
184
-        }
185
-
186
-        return $this->loginProxy->login($user->email, config('skeleton.social_pass'));
187
-    }
13
+	/**
14
+	 * @var PermissionService
15
+	 */
16
+	protected $permissionService;
17
+
18
+	/**
19
+	 * @var LoginProxy
20
+	 */
21
+	protected $loginProxy;
22
+
23
+	/**
24
+	 * @var NotificationService
25
+	 */
26
+	protected $notificationService;
27
+
28
+	/**
29
+	 * @var OauthClientService
30
+	 */
31
+	protected $oauthClientService;
32
+
33
+	/**
34
+	 * Init new object.
35
+	 *
36
+	 * @param   UserRepository       $repo
37
+	 * @param   PermissionService    $permissionService
38
+	 * @param   LoginProxy           $loginProxy
39
+	 * @param   NotificationService  $notificationService
40
+	 * @param   OauthClientService   $oauthClientService
41
+	 * @return  void
42
+	 */
43
+	public function __construct(
44
+		UserRepository $repo, 
45
+		PermissionService $permissionService, 
46
+		LoginProxy $loginProxy, 
47
+		NotificationService $notificationService,
48
+		OauthClientService $oauthClientService)
49
+	{
50
+		$this->permissionService   = $permissionService;
51
+		$this->loginProxy          = $loginProxy;
52
+		$this->notificationService = $notificationService;
53
+		$this->oauthClientService  = $oauthClientService;
54
+		parent::__construct($repo);
55
+	}
56
+
57
+	/**
58
+	 * Return the logged in user account.
59
+	 *
60
+	 * @param  array   $relations
61
+	 * @return boolean
62
+	 */
63
+	public function account($relations = ['roles.permissions'])
64
+	{
65
+		$permissions = [];
66
+		$user        = $this->repo->find(\Auth::id(), $relations);
67
+		foreach ($user->roles as $role) {
68
+			$role->permissions->each(function ($permission) use (&$permissions) {
69
+				$permissions[$permission->repo][$permission->id] = $permission->name;
70
+			});
71
+		}
72
+		$user->permissions = $permissions;
73
+
74
+		return $user;
75
+	}
76
+
77
+	/**
78
+	 * Check if the logged in user or the given user
79
+	 * has the given permissions on the given model.
80
+	 *
81
+	 * @param  string $permissionName
82
+	 * @param  string $model
83
+	 * @param  mixed  $userId
84
+	 * @return boolean
85
+	 */
86
+	public function can($permissionName, $model, $userId = false)
87
+	{
88
+		$permission = $this->permissionService->first([
89
+			'and' => [
90
+				'model' => $model,
91
+				'name'  => $permissionName,
92
+				'roles' => [
93
+					'op' => 'has',
94
+					'val' => [
95
+						'users' => [
96
+							'op' => 'has',
97
+							'val' => [
98
+								'users.id' => $userId ?: \Auth::id()
99
+							]
100
+						]
101
+					]
102
+				]
103
+			]
104
+		]);
105
+
106
+		return $permission ? true : false;
107
+	}
108
+
109
+	/**
110
+	 * Check if the logged in or the given user has the given role.
111
+	 *
112
+	 * @param  string[] $roles
113
+	 * @param  mixed    $user
114
+	 * @return boolean
115
+	 */
116
+	public function hasRoles($roles, $user = false)
117
+	{
118
+		return $this->repo->countRoles($user ?: \Auth::id(), $roles) ? true : false;
119
+	}
120
+
121
+	/**
122
+	 * Assign the given role ids to the given user.
123
+	 *
124
+	 * @param  integer $userId
125
+	 * @param  array   $roleIds
126
+	 * @return object
127
+	 */
128
+	public function assignRoles($userId, $roleIds)
129
+	{
130
+		$user = false;
131
+		\DB::transaction(function () use ($userId, $permissionIds, &$user) {
132
+			$user = $this->repo->find($userId);
133
+			$this->repo->detachPermissions($userId);
134
+			$this->repo->attachPermissions($userId, $roleIds);
135
+		});
136
+
137
+		return $user;
138
+	}
139
+
140
+	/**
141
+	 * Handle a login request to the application.
142
+	 *
143
+	 * @param  string  $email
144
+	 * @param  string  $password
145
+	 * @param  boolean $adminLogin
146
+	 * @return object
147
+	 */
148
+	public function login($email, $password, $adminLogin = false)
149
+	{
150
+		if (! $user = $this->repo->first(['email' => $email])) {
151
+			\Errors::loginFailed();
152
+		} elseif ($adminLogin && ! $this->hasRoles(['Admin'], $user)) {
153
+			\Errors::loginFailed();
154
+		} elseif (! $adminLogin && $this->hasRoles(['Admin'], $user)) {
155
+			\Errors::loginFailed();
156
+		} elseif ($user->blocked) {
157
+			\Errors::userIsBlocked();
158
+		} elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
159
+			\Errors::emailNotConfirmed();
160
+		}
161
+
162
+		return ['user' => $user, 'tokens' => $this->loginProxy->login($user->email, $password)];
163
+	}
164
+
165
+	/**
166
+	 * Handle a social login request of the none admin to the application.
167
+	 *
168
+	 * @param  string $authCode
169
+	 * @param  string $accessToken
170
+	 * @param  string $type
171
+	 * @return array
172
+	 */
173
+	public function loginSocial($authCode, $accessToken, $type)
174
+	{
175
+		$access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
176
+		$user         = \Socialite::driver($type)->userFromToken($access_token);
177
+
178
+		if (! $user->email) {
179
+			\Errors::noSocialEmail();
180
+		}
181
+
182
+		if (! $this->repo->first(['email' => $user->email])) {
183
+			$this->register(['email' => $user->email, 'password' => ''], true);
184
+		}
185
+
186
+		return $this->loginProxy->login($user->email, config('skeleton.social_pass'));
187
+	}
188 188
     
189
-    /**
190
-     * Handle a registration request.
191
-     *
192
-     * @param  string  $name
193
-     * @param  string  $email
194
-     * @param  string  $password
195
-     * @param  boolean $skipConfirmEmail
196
-     * @return array
197
-     */
198
-    public function register($name, $email, $password, $skipConfirmEmail = false)
199
-    {
200
-        $user = $this->repo->save([
201
-            'name'      => $name,
202
-            'email'     => $email,
203
-            'password'  => $password,
204
-            'confirmed' => $skipConfirmEmail
205
-        ]);
206
-
207
-        if (! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) {
208
-            $this->sendConfirmationEmail($user->email);
209
-        }
210
-
211
-        return $user;
212
-    }
189
+	/**
190
+	 * Handle a registration request.
191
+	 *
192
+	 * @param  string  $name
193
+	 * @param  string  $email
194
+	 * @param  string  $password
195
+	 * @param  boolean $skipConfirmEmail
196
+	 * @return array
197
+	 */
198
+	public function register($name, $email, $password, $skipConfirmEmail = false)
199
+	{
200
+		$user = $this->repo->save([
201
+			'name'      => $name,
202
+			'email'     => $email,
203
+			'password'  => $password,
204
+			'confirmed' => $skipConfirmEmail
205
+		]);
206
+
207
+		if (! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) {
208
+			$this->sendConfirmationEmail($user->email);
209
+		}
210
+
211
+		return $user;
212
+	}
213 213
     
214
-    /**
215
-     * Block the user.
216
-     *
217
-     * @param  integer $userId
218
-     * @return object
219
-     */
220
-    public function block($userId)
221
-    {
222
-        if (\Auth::id() == $userId || $this->hasRoles(['Admin'], $user) !== false) {
223
-            \Errors::noPermissions();
224
-        }
214
+	/**
215
+	 * Block the user.
216
+	 *
217
+	 * @param  integer $userId
218
+	 * @return object
219
+	 */
220
+	public function block($userId)
221
+	{
222
+		if (\Auth::id() == $userId || $this->hasRoles(['Admin'], $user) !== false) {
223
+			\Errors::noPermissions();
224
+		}
225 225
         
226
-        return $this->repo->save(['id' => $userId, 'blocked' => 1]);
227
-    }
228
-
229
-    /**
230
-     * Unblock the user.
231
-     *
232
-     * @param  integer $userId
233
-     * @return object
234
-     */
235
-    public function unblock($userId)
236
-    {
237
-        return $this->repo->save(['id' => $userId, 'blocked' => 0]);
238
-    }
239
-
240
-    /**
241
-     * Send a reset link to the given user.
242
-     *
243
-     * @param  string  $email
244
-     * @return void
245
-     */
246
-    public function sendReset($email)
247
-    {
248
-        if (! $user = $this->repo->first(['email' => $email])) {
249
-            \Errors::notFound('email');
250
-        }
251
-
252
-        $token = \Password::getService()->create($user);
253
-        $this->notificationService->notify($user, 'ResetPassword', $token);
254
-    }
255
-
256
-    /**
257
-     * Reset the given user's password.
258
-     *
259
-     * @param   string  $email
260
-     * @param   string  $password
261
-     * @param   string  $passwordConfirmation
262
-     * @param   string  $token
263
-     * @return string|void
264
-     */
265
-    public function resetPassword($email, $password, $passwordConfirmation, $token)
266
-    {
267
-        $response = \Password::reset([
268
-            'email'                 => $email, 
269
-            'password'              => $password, 
270
-            'password_confirmation' => $passwordConfirmation, 
271
-            'token'                 => $token
272
-        ], function ($user, $password) {
273
-            $this->repo->save(['id' => $user->id, 'password' => $password]);
274
-        });
275
-
276
-        switch ($response) {
277
-            case \Password::PASSWORD_RESET:
278
-                return 'success';
279
-                break;
280
-
281
-            case \Password::INVALID_TOKEN:
282
-                \Errors::invalidResetToken('token');
283
-                break;
284
-
285
-            case \Password::INVALID_PASSWORD:
286
-                \Errors::invalidResetPassword('email');
287
-                break;
288
-
289
-            case \Password::INVALID_USER:
290
-                \Errors::notFound('user');
291
-                break;
292
-
293
-            default:
294
-                \Errors::generalError();
295
-                break;
296
-        }
297
-    }
298
-
299
-    /**
300
-     * Change the logged in user password.
301
-     *
302
-     * @param  string  $password
303
-     * @param  string  $oldPassword
304
-     * @return void
305
-     */
306
-    public function changePassword($password, $oldPassword)
307
-    {
308
-        $user = \Auth::user();
309
-        if (! \Hash::check($oldPassword, $user->password)) {
310
-            \Errors::invalidOldPassword();
311
-        }
312
-
313
-        $this->repo->save(['id' => $user->id, 'password' => $password]);
314
-    }
315
-
316
-    /**
317
-     * Confirm email using the confirmation code.
318
-     *
319
-     * @param  string $confirmationCode
320
-     * @return void
321
-     */
322
-    public function confirmEmail($confirmationCode)
323
-    {
324
-        if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
325
-            \Errors::invalidConfirmationCode();
326
-        }
327
-
328
-        $this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]);
329
-    }
330
-
331
-    /**
332
-     * Send the confirmation mail.
333
-     *
334
-     * @param  string $email
335
-     * @return void
336
-     */
337
-    public function sendConfirmationEmail($email)
338
-    {
339
-        $user = $this->repo->first(['email' => $email]);
340
-        if ($user->confirmed) {
341
-            \Errors::emailAlreadyConfirmed();
342
-        }
343
-
344
-        $this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]);
345
-        $this->notificationService->notify($user, 'ConfirmEmail');
346
-    }
347
-
348
-    /**
349
-     * Save the given data to the logged in user.
350
-     *
351
-     * @param  string $name
352
-     * @param  string $email
353
-     * @param  string $profilePicture
354
-     * @return void
355
-     */
356
-    public function saveProfile($name, $email, $profilePicture = false)
357
-    {
358
-        if ($profilePicture) {
359
-            $data['profile_picture'] = \Media::uploadImageBas64($profilePicture, 'admins/profile_pictures');
360
-        }
226
+		return $this->repo->save(['id' => $userId, 'blocked' => 1]);
227
+	}
228
+
229
+	/**
230
+	 * Unblock the user.
231
+	 *
232
+	 * @param  integer $userId
233
+	 * @return object
234
+	 */
235
+	public function unblock($userId)
236
+	{
237
+		return $this->repo->save(['id' => $userId, 'blocked' => 0]);
238
+	}
239
+
240
+	/**
241
+	 * Send a reset link to the given user.
242
+	 *
243
+	 * @param  string  $email
244
+	 * @return void
245
+	 */
246
+	public function sendReset($email)
247
+	{
248
+		if (! $user = $this->repo->first(['email' => $email])) {
249
+			\Errors::notFound('email');
250
+		}
251
+
252
+		$token = \Password::getService()->create($user);
253
+		$this->notificationService->notify($user, 'ResetPassword', $token);
254
+	}
255
+
256
+	/**
257
+	 * Reset the given user's password.
258
+	 *
259
+	 * @param   string  $email
260
+	 * @param   string  $password
261
+	 * @param   string  $passwordConfirmation
262
+	 * @param   string  $token
263
+	 * @return string|void
264
+	 */
265
+	public function resetPassword($email, $password, $passwordConfirmation, $token)
266
+	{
267
+		$response = \Password::reset([
268
+			'email'                 => $email, 
269
+			'password'              => $password, 
270
+			'password_confirmation' => $passwordConfirmation, 
271
+			'token'                 => $token
272
+		], function ($user, $password) {
273
+			$this->repo->save(['id' => $user->id, 'password' => $password]);
274
+		});
275
+
276
+		switch ($response) {
277
+			case \Password::PASSWORD_RESET:
278
+				return 'success';
279
+				break;
280
+
281
+			case \Password::INVALID_TOKEN:
282
+				\Errors::invalidResetToken('token');
283
+				break;
284
+
285
+			case \Password::INVALID_PASSWORD:
286
+				\Errors::invalidResetPassword('email');
287
+				break;
288
+
289
+			case \Password::INVALID_USER:
290
+				\Errors::notFound('user');
291
+				break;
292
+
293
+			default:
294
+				\Errors::generalError();
295
+				break;
296
+		}
297
+	}
298
+
299
+	/**
300
+	 * Change the logged in user password.
301
+	 *
302
+	 * @param  string  $password
303
+	 * @param  string  $oldPassword
304
+	 * @return void
305
+	 */
306
+	public function changePassword($password, $oldPassword)
307
+	{
308
+		$user = \Auth::user();
309
+		if (! \Hash::check($oldPassword, $user->password)) {
310
+			\Errors::invalidOldPassword();
311
+		}
312
+
313
+		$this->repo->save(['id' => $user->id, 'password' => $password]);
314
+	}
315
+
316
+	/**
317
+	 * Confirm email using the confirmation code.
318
+	 *
319
+	 * @param  string $confirmationCode
320
+	 * @return void
321
+	 */
322
+	public function confirmEmail($confirmationCode)
323
+	{
324
+		if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
325
+			\Errors::invalidConfirmationCode();
326
+		}
327
+
328
+		$this->repo->save(['id' => $user->id, 'confirmed' => 1, 'confirmation_code' => null]);
329
+	}
330
+
331
+	/**
332
+	 * Send the confirmation mail.
333
+	 *
334
+	 * @param  string $email
335
+	 * @return void
336
+	 */
337
+	public function sendConfirmationEmail($email)
338
+	{
339
+		$user = $this->repo->first(['email' => $email]);
340
+		if ($user->confirmed) {
341
+			\Errors::emailAlreadyConfirmed();
342
+		}
343
+
344
+		$this->repo->save(['id' => $user->id, 'confirmation_code' => sha1(microtime())]);
345
+		$this->notificationService->notify($user, 'ConfirmEmail');
346
+	}
347
+
348
+	/**
349
+	 * Save the given data to the logged in user.
350
+	 *
351
+	 * @param  string $name
352
+	 * @param  string $email
353
+	 * @param  string $profilePicture
354
+	 * @return void
355
+	 */
356
+	public function saveProfile($name, $email, $profilePicture = false)
357
+	{
358
+		if ($profilePicture) {
359
+			$data['profile_picture'] = \Media::uploadImageBas64($profilePicture, 'admins/profile_pictures');
360
+		}
361 361
         
362
-        $data['id'] = \Auth::id();
363
-        return $this->repo->save([
364
-            'id'             => \Auth::id(),
365
-            'name'           => $name,
366
-            'email'          => $email,
367
-            'profilePicture' => $profilePicture,
368
-        ]);
369
-    }
370
-
371
-    /**
372
-     * Logs out the user, revoke access token and refresh token.
373
-     *
374
-     * @return void
375
-     */
376
-    public function logout()
377
-    {
378
-        $this->oauthClientService->revokeAccessToken(\Auth::user()->token());
379
-    }
380
-
381
-    /**
382
-     * Attempt to refresh the access token using the given refresh token.
383
-     *
384
-     * @param  string $refreshToken
385
-     * @return array
386
-     */
387
-    public function refreshToken($refreshToken)
388
-    {
389
-        return $this->loginProxy->refreshToken($refreshToken);
390
-    }
362
+		$data['id'] = \Auth::id();
363
+		return $this->repo->save([
364
+			'id'             => \Auth::id(),
365
+			'name'           => $name,
366
+			'email'          => $email,
367
+			'profilePicture' => $profilePicture,
368
+		]);
369
+	}
370
+
371
+	/**
372
+	 * Logs out the user, revoke access token and refresh token.
373
+	 *
374
+	 * @return void
375
+	 */
376
+	public function logout()
377
+	{
378
+		$this->oauthClientService->revokeAccessToken(\Auth::user()->token());
379
+	}
380
+
381
+	/**
382
+	 * Attempt to refresh the access token using the given refresh token.
383
+	 *
384
+	 * @param  string $refreshToken
385
+	 * @return array
386
+	 */
387
+	public function refreshToken($refreshToken)
388
+	{
389
+		return $this->loginProxy->refreshToken($refreshToken);
390
+	}
391 391
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         $permissions = [];
66 66
         $user        = $this->repo->find(\Auth::id(), $relations);
67 67
         foreach ($user->roles as $role) {
68
-            $role->permissions->each(function ($permission) use (&$permissions) {
68
+            $role->permissions->each(function($permission) use (&$permissions) {
69 69
                 $permissions[$permission->repo][$permission->id] = $permission->name;
70 70
             });
71 71
         }
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
     public function assignRoles($userId, $roleIds)
129 129
     {
130 130
         $user = false;
131
-        \DB::transaction(function () use ($userId, $permissionIds, &$user) {
131
+        \DB::transaction(function() use ($userId, $permissionIds, &$user) {
132 132
             $user = $this->repo->find($userId);
133 133
             $this->repo->detachPermissions($userId);
134 134
             $this->repo->attachPermissions($userId, $roleIds);
@@ -147,15 +147,15 @@  discard block
 block discarded – undo
147 147
      */
148 148
     public function login($email, $password, $adminLogin = false)
149 149
     {
150
-        if (! $user = $this->repo->first(['email' => $email])) {
150
+        if ( ! $user = $this->repo->first(['email' => $email])) {
151 151
             \Errors::loginFailed();
152 152
         } elseif ($adminLogin && ! $this->hasRoles(['Admin'], $user)) {
153 153
             \Errors::loginFailed();
154
-        } elseif (! $adminLogin && $this->hasRoles(['Admin'], $user)) {
154
+        } elseif ( ! $adminLogin && $this->hasRoles(['Admin'], $user)) {
155 155
             \Errors::loginFailed();
156 156
         } elseif ($user->blocked) {
157 157
             \Errors::userIsBlocked();
158
-        } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
158
+        } elseif ( ! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
159 159
             \Errors::emailNotConfirmed();
160 160
         }
161 161
 
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
         $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
176 176
         $user         = \Socialite::driver($type)->userFromToken($access_token);
177 177
 
178
-        if (! $user->email) {
178
+        if ( ! $user->email) {
179 179
             \Errors::noSocialEmail();
180 180
         }
181 181
 
182
-        if (! $this->repo->first(['email' => $user->email])) {
182
+        if ( ! $this->repo->first(['email' => $user->email])) {
183 183
             $this->register(['email' => $user->email, 'password' => ''], true);
184 184
         }
185 185
 
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
             'confirmed' => $skipConfirmEmail
205 205
         ]);
206 206
 
207
-        if (! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) {
207
+        if ( ! $skipConfirmEmail && ! config('skeleton.disable_confirm_email')) {
208 208
             $this->sendConfirmationEmail($user->email);
209 209
         }
210 210
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      */
246 246
     public function sendReset($email)
247 247
     {
248
-        if (! $user = $this->repo->first(['email' => $email])) {
248
+        if ( ! $user = $this->repo->first(['email' => $email])) {
249 249
             \Errors::notFound('email');
250 250
         }
251 251
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
             'password'              => $password, 
270 270
             'password_confirmation' => $passwordConfirmation, 
271 271
             'token'                 => $token
272
-        ], function ($user, $password) {
272
+        ], function($user, $password) {
273 273
             $this->repo->save(['id' => $user->id, 'password' => $password]);
274 274
         });
275 275
 
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
     public function changePassword($password, $oldPassword)
307 307
     {
308 308
         $user = \Auth::user();
309
-        if (! \Hash::check($oldPassword, $user->password)) {
309
+        if ( ! \Hash::check($oldPassword, $user->password)) {
310 310
             \Errors::invalidOldPassword();
311 311
         }
312 312
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
      */
322 322
     public function confirmEmail($confirmationCode)
323 323
     {
324
-        if (! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
324
+        if ( ! $user = $this->repo->first(['confirmation_code' => $confirmationCode])) {
325 325
             \Errors::invalidConfirmationCode();
326 326
         }
327 327
 
Please login to merge, or discard this patch.
src/Modules/Users/Database/Seeds/UsersTableSeeder.php 2 patches
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -8,105 +8,105 @@
 block discarded – undo
8 8
 
9 9
 class UsersTableSeeder extends Seeder
10 10
 {
11
-    /**
12
-     * Run the database seeds.
13
-     *
14
-     * @return void
15
-     */
16
-    public function run()
17
-    {
18
-        /**
19
-         * Create Default roles.
20
-         */
21
-        $role = Role::updateOrInsert([
22
-            'name' => 'Admin',
23
-        ],[
24
-            'created_at' => \DB::raw('NOW()'),
25
-            'updated_at' => \DB::raw('NOW()')
26
-        ]);
11
+	/**
12
+	 * Run the database seeds.
13
+	 *
14
+	 * @return void
15
+	 */
16
+	public function run()
17
+	{
18
+		/**
19
+		 * Create Default roles.
20
+		 */
21
+		$role = Role::updateOrInsert([
22
+			'name' => 'Admin',
23
+		],[
24
+			'created_at' => \DB::raw('NOW()'),
25
+			'updated_at' => \DB::raw('NOW()')
26
+		]);
27 27
 
28
-        /**
29
-         * Create Default user.
30
-         */
31
-        AclUser::updateOrInsert([
32
-            'email' => '[email protected]',
33
-        ],[
34
-            'name'       => 'Admin',
35
-            'password'   => \Hash::make('123456'),
36
-            'confirmed'  => 1,
37
-            'created_at' => \DB::raw('NOW()'),
38
-            'updated_at' => \DB::raw('NOW()')
39
-        ]);
28
+		/**
29
+		 * Create Default user.
30
+		 */
31
+		AclUser::updateOrInsert([
32
+			'email' => '[email protected]',
33
+		],[
34
+			'name'       => 'Admin',
35
+			'password'   => \Hash::make('123456'),
36
+			'confirmed'  => 1,
37
+			'created_at' => \DB::raw('NOW()'),
38
+			'updated_at' => \DB::raw('NOW()')
39
+		]);
40 40
 
41
-        /**
42
-         * Insert the permissions related to users table.
43
-         */
44
-        \DB::table('permissions')->insert(
45
-            [
46
-                /**
47
-                 * Users model permissions.
48
-                 */
49
-                [
50
-                'name'       => 'index',
51
-                'model'      => 'user',
52
-                'created_at' => \DB::raw('NOW()'),
53
-                'updated_at' => \DB::raw('NOW()')
54
-                ],
55
-                [
56
-                'name'       => 'find',
57
-                'model'      => 'user',
58
-                'created_at' => \DB::raw('NOW()'),
59
-                'updated_at' => \DB::raw('NOW()')
60
-                ],
61
-                [
62
-                'name'       => 'insert',
63
-                'model'      => 'user',
64
-                'created_at' => \DB::raw('NOW()'),
65
-                'updated_at' => \DB::raw('NOW()')
66
-                ],
67
-                [
68
-                'name'       => 'update',
69
-                'model'      => 'user',
70
-                'created_at' => \DB::raw('NOW()'),
71
-                'updated_at' => \DB::raw('NOW()')
72
-                ],
73
-                [
74
-                'name'       => 'delete',
75
-                'model'      => 'user',
76
-                'created_at' => \DB::raw('NOW()'),
77
-                'updated_at' => \DB::raw('NOW()')
78
-                ],
79
-                [
80
-                'name'       => 'deleted',
81
-                'model'      => 'user',
82
-                'created_at' => \DB::raw('NOW()'),
83
-                'updated_at' => \DB::raw('NOW()')
84
-                ],
85
-                [
86
-                'name'       => 'restore',
87
-                'model'      => 'user',
88
-                'created_at' => \DB::raw('NOW()'),
89
-                'updated_at' => \DB::raw('NOW()')
90
-                ],
91
-                [
92
-                'name'       => 'assignRoles',
93
-                'model'      => 'user',
94
-                'created_at' => \DB::raw('NOW()'),
95
-                'updated_at' => \DB::raw('NOW()')
96
-                ],
97
-                [
98
-                'name'       => 'block',
99
-                'model'      => 'user',
100
-                'created_at' => \DB::raw('NOW()'),
101
-                'updated_at' => \DB::raw('NOW()')
102
-                ],
103
-                [
104
-                'name'       => 'unblock',
105
-                'model'      => 'user',
106
-                'created_at' => \DB::raw('NOW()'),
107
-                'updated_at' => \DB::raw('NOW()')
108
-                ]
109
-            ]
110
-        );
111
-    }
41
+		/**
42
+		 * Insert the permissions related to users table.
43
+		 */
44
+		\DB::table('permissions')->insert(
45
+			[
46
+				/**
47
+				 * Users model permissions.
48
+				 */
49
+				[
50
+				'name'       => 'index',
51
+				'model'      => 'user',
52
+				'created_at' => \DB::raw('NOW()'),
53
+				'updated_at' => \DB::raw('NOW()')
54
+				],
55
+				[
56
+				'name'       => 'find',
57
+				'model'      => 'user',
58
+				'created_at' => \DB::raw('NOW()'),
59
+				'updated_at' => \DB::raw('NOW()')
60
+				],
61
+				[
62
+				'name'       => 'insert',
63
+				'model'      => 'user',
64
+				'created_at' => \DB::raw('NOW()'),
65
+				'updated_at' => \DB::raw('NOW()')
66
+				],
67
+				[
68
+				'name'       => 'update',
69
+				'model'      => 'user',
70
+				'created_at' => \DB::raw('NOW()'),
71
+				'updated_at' => \DB::raw('NOW()')
72
+				],
73
+				[
74
+				'name'       => 'delete',
75
+				'model'      => 'user',
76
+				'created_at' => \DB::raw('NOW()'),
77
+				'updated_at' => \DB::raw('NOW()')
78
+				],
79
+				[
80
+				'name'       => 'deleted',
81
+				'model'      => 'user',
82
+				'created_at' => \DB::raw('NOW()'),
83
+				'updated_at' => \DB::raw('NOW()')
84
+				],
85
+				[
86
+				'name'       => 'restore',
87
+				'model'      => 'user',
88
+				'created_at' => \DB::raw('NOW()'),
89
+				'updated_at' => \DB::raw('NOW()')
90
+				],
91
+				[
92
+				'name'       => 'assignRoles',
93
+				'model'      => 'user',
94
+				'created_at' => \DB::raw('NOW()'),
95
+				'updated_at' => \DB::raw('NOW()')
96
+				],
97
+				[
98
+				'name'       => 'block',
99
+				'model'      => 'user',
100
+				'created_at' => \DB::raw('NOW()'),
101
+				'updated_at' => \DB::raw('NOW()')
102
+				],
103
+				[
104
+				'name'       => 'unblock',
105
+				'model'      => 'user',
106
+				'created_at' => \DB::raw('NOW()'),
107
+				'updated_at' => \DB::raw('NOW()')
108
+				]
109
+			]
110
+		);
111
+	}
112 112
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
          */
21 21
         $role = Role::updateOrInsert([
22 22
             'name' => 'Admin',
23
-        ],[
23
+        ], [
24 24
             'created_at' => \DB::raw('NOW()'),
25 25
             'updated_at' => \DB::raw('NOW()')
26 26
         ]);
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
          */
31 31
         AclUser::updateOrInsert([
32 32
             'email' => '[email protected]',
33
-        ],[
33
+        ], [
34 34
             'name'       => 'Admin',
35 35
             'password'   => \Hash::make('123456'),
36 36
             'confirmed'  => 1,
Please login to merge, or discard this patch.
src/Modules/Users/Database/Seeds/AssignRelationsSeeder.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -6,27 +6,27 @@
 block discarded – undo
6 6
 
7 7
 class AssignRelationsSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id;
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id;
17 17
 
18
-        /**
19
-         * Assign the permissions to the admin role.
20
-         */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['user'])->each(function ($permission) use ($adminRoleId) {
22
-            \DB::table('permission_role')->insert(
23
-                [
24
-                'permission_id' => $permission->id,
25
-                'role_id'       => $adminRoleId,
26
-                'created_at'    => \DB::raw('NOW()'),
27
-                'updated_at'    => \DB::raw('NOW()')
28
-                ]
29
-            );
30
-        });
31
-    }
18
+		/**
19
+		 * Assign the permissions to the admin role.
20
+		 */
21
+		\DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['user'])->each(function ($permission) use ($adminRoleId) {
22
+			\DB::table('permission_role')->insert(
23
+				[
24
+				'permission_id' => $permission->id,
25
+				'role_id'       => $adminRoleId,
26
+				'created_at'    => \DB::raw('NOW()'),
27
+				'updated_at'    => \DB::raw('NOW()')
28
+				]
29
+			);
30
+		});
31
+	}
32 32
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
         /**
19 19
          * Assign the permissions to the admin role.
20 20
          */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['user'])->each(function ($permission) use ($adminRoleId) {
21
+        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['user'])->each(function($permission) use ($adminRoleId) {
22 22
             \DB::table('permission_role')->insert(
23 23
                 [
24 24
                 'permission_id' => $permission->id,
Please login to merge, or discard this patch.
src/Modules/Users/Database/Seeds/ClearDataSeeder.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -6,15 +6,15 @@
 block discarded – undo
6 6
 
7 7
 class ClearDataSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $permissions = \DB::table('permissions')->whereIn('model', ['user']);
17
-        \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete();
18
-        $permissions->delete();
19
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$permissions = \DB::table('permissions')->whereIn('model', ['user']);
17
+		\DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete();
18
+		$permissions->delete();
19
+	}
20 20
 }
Please login to merge, or discard this patch.
Modules/PushNotificationDevices/Database/Seeds/AssignRelationsSeeder.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -6,27 +6,27 @@
 block discarded – undo
6 6
 
7 7
 class AssignRelationsSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id;
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id;
17 17
 
18
-        /**
19
-         * Assign the permissions to the admin role.
20
-         */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['pushNotificationDevice'])->each(function ($permission) use ($adminRoleId) {
22
-            \DB::table('permission_role')->insert(
23
-                [
24
-                'permission_id' => $permission->id,
25
-                'role_id'      => $adminRoleId,
26
-                'created_at'    => \DB::raw('NOW()'),
27
-                'updated_at'    => \DB::raw('NOW()')
28
-                ]
29
-            );
30
-        });
31
-    }
18
+		/**
19
+		 * Assign the permissions to the admin role.
20
+		 */
21
+		\DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['pushNotificationDevice'])->each(function ($permission) use ($adminRoleId) {
22
+			\DB::table('permission_role')->insert(
23
+				[
24
+				'permission_id' => $permission->id,
25
+				'role_id'      => $adminRoleId,
26
+				'created_at'    => \DB::raw('NOW()'),
27
+				'updated_at'    => \DB::raw('NOW()')
28
+				]
29
+			);
30
+		});
31
+	}
32 32
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
         /**
19 19
          * Assign the permissions to the admin role.
20 20
          */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['pushNotificationDevice'])->each(function ($permission) use ($adminRoleId) {
21
+        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['pushNotificationDevice'])->each(function($permission) use ($adminRoleId) {
22 22
             \DB::table('permission_role')->insert(
23 23
                 [
24 24
                 'permission_id' => $permission->id,
Please login to merge, or discard this patch.
src/Modules/PushNotificationDevices/Database/Seeds/ClearDataSeeder.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -6,15 +6,15 @@
 block discarded – undo
6 6
 
7 7
 class ClearDataSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-        $permissions = \DB::table('permissions')->whereIn('model', ['pushNotificationDevice']);
17
-        \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete();
18
-        $permissions->delete();
19
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$permissions = \DB::table('permissions')->whereIn('model', ['pushNotificationDevice']);
17
+		\DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete();
18
+		$permissions->delete();
19
+	}
20 20
 }
Please login to merge, or discard this patch.
Http/Controllers/PushNotificationDeviceController.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -10,61 +10,61 @@
 block discarded – undo
10 10
 
11 11
 class PushNotificationDeviceController extends BaseApiController
12 12
 {
13
-    /**
14
-     * Path of the model resource
15
-     *
16
-     * @var string
17
-     */
18
-    protected $modelResource = 'App\Modules\PushNotificationDevices\Http\Resources\PushNotificationDevice';
13
+	/**
14
+	 * Path of the model resource
15
+	 *
16
+	 * @var string
17
+	 */
18
+	protected $modelResource = 'App\Modules\PushNotificationDevices\Http\Resources\PushNotificationDevice';
19 19
 
20
-    /**
21
-     * List of all route actions that the base api controller
22
-     * will skip permissions check for them.
23
-     * @var array
24
-     */
25
-    protected $skipPermissionCheck = ['registerDevice'];
20
+	/**
21
+	 * List of all route actions that the base api controller
22
+	 * will skip permissions check for them.
23
+	 * @var array
24
+	 */
25
+	protected $skipPermissionCheck = ['registerDevice'];
26 26
 
27
-    /**
28
-     * Init new object.
29
-     *
30
-     * @param   PushNotificationDeviceService $service
31
-     * @return  void
32
-     */
33
-    public function __construct(PushNotificationDeviceService $service)
34
-    {
35
-        parent::__construct($service);
36
-    }
27
+	/**
28
+	 * Init new object.
29
+	 *
30
+	 * @param   PushNotificationDeviceService $service
31
+	 * @return  void
32
+	 */
33
+	public function __construct(PushNotificationDeviceService $service)
34
+	{
35
+		parent::__construct($service);
36
+	}
37 37
 
38
-    /**
39
-     * Insert the given model to storage.
40
-     *
41
-     * @param InsertPushNotificationDevice $request
42
-     * @return \Illuminate\Http\Response
43
-     */
44
-    public function insert(InsertPushNotificationDevice $request)
45
-    {
46
-        return new $this->modelResource($this->service->save($request->all()));
47
-    }
38
+	/**
39
+	 * Insert the given model to storage.
40
+	 *
41
+	 * @param InsertPushNotificationDevice $request
42
+	 * @return \Illuminate\Http\Response
43
+	 */
44
+	public function insert(InsertPushNotificationDevice $request)
45
+	{
46
+		return new $this->modelResource($this->service->save($request->all()));
47
+	}
48 48
 
49
-    /**
50
-     * Update the given model to storage.
51
-     *
52
-     * @param UpdatePushNotificationDevice $request
53
-     * @return \Illuminate\Http\Response
54
-     */
55
-    public function update(UpdatePushNotificationDevice $request)
56
-    {
57
-        return new $this->modelResource($this->service->save($request->all()));
58
-    }
49
+	/**
50
+	 * Update the given model to storage.
51
+	 *
52
+	 * @param UpdatePushNotificationDevice $request
53
+	 * @return \Illuminate\Http\Response
54
+	 */
55
+	public function update(UpdatePushNotificationDevice $request)
56
+	{
57
+		return new $this->modelResource($this->service->save($request->all()));
58
+	}
59 59
 
60
-    /**
61
-     * Register the given device to the logged in user.
62
-     *
63
-     * @param RegisterDevice $request
64
-     * @return \Illuminate\Http\Response
65
-     */
66
-    public function registerDevice(RegisterDevice $request)
67
-    {
68
-        return new $this->modelResource($this->service->registerDevice($request->all()));
69
-    }
60
+	/**
61
+	 * Register the given device to the logged in user.
62
+	 *
63
+	 * @param RegisterDevice $request
64
+	 * @return \Illuminate\Http\Response
65
+	 */
66
+	public function registerDevice(RegisterDevice $request)
67
+	{
68
+		return new $this->modelResource($this->service->registerDevice($request->all()));
69
+	}
70 70
 }
Please login to merge, or discard this patch.
Modules/PushNotificationDevices/Services/PushNotificationDeviceService.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -8,63 +8,63 @@
 block discarded – undo
8 8
 
9 9
 class PushNotificationDeviceService extends BaseService
10 10
 {
11
-    /**
12
-     * Init new object.
13
-     *
14
-     * @param   PushNotificationDeviceRepository $repo
15
-     * @return  void
16
-     */
17
-    public function __construct(PushNotificationDeviceRepository $repo)
18
-    {
19
-        parent::__construct($repo);
20
-    }
11
+	/**
12
+	 * Init new object.
13
+	 *
14
+	 * @param   PushNotificationDeviceRepository $repo
15
+	 * @return  void
16
+	 */
17
+	public function __construct(PushNotificationDeviceRepository $repo)
18
+	{
19
+		parent::__construct($repo);
20
+	}
21 21
 
22
-    /**
23
-     * Register the given device to the logged in user.
24
-     *
25
-     * @param  array $data
26
-     * @return void
27
-     */
28
-    public function registerDevice($data)
29
-    {
30
-        $data['access_token'] = \Auth::user()->token();
31
-        $data['user_id']      = \Auth::id();
32
-        $device               = $this->repo->first([
33
-            'and' => [
34
-                'device_token' => $data['device_token'], 
35
-                'user_id' => $data['user_id']
36
-                ]
37
-            ]);
22
+	/**
23
+	 * Register the given device to the logged in user.
24
+	 *
25
+	 * @param  array $data
26
+	 * @return void
27
+	 */
28
+	public function registerDevice($data)
29
+	{
30
+		$data['access_token'] = \Auth::user()->token();
31
+		$data['user_id']      = \Auth::id();
32
+		$device               = $this->repo->first([
33
+			'and' => [
34
+				'device_token' => $data['device_token'], 
35
+				'user_id' => $data['user_id']
36
+				]
37
+			]);
38 38
 
39
-        if ($device) {
40
-            $data['id'] = $device->id;
41
-        }
39
+		if ($device) {
40
+			$data['id'] = $device->id;
41
+		}
42 42
 
43
-        return $this->repo->save($data);
44
-    }
43
+		return $this->repo->save($data);
44
+	}
45 45
 
46
-    /**
47
-     * Generate the given message data.
48
-     *
49
-     * @param  string $title
50
-     * @param  string $message
51
-     * @param  array  $data
52
-     * @return void
53
-     */
54
-    public function generateMessageData($title, $message, $data = [])
55
-    {
56
-        $optionBuilder       = new OptionsBuilder();
57
-        $notificationBuilder = new PayloadNotificationBuilder($title);
58
-        $dataBuilder         = new PayloadDataBuilder();
46
+	/**
47
+	 * Generate the given message data.
48
+	 *
49
+	 * @param  string $title
50
+	 * @param  string $message
51
+	 * @param  array  $data
52
+	 * @return void
53
+	 */
54
+	public function generateMessageData($title, $message, $data = [])
55
+	{
56
+		$optionBuilder       = new OptionsBuilder();
57
+		$notificationBuilder = new PayloadNotificationBuilder($title);
58
+		$dataBuilder         = new PayloadDataBuilder();
59 59
 
60
-        $optionBuilder->setTimeToLive(60 * 20);
61
-        $notificationBuilder->setBody($message);
62
-        $dataBuilder->addData($data);
60
+		$optionBuilder->setTimeToLive(60 * 20);
61
+		$notificationBuilder->setBody($message);
62
+		$dataBuilder->addData($data);
63 63
 
64
-        $options             = $optionBuilder->build();
65
-        $notification        = $notificationBuilder->build();
66
-        $data                = $dataBuilder->build();
64
+		$options             = $optionBuilder->build();
65
+		$notification        = $notificationBuilder->build();
66
+		$data                = $dataBuilder->build();
67 67
 
68
-        return compact('options', 'notification', 'data');
69
-    }
68
+		return compact('options', 'notification', 'data');
69
+	}
70 70
 }
Please login to merge, or discard this patch.