Completed
Push — master ( ec2395...0dfd17 )
by Sherif
02:09
created
src/Modules/Users/AclUser.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -7,133 +7,133 @@
 block discarded – undo
7 7
 class AclUser extends User
8 8
 {
9 9
 
10
-    use SoftDeletes, HasApiTokens;
11
-    protected $table    = 'users';
12
-    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
13
-    protected $hidden   = ['password', 'remember_token', 'deleted_at'];
14
-    protected $guarded  = ['id'];
15
-    protected $fillable = ['profile_picture', 'name', 'email', 'password', 'locale', 'timezone'];
16
-    public $searchable  = ['name', 'email'];
10
+	use SoftDeletes, HasApiTokens;
11
+	protected $table    = 'users';
12
+	protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
13
+	protected $hidden   = ['password', 'remember_token', 'deleted_at'];
14
+	protected $guarded  = ['id'];
15
+	protected $fillable = ['profile_picture', 'name', 'email', 'password', 'locale', 'timezone'];
16
+	public $searchable  = ['name', 'email'];
17 17
     
18
-    public function getCreatedAtAttribute($value)
19
-    {
20
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
21
-    }
22
-
23
-    public function getUpdatedAtAttribute($value)
24
-    {
25
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
26
-    }
27
-
28
-    public function getDeletedAtAttribute($value)
29
-    {
30
-        return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
31
-    }
32
-
33
-    /**
34
-     * Get the profile picture url.
35
-     * @return string
36
-     */
37
-    public function getProfilePictureAttribute($value)
38
-    {
39
-        return url(\Storage::url($value));
40
-    }
41
-
42
-    /**
43
-     * Encrypt the password attribute before
44
-     * saving it in the storage.
45
-     *
46
-     * @param string $value
47
-     */
48
-    public function setPasswordAttribute($value)
49
-    {
50
-        $this->attributes['password'] = bcrypt($value);
51
-    }
52
-
53
-    /**
54
-     * Get the entity's notifications.
55
-     */
56
-    public function notifications()
57
-    {
58
-        return $this->morphMany('App\Modules\Notifications\Notification', 'notifiable')->orderBy('created_at', 'desc');
59
-    }
60
-
61
-    /**
62
-     * Get the entity's read notifications.
63
-     */
64
-    public function readNotifications()
65
-    {
66
-        return $this->notifications()->whereNotNull('read_at');
67
-    }
68
-
69
-    /**
70
-     * Get the entity's unread notifications.
71
-     */
72
-    public function unreadNotifications()
73
-    {
74
-        return $this->notifications()->whereNull('read_at');
75
-    }
76
-
77
-    public function groups()
78
-    {
79
-        return $this->belongsToMany('App\Modules\Groups\AclGroup', 'users_groups', 'user_id', 'group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
80
-    }
81
-
82
-    public function oauthClients()
83
-    {
84
-        return $this->hasMany('App\Modules\OauthClients\OauthClient', 'user_id');
85
-    }
86
-
87
-    /**
88
-     * Return fcm device tokens that will be used in sending fcm notifications.
89
-     *
90
-     * @return array
91
-     */
92
-    public function routeNotificationForFCM()
93
-    {
94
-        $devices = \Core::pushNotificationDevices()->findBy(['user_id' => $this->id]);
95
-        $tokens  = [];
96
-
97
-        foreach ($devices as $device) {
98
-            if (\Core::users()->accessTokenExpiredOrRevoked($device->access_token)) {
99
-                $device->forceDelete();
100
-                continue;
101
-            }
102
-
103
-            $tokens[] = $device->device_token;
104
-        }
105
-
106
-        return $tokens;
107
-    }
108
-
109
-    /**
110
-     * The channels the user receives notification broadcasts on.
111
-     *
112
-     * @return string
113
-     */
114
-    public function receivesBroadcastNotificationsOn()
115
-    {
116
-        return 'users.'.$this->id;
117
-    }
118
-
119
-    /**
120
-     * Custom password validation.
121
-     *
122
-     * @param  string $password
123
-     * @return boolean
124
-     */
125
-    public function validateForPassportPasswordGrant($password)
126
-    {
127
-        if ($password == config('skeleton.social_pass')) {
128
-            return true;
129
-        }
130
-
131
-        return \Hash::check($password, $this->password);
132
-    }
18
+	public function getCreatedAtAttribute($value)
19
+	{
20
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
21
+	}
22
+
23
+	public function getUpdatedAtAttribute($value)
24
+	{
25
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
26
+	}
27
+
28
+	public function getDeletedAtAttribute($value)
29
+	{
30
+		return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString();
31
+	}
32
+
33
+	/**
34
+	 * Get the profile picture url.
35
+	 * @return string
36
+	 */
37
+	public function getProfilePictureAttribute($value)
38
+	{
39
+		return url(\Storage::url($value));
40
+	}
41
+
42
+	/**
43
+	 * Encrypt the password attribute before
44
+	 * saving it in the storage.
45
+	 *
46
+	 * @param string $value
47
+	 */
48
+	public function setPasswordAttribute($value)
49
+	{
50
+		$this->attributes['password'] = bcrypt($value);
51
+	}
52
+
53
+	/**
54
+	 * Get the entity's notifications.
55
+	 */
56
+	public function notifications()
57
+	{
58
+		return $this->morphMany('App\Modules\Notifications\Notification', 'notifiable')->orderBy('created_at', 'desc');
59
+	}
60
+
61
+	/**
62
+	 * Get the entity's read notifications.
63
+	 */
64
+	public function readNotifications()
65
+	{
66
+		return $this->notifications()->whereNotNull('read_at');
67
+	}
68
+
69
+	/**
70
+	 * Get the entity's unread notifications.
71
+	 */
72
+	public function unreadNotifications()
73
+	{
74
+		return $this->notifications()->whereNull('read_at');
75
+	}
76
+
77
+	public function groups()
78
+	{
79
+		return $this->belongsToMany('App\Modules\Groups\AclGroup', 'users_groups', 'user_id', 'group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
80
+	}
81
+
82
+	public function oauthClients()
83
+	{
84
+		return $this->hasMany('App\Modules\OauthClients\OauthClient', 'user_id');
85
+	}
86
+
87
+	/**
88
+	 * Return fcm device tokens that will be used in sending fcm notifications.
89
+	 *
90
+	 * @return array
91
+	 */
92
+	public function routeNotificationForFCM()
93
+	{
94
+		$devices = \Core::pushNotificationDevices()->findBy(['user_id' => $this->id]);
95
+		$tokens  = [];
96
+
97
+		foreach ($devices as $device) {
98
+			if (\Core::users()->accessTokenExpiredOrRevoked($device->access_token)) {
99
+				$device->forceDelete();
100
+				continue;
101
+			}
102
+
103
+			$tokens[] = $device->device_token;
104
+		}
105
+
106
+		return $tokens;
107
+	}
108
+
109
+	/**
110
+	 * The channels the user receives notification broadcasts on.
111
+	 *
112
+	 * @return string
113
+	 */
114
+	public function receivesBroadcastNotificationsOn()
115
+	{
116
+		return 'users.'.$this->id;
117
+	}
118
+
119
+	/**
120
+	 * Custom password validation.
121
+	 *
122
+	 * @param  string $password
123
+	 * @return boolean
124
+	 */
125
+	public function validateForPassportPasswordGrant($password)
126
+	{
127
+		if ($password == config('skeleton.social_pass')) {
128
+			return true;
129
+		}
130
+
131
+		return \Hash::check($password, $this->password);
132
+	}
133 133
     
134
-    public static function boot()
135
-    {
136
-        parent::boot();
137
-        AclUser::observe(\App::make('App\Modules\Users\ModelObservers\AclUserObserver'));
138
-    }
134
+	public static function boot()
135
+	{
136
+		parent::boot();
137
+		AclUser::observe(\App::make('App\Modules\Users\ModelObservers\AclUserObserver'));
138
+	}
139 139
 }
Please login to merge, or discard this patch.
src/Modules/Users/Reppsitories/UserRepository.php 1 patch
Indentation   +380 added lines, -380 removed lines patch added patch discarded remove patch
@@ -6,391 +6,391 @@
 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
-    }
19
-
20
-    /**
21
-     * Return the logged in user account.
22
-     *
23
-     * @param  array   $relations
24
-     * @return boolean
25
-     */
26
-    public function account($relations = [])
27
-    {
28
-        $permissions = [];
29
-        $user        = $this->find(\Auth::id(), $relations);
30
-        foreach ($user->groups()->get() as $group) {
31
-            $group->permissions->each(function ($permission) use (&$permissions) {
32
-                $permissions[$permission->model][$permission->id] = $permission->name;
33
-            });
34
-        }
35
-        $user->permissions = $permissions;
36
-
37
-        return $user;
38
-    }
39
-
40
-    /**
41
-     * Check if the logged in user or the given user
42
-     * has the given permissions on the given model.
43
-     *
44
-     * @param  string $nameOfPermission
45
-     * @param  string $model
46
-     * @param  mixed  $user
47
-     * @return boolean
48
-     */
49
-    public function can($nameOfPermission, $model, $user = false)
50
-    {
51
-        $user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52
-        $permissions = [];
53
-
54
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model) {
55
-            $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray());
56
-        });
57
-
58
-        return in_array($nameOfPermission, $permissions);
59
-    }
60
-
61
-    /**
62
-     * Check if the logged in user has the given group.
63
-     *
64
-     * @param  string[] $groups
65
-     * @param  mixed $user
66
-     * @return boolean
67
-     */
68
-    public function hasGroup($groups, $user = false)
69
-    {
70
-        $user = $user ?: $this->find(\Auth::id());
71
-        return $user->groups->whereIn('name', $groups)->count() ? true : false;
72
-    }
73
-
74
-    /**
75
-     * Assign the given group ids to the given user.
76
-     *
77
-     * @param  integer $userId
78
-     * @param  array   $groupIds
79
-     * @return object
80
-     */
81
-    public function assignGroups($userId, $groupIds)
82
-    {
83
-        \DB::transaction(function () use ($userId, $groupIds) {
84
-            $user = $this->find($userId);
85
-            $user->groups()->detach();
86
-            $user->groups()->attach($groupIds);
87
-        });
88
-
89
-        return $this->find($userId);
90
-    }
91
-
92
-
93
-    /**
94
-     * Handle a login request to the application.
95
-     *
96
-     * @param  array   $credentials
97
-     * @param  boolean $adminLogin
98
-     * @return object
99
-     */
100
-    public function login($credentials, $adminLogin = false)
101
-    {
102
-        if (! $user = $this->first(['email' => $credentials['email']])) {
103
-            \ErrorHandler::loginFailed();
104
-        } elseif ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) {
105
-            \ErrorHandler::loginFailed();
106
-        } elseif (! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) {
107
-            \ErrorHandler::loginFailed();
108
-        } elseif ($user->blocked) {
109
-            \ErrorHandler::userIsBlocked();
110
-        } elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
111
-            \ErrorHandler::emailNotConfirmed();
112
-        }
113
-
114
-        return $user;
115
-    }
116
-
117
-    /**
118
-     * Handle a social login request of the none admin to the application.
119
-     *
120
-     * @param  string $authCode
121
-     * @param  string $accessToken
122
-     * @param  string $type
123
-     * @return array
124
-     */
125
-    public function loginSocial($authCode, $accessToken, $type)
126
-    {
127
-        $access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
128
-        $user         = \Socialite::driver($type)->userFromToken($access_token);
129
-
130
-        if (! $user->email) {
131
-            \ErrorHandler::noSocialEmail();
132
-        }
133
-
134
-        if (! $this->model->where('email', $user->email)->first()) {
135
-            $this->register(['email' => $user->email, 'password' => ''], true);
136
-        }
137
-
138
-        $loginProxy = \App::make('App\Modules\Users\Proxy\LoginProxy');
139
-        return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0);
140
-    }
9
+	/**
10
+	 * Init new object.
11
+	 *
12
+	 * @param   AclUser $model
13
+	 * @return  void
14
+	 */
15
+	public function __construct(AclUser $model)
16
+	{
17
+		parent::__construct($model);
18
+	}
19
+
20
+	/**
21
+	 * Return the logged in user account.
22
+	 *
23
+	 * @param  array   $relations
24
+	 * @return boolean
25
+	 */
26
+	public function account($relations = [])
27
+	{
28
+		$permissions = [];
29
+		$user        = $this->find(\Auth::id(), $relations);
30
+		foreach ($user->groups()->get() as $group) {
31
+			$group->permissions->each(function ($permission) use (&$permissions) {
32
+				$permissions[$permission->model][$permission->id] = $permission->name;
33
+			});
34
+		}
35
+		$user->permissions = $permissions;
36
+
37
+		return $user;
38
+	}
39
+
40
+	/**
41
+	 * Check if the logged in user or the given user
42
+	 * has the given permissions on the given model.
43
+	 *
44
+	 * @param  string $nameOfPermission
45
+	 * @param  string $model
46
+	 * @param  mixed  $user
47
+	 * @return boolean
48
+	 */
49
+	public function can($nameOfPermission, $model, $user = false)
50
+	{
51
+		$user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52
+		$permissions = [];
53
+
54
+		$user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model) {
55
+			$permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray());
56
+		});
57
+
58
+		return in_array($nameOfPermission, $permissions);
59
+	}
60
+
61
+	/**
62
+	 * Check if the logged in user has the given group.
63
+	 *
64
+	 * @param  string[] $groups
65
+	 * @param  mixed $user
66
+	 * @return boolean
67
+	 */
68
+	public function hasGroup($groups, $user = false)
69
+	{
70
+		$user = $user ?: $this->find(\Auth::id());
71
+		return $user->groups->whereIn('name', $groups)->count() ? true : false;
72
+	}
73
+
74
+	/**
75
+	 * Assign the given group ids to the given user.
76
+	 *
77
+	 * @param  integer $userId
78
+	 * @param  array   $groupIds
79
+	 * @return object
80
+	 */
81
+	public function assignGroups($userId, $groupIds)
82
+	{
83
+		\DB::transaction(function () use ($userId, $groupIds) {
84
+			$user = $this->find($userId);
85
+			$user->groups()->detach();
86
+			$user->groups()->attach($groupIds);
87
+		});
88
+
89
+		return $this->find($userId);
90
+	}
91
+
92
+
93
+	/**
94
+	 * Handle a login request to the application.
95
+	 *
96
+	 * @param  array   $credentials
97
+	 * @param  boolean $adminLogin
98
+	 * @return object
99
+	 */
100
+	public function login($credentials, $adminLogin = false)
101
+	{
102
+		if (! $user = $this->first(['email' => $credentials['email']])) {
103
+			\ErrorHandler::loginFailed();
104
+		} elseif ($adminLogin && ! $user->groups->whereIn('name', ['Admin'])->count()) {
105
+			\ErrorHandler::loginFailed();
106
+		} elseif (! $adminLogin && $user->groups->whereIn('name', ['Admin'])->count()) {
107
+			\ErrorHandler::loginFailed();
108
+		} elseif ($user->blocked) {
109
+			\ErrorHandler::userIsBlocked();
110
+		} elseif (! config('skeleton.disable_confirm_email') && ! $user->confirmed) {
111
+			\ErrorHandler::emailNotConfirmed();
112
+		}
113
+
114
+		return $user;
115
+	}
116
+
117
+	/**
118
+	 * Handle a social login request of the none admin to the application.
119
+	 *
120
+	 * @param  string $authCode
121
+	 * @param  string $accessToken
122
+	 * @param  string $type
123
+	 * @return array
124
+	 */
125
+	public function loginSocial($authCode, $accessToken, $type)
126
+	{
127
+		$access_token = $authCode ? Arr::get(\Socialite::driver($type)->getAccessTokenResponse($authCode), 'access_token') : $accessToken;
128
+		$user         = \Socialite::driver($type)->userFromToken($access_token);
129
+
130
+		if (! $user->email) {
131
+			\ErrorHandler::noSocialEmail();
132
+		}
133
+
134
+		if (! $this->model->where('email', $user->email)->first()) {
135
+			$this->register(['email' => $user->email, 'password' => ''], true);
136
+		}
137
+
138
+		$loginProxy = \App::make('App\Modules\Users\Proxy\LoginProxy');
139
+		return $loginProxy->login(['email' => $user->email, 'password' => config('skeleton.social_pass')], 0);
140
+	}
141 141
     
142
-    /**
143
-     * Handle a registration request.
144
-     *
145
-     * @param  array   $credentials
146
-     * @param  boolean $skipConfirmEmail
147
-     * @return array
148
-     */
149
-    public function register($credentials, $skipConfirmEmail = false)
150
-    {
151
-        $user = $this->save($credentials);
152
-
153
-        if ($skipConfirmEmail) {
154
-            $user->confirmed = 1;
155
-            $user->save();
156
-        } elseif (! config('skeleton.disable_confirm_email')) {
157
-            $this->sendConfirmationEmail($user->email);
158
-        }
159
-
160
-        return $user;
161
-    }
142
+	/**
143
+	 * Handle a registration request.
144
+	 *
145
+	 * @param  array   $credentials
146
+	 * @param  boolean $skipConfirmEmail
147
+	 * @return array
148
+	 */
149
+	public function register($credentials, $skipConfirmEmail = false)
150
+	{
151
+		$user = $this->save($credentials);
152
+
153
+		if ($skipConfirmEmail) {
154
+			$user->confirmed = 1;
155
+			$user->save();
156
+		} elseif (! config('skeleton.disable_confirm_email')) {
157
+			$this->sendConfirmationEmail($user->email);
158
+		}
159
+
160
+		return $user;
161
+	}
162 162
     
163
-    /**
164
-     * Block the user.
165
-     *
166
-     * @param  integer $userId
167
-     * @return object
168
-     */
169
-    public function block($userId)
170
-    {
171
-        if (! $user = $this->find($userId)) {
172
-            \ErrorHandler::notFound('user');
173
-        }
174
-        if (! $this->hasGroup(['Admin'])) {
175
-            \ErrorHandler::noPermissions();
176
-        } elseif (\Auth::id() == $userId) {
177
-            \ErrorHandler::noPermissions();
178
-        } elseif ($user->groups->pluck('name')->search('Admin', true) !== false) {
179
-            \ErrorHandler::noPermissions();
180
-        }
181
-
182
-        $user->blocked = 1;
183
-        $user->save();
163
+	/**
164
+	 * Block the user.
165
+	 *
166
+	 * @param  integer $userId
167
+	 * @return object
168
+	 */
169
+	public function block($userId)
170
+	{
171
+		if (! $user = $this->find($userId)) {
172
+			\ErrorHandler::notFound('user');
173
+		}
174
+		if (! $this->hasGroup(['Admin'])) {
175
+			\ErrorHandler::noPermissions();
176
+		} elseif (\Auth::id() == $userId) {
177
+			\ErrorHandler::noPermissions();
178
+		} elseif ($user->groups->pluck('name')->search('Admin', true) !== false) {
179
+			\ErrorHandler::noPermissions();
180
+		}
181
+
182
+		$user->blocked = 1;
183
+		$user->save();
184 184
         
185
-        return $user;
186
-    }
187
-
188
-    /**
189
-     * Unblock the user.
190
-     *
191
-     * @param  integer $userId
192
-     * @return object
193
-     */
194
-    public function unblock($userId)
195
-    {
196
-        if (! $this->hasGroup(['Admin'])) {
197
-            \ErrorHandler::noPermissions();
198
-        }
199
-
200
-        $user          = $this->find($userId);
201
-        $user->blocked = 0;
202
-        $user->save();
203
-
204
-        return $user;
205
-    }
206
-
207
-    /**
208
-     * Send a reset link to the given user.
209
-     *
210
-     * @param  string  $email
211
-     * @return void
212
-     */
213
-    public function sendReset($email)
214
-    {
215
-        if (! $user = $this->model->where('email', $email)->first()) {
216
-            \ErrorHandler::notFound('email');
217
-        }
218
-
219
-        $token = \Password::getRepository()->create($user);
220
-        \Core::notifications()->notify($user, 'ResetPassword', $token);
221
-    }
222
-
223
-    /**
224
-     * Reset the given user's password.
225
-     *
226
-     * @param  array  $credentials
227
-     * @return string|null
228
-     */
229
-    public function resetPassword($credentials)
230
-    {
231
-        $response = \Password::reset($credentials, function ($user, $password) {
232
-            $user->password = $password;
233
-            $user->save();
234
-        });
235
-
236
-        switch ($response) {
237
-            case \Password::PASSWORD_RESET:
238
-                return 'success';
239
-
240
-            case \Password::INVALID_TOKEN:
241
-                \ErrorHandler::invalidResetToken('token');
242
-                //no break
243
-
244
-            case \Password::INVALID_PASSWORD:
245
-                \ErrorHandler::invalidResetPassword('email');
246
-                //no break
247
-
248
-            case \Password::INVALID_USER:
249
-                \ErrorHandler::notFound('user');
250
-                //no break
251
-
252
-            default:
253
-                \ErrorHandler::generalError();
254
-        }
255
-    }
256
-
257
-    /**
258
-     * Change the logged in user password.
259
-     *
260
-     * @param  array  $credentials
261
-     * @return void
262
-     */
263
-    public function changePassword($credentials)
264
-    {
265
-        $user = \Auth::user();
266
-        if (! \Hash::check($credentials['old_password'], $user->password)) {
267
-            \ErrorHandler::invalidOldPassword();
268
-        }
269
-
270
-        $user->password = $credentials['password'];
271
-        $user->save();
272
-    }
273
-
274
-    /**
275
-     * Confirm email using the confirmation code.
276
-     *
277
-     * @param  string $confirmationCode
278
-     * @return void
279
-     */
280
-    public function confirmEmail($confirmationCode)
281
-    {
282
-        if (! $user = $this->first(['confirmation_code' => $confirmationCode])) {
283
-            \ErrorHandler::invalidConfirmationCode();
284
-        }
285
-
286
-        $user->confirmed         = 1;
287
-        $user->confirmation_code = null;
288
-        $user->save();
289
-    }
290
-
291
-    /**
292
-     * Send the confirmation mail.
293
-     *
294
-     * @param  string $email
295
-     * @return void
296
-     */
297
-    public function sendConfirmationEmail($email)
298
-    {
299
-        $user = $this->first(['email' => $email]);
300
-        if ($user->confirmed) {
301
-            \ErrorHandler::emailAlreadyConfirmed();
302
-        }
303
-
304
-        $user->confirmed         = 0;
305
-        $user->confirmation_code = sha1(microtime());
306
-        $user->save();
307
-        \Core::notifications()->notify($user, 'ConfirmEmail');
308
-    }
309
-
310
-    /**
311
-     * Paginate all users in the given group based on the given conditions.
312
-     *
313
-     * @param  string  $groupName
314
-     * @param  array   $relations
315
-     * @param  integer $perPage
316
-     * @param  string  $sortBy
317
-     * @param  boolean $desc
318
-     * @return \Illuminate\Http\Response
319
-     */
320
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
321
-    {
322
-        unset($conditions['page']);
323
-        $conditions = $this->constructConditions($conditions, $this->model);
324
-        $sort       = $desc ? 'desc' : 'asc';
325
-        $model      = $this->model->with($relations);
326
-
327
-        $model->whereHas('groups', function ($q) use ($groupName) {
328
-            $q->where('name', $groupName);
329
-        });
185
+		return $user;
186
+	}
187
+
188
+	/**
189
+	 * Unblock the user.
190
+	 *
191
+	 * @param  integer $userId
192
+	 * @return object
193
+	 */
194
+	public function unblock($userId)
195
+	{
196
+		if (! $this->hasGroup(['Admin'])) {
197
+			\ErrorHandler::noPermissions();
198
+		}
199
+
200
+		$user          = $this->find($userId);
201
+		$user->blocked = 0;
202
+		$user->save();
203
+
204
+		return $user;
205
+	}
206
+
207
+	/**
208
+	 * Send a reset link to the given user.
209
+	 *
210
+	 * @param  string  $email
211
+	 * @return void
212
+	 */
213
+	public function sendReset($email)
214
+	{
215
+		if (! $user = $this->model->where('email', $email)->first()) {
216
+			\ErrorHandler::notFound('email');
217
+		}
218
+
219
+		$token = \Password::getRepository()->create($user);
220
+		\Core::notifications()->notify($user, 'ResetPassword', $token);
221
+	}
222
+
223
+	/**
224
+	 * Reset the given user's password.
225
+	 *
226
+	 * @param  array  $credentials
227
+	 * @return string|null
228
+	 */
229
+	public function resetPassword($credentials)
230
+	{
231
+		$response = \Password::reset($credentials, function ($user, $password) {
232
+			$user->password = $password;
233
+			$user->save();
234
+		});
235
+
236
+		switch ($response) {
237
+			case \Password::PASSWORD_RESET:
238
+				return 'success';
239
+
240
+			case \Password::INVALID_TOKEN:
241
+				\ErrorHandler::invalidResetToken('token');
242
+				//no break
243
+
244
+			case \Password::INVALID_PASSWORD:
245
+				\ErrorHandler::invalidResetPassword('email');
246
+				//no break
247
+
248
+			case \Password::INVALID_USER:
249
+				\ErrorHandler::notFound('user');
250
+				//no break
251
+
252
+			default:
253
+				\ErrorHandler::generalError();
254
+		}
255
+	}
256
+
257
+	/**
258
+	 * Change the logged in user password.
259
+	 *
260
+	 * @param  array  $credentials
261
+	 * @return void
262
+	 */
263
+	public function changePassword($credentials)
264
+	{
265
+		$user = \Auth::user();
266
+		if (! \Hash::check($credentials['old_password'], $user->password)) {
267
+			\ErrorHandler::invalidOldPassword();
268
+		}
269
+
270
+		$user->password = $credentials['password'];
271
+		$user->save();
272
+	}
273
+
274
+	/**
275
+	 * Confirm email using the confirmation code.
276
+	 *
277
+	 * @param  string $confirmationCode
278
+	 * @return void
279
+	 */
280
+	public function confirmEmail($confirmationCode)
281
+	{
282
+		if (! $user = $this->first(['confirmation_code' => $confirmationCode])) {
283
+			\ErrorHandler::invalidConfirmationCode();
284
+		}
285
+
286
+		$user->confirmed         = 1;
287
+		$user->confirmation_code = null;
288
+		$user->save();
289
+	}
290
+
291
+	/**
292
+	 * Send the confirmation mail.
293
+	 *
294
+	 * @param  string $email
295
+	 * @return void
296
+	 */
297
+	public function sendConfirmationEmail($email)
298
+	{
299
+		$user = $this->first(['email' => $email]);
300
+		if ($user->confirmed) {
301
+			\ErrorHandler::emailAlreadyConfirmed();
302
+		}
303
+
304
+		$user->confirmed         = 0;
305
+		$user->confirmation_code = sha1(microtime());
306
+		$user->save();
307
+		\Core::notifications()->notify($user, 'ConfirmEmail');
308
+	}
309
+
310
+	/**
311
+	 * Paginate all users in the given group based on the given conditions.
312
+	 *
313
+	 * @param  string  $groupName
314
+	 * @param  array   $relations
315
+	 * @param  integer $perPage
316
+	 * @param  string  $sortBy
317
+	 * @param  boolean $desc
318
+	 * @return \Illuminate\Http\Response
319
+	 */
320
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
321
+	{
322
+		unset($conditions['page']);
323
+		$conditions = $this->constructConditions($conditions, $this->model);
324
+		$sort       = $desc ? 'desc' : 'asc';
325
+		$model      = $this->model->with($relations);
326
+
327
+		$model->whereHas('groups', function ($q) use ($groupName) {
328
+			$q->where('name', $groupName);
329
+		});
330 330
 
331 331
         
332
-        if (count($conditions['conditionValues'])) {
333
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
334
-        }
335
-
336
-        if ($perPage) {
337
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
338
-        }
339
-
340
-        return $model->orderBy($sortBy, $sort)->get();
341
-    }
342
-
343
-    /**
344
-     * Save the given data to the logged in user.
345
-     *
346
-     * @param  array $data
347
-     * @return void
348
-     */
349
-    public function saveProfile($data)
350
-    {
351
-        if (Arr::has($data, 'profile_picture')) {
352
-            $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
353
-        }
332
+		if (count($conditions['conditionValues'])) {
333
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
334
+		}
335
+
336
+		if ($perPage) {
337
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
338
+		}
339
+
340
+		return $model->orderBy($sortBy, $sort)->get();
341
+	}
342
+
343
+	/**
344
+	 * Save the given data to the logged in user.
345
+	 *
346
+	 * @param  array $data
347
+	 * @return void
348
+	 */
349
+	public function saveProfile($data)
350
+	{
351
+		if (Arr::has($data, 'profile_picture')) {
352
+			$data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
353
+		}
354 354
         
355
-        $data['id'] = \Auth::id();
356
-        return $this->save($data);
357
-    }
358
-
359
-    /**
360
-     * Ensure access token hasn't expired or revoked.
361
-     *
362
-     * @param  string $accessToken
363
-     * @return boolean
364
-     */
365
-    public function accessTokenExpiredOrRevoked($accessToken)
366
-    {
367
-        $accessTokenId = json_decode($accessToken, true)['id'];
368
-        $accessToken   = \DB::table('oauth_access_tokens')
369
-                ->where('id', $accessTokenId)
370
-                ->first();
355
+		$data['id'] = \Auth::id();
356
+		return $this->save($data);
357
+	}
358
+
359
+	/**
360
+	 * Ensure access token hasn't expired or revoked.
361
+	 *
362
+	 * @param  string $accessToken
363
+	 * @return boolean
364
+	 */
365
+	public function accessTokenExpiredOrRevoked($accessToken)
366
+	{
367
+		$accessTokenId = json_decode($accessToken, true)['id'];
368
+		$accessToken   = \DB::table('oauth_access_tokens')
369
+				->where('id', $accessTokenId)
370
+				->first();
371 371
         
372
-        if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) {
373
-            return true;
374
-        }
375
-
376
-        return false;
377
-    }
378
-
379
-    /**
380
-     * Revoke the given access token and all
381
-     * associated refresh tokens.
382
-     *
383
-     * @param  oject $accessToken
384
-     * @return void
385
-     */
386
-    public function revokeAccessToken($accessToken)
387
-    {
388
-        \DB::table('oauth_refresh_tokens')
389
-            ->where('access_token_id', $accessToken->id)
390
-            ->update([
391
-                'revoked' => true
392
-            ]);
393
-
394
-        $accessToken->revoke();
395
-    }
372
+		if (\Carbon\Carbon::parse($accessToken->expires_at)->isPast() || $accessToken->revoked) {
373
+			return true;
374
+		}
375
+
376
+		return false;
377
+	}
378
+
379
+	/**
380
+	 * Revoke the given access token and all
381
+	 * associated refresh tokens.
382
+	 *
383
+	 * @param  oject $accessToken
384
+	 * @return void
385
+	 */
386
+	public function revokeAccessToken($accessToken)
387
+	{
388
+		\DB::table('oauth_refresh_tokens')
389
+			->where('access_token_id', $accessToken->id)
390
+			->update([
391
+				'revoked' => true
392
+			]);
393
+
394
+		$accessToken->revoke();
395
+	}
396 396
 }
Please login to merge, or discard this patch.
src/Modules/Users/Http/Resources/AclUser.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -9,32 +9,32 @@
 block discarded – undo
9 9
 
10 10
 class AclUser extends JsonResource
11 11
 {
12
-    /**
13
-     * Transform the resource into an array.
14
-     *
15
-     * @param Request $request
16
-     * @return array
17
-     */
18
-    public function toArray($request)
19
-    {
20
-        if (! $this->resource) {
21
-            return [];
22
-        }
12
+	/**
13
+	 * Transform the resource into an array.
14
+	 *
15
+	 * @param Request $request
16
+	 * @return array
17
+	 */
18
+	public function toArray($request)
19
+	{
20
+		if (! $this->resource) {
21
+			return [];
22
+		}
23 23
 
24
-        return [
25
-            'id' => $this->id,
26
-            'name' => $this->name,
27
-            'email' => $this->email,
28
-            'profilePicture' => $this->profile_picture,
29
-            'notifications' => NotificationResource::collection($this->whenLoaded('notifications')),
30
-            'readNotifications' => NotificationResource::collection($this->whenLoaded('readNotifications')),
31
-            'unreadNotifications' => NotificationResource::collection($this->whenLoaded('unreadNotifications')),
32
-            'groups' => AclGroupResource::collection($this->whenLoaded('groups')),
33
-            'oauthClients' => OauthClientResource::collection($this->whenLoaded('oauthClients')),
34
-            'locale' => $this->locale,
35
-            'timezone' => $this->timezone,
36
-            'created_at' => $this->created_at,
37
-            'updated_at' => $this->updated_at,
38
-        ];
39
-    }
24
+		return [
25
+			'id' => $this->id,
26
+			'name' => $this->name,
27
+			'email' => $this->email,
28
+			'profilePicture' => $this->profile_picture,
29
+			'notifications' => NotificationResource::collection($this->whenLoaded('notifications')),
30
+			'readNotifications' => NotificationResource::collection($this->whenLoaded('readNotifications')),
31
+			'unreadNotifications' => NotificationResource::collection($this->whenLoaded('unreadNotifications')),
32
+			'groups' => AclGroupResource::collection($this->whenLoaded('groups')),
33
+			'oauthClients' => OauthClientResource::collection($this->whenLoaded('oauthClients')),
34
+			'locale' => $this->locale,
35
+			'timezone' => $this->timezone,
36
+			'created_at' => $this->created_at,
37
+			'updated_at' => $this->updated_at,
38
+		];
39
+	}
40 40
 }
Please login to merge, or discard this patch.
src/Modules/Users/Http/Controllers/UserController.php 1 patch
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -25,239 +25,239 @@
 block discarded – undo
25 25
 
26 26
 class UserController extends BaseApiController
27 27
 {
28
-    /**
29
-     * List of all route actions that the base api controller
30
-     * will skip permissions check for them.
31
-     * @var array
32
-     */
33
-    protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account'];
28
+	/**
29
+	 * List of all route actions that the base api controller
30
+	 * will skip permissions check for them.
31
+	 * @var array
32
+	 */
33
+	protected $skipPermissionCheck = ['account', 'logout', 'changePassword', 'saveProfile', 'account'];
34 34
 
35
-    /**
36
-     * List of all route actions that the base api controller
37
-     * will skip login check for them.
38
-     * @var array
39
-     */
40
-    protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation'];
35
+	/**
36
+	 * List of all route actions that the base api controller
37
+	 * will skip login check for them.
38
+	 * @var array
39
+	 */
40
+	protected $skipLoginCheck = ['login', 'loginSocial', 'register', 'sendReset', 'resetPassword', 'refreshToken', 'confirmEmail', 'resendEmailConfirmation'];
41 41
 
42
-    /**
43
-     * The loginProxy implementation.
44
-     *
45
-     * @var App\Modules\Users\Proxy\LoginProxy
46
-     */
47
-    protected $loginProxy;
42
+	/**
43
+	 * The loginProxy implementation.
44
+	 *
45
+	 * @var App\Modules\Users\Proxy\LoginProxy
46
+	 */
47
+	protected $loginProxy;
48 48
 
49
-    /**
50
-     * Init new object.
51
-     *
52
-     * @param   LoginProxy     $loginProxy
53
-     * @param   UserRepository $repo
54
-     * @param   CoreConfig     $config
55
-     * @return  void
56
-     */
57
-    public function __construct(LoginProxy $loginProxy, UserRepository $repo, CoreConfig $config)
58
-    {
59
-        $this->loginProxy = $loginProxy;
60
-        parent::__construct($repo, $config, 'App\Modules\Users\Http\Resources\AclUser');
61
-    }
49
+	/**
50
+	 * Init new object.
51
+	 *
52
+	 * @param   LoginProxy     $loginProxy
53
+	 * @param   UserRepository $repo
54
+	 * @param   CoreConfig     $config
55
+	 * @return  void
56
+	 */
57
+	public function __construct(LoginProxy $loginProxy, UserRepository $repo, CoreConfig $config)
58
+	{
59
+		$this->loginProxy = $loginProxy;
60
+		parent::__construct($repo, $config, 'App\Modules\Users\Http\Resources\AclUser');
61
+	}
62 62
 
63
-    /**
64
-     * Insert the given model to storage.
65
-     *
66
-     * @param InsertUser $request
67
-     * @return \Illuminate\Http\Response
68
-     */
69
-    public function insert(InsertUser $request)
70
-    {
71
-        return new $this->modelResource($this->repo->save($request->all()));
72
-    }
63
+	/**
64
+	 * Insert the given model to storage.
65
+	 *
66
+	 * @param InsertUser $request
67
+	 * @return \Illuminate\Http\Response
68
+	 */
69
+	public function insert(InsertUser $request)
70
+	{
71
+		return new $this->modelResource($this->repo->save($request->all()));
72
+	}
73 73
 
74
-    /**
75
-     * Update the given model to storage.
76
-     *
77
-     * @param UpdateUser $request
78
-     * @return \Illuminate\Http\Response
79
-     */
80
-    public function update(UpdateUser $request)
81
-    {
82
-        return new $this->modelResource($this->repo->save($request->all()));
83
-    }
74
+	/**
75
+	 * Update the given model to storage.
76
+	 *
77
+	 * @param UpdateUser $request
78
+	 * @return \Illuminate\Http\Response
79
+	 */
80
+	public function update(UpdateUser $request)
81
+	{
82
+		return new $this->modelResource($this->repo->save($request->all()));
83
+	}
84 84
 
85
-    /**
86
-     * Return the logged in user account.
87
-     *
88
-     * @return \Illuminate\Http\Response
89
-     */
90
-    public function account()
91
-    {
92
-        return new $this->modelResource($this->repo->account($this->relations));
93
-    }
85
+	/**
86
+	 * Return the logged in user account.
87
+	 *
88
+	 * @return \Illuminate\Http\Response
89
+	 */
90
+	public function account()
91
+	{
92
+		return new $this->modelResource($this->repo->account($this->relations));
93
+	}
94 94
 
95
-    /**
96
-     * Block the user.
97
-     *
98
-     * @param  integer  $id Id of the user.
99
-     * @return \Illuminate\Http\Response
100
-     */
101
-    public function block($id)
102
-    {
103
-        return new $this->modelResource($this->repo->block($id));
104
-    }
95
+	/**
96
+	 * Block the user.
97
+	 *
98
+	 * @param  integer  $id Id of the user.
99
+	 * @return \Illuminate\Http\Response
100
+	 */
101
+	public function block($id)
102
+	{
103
+		return new $this->modelResource($this->repo->block($id));
104
+	}
105 105
 
106
-    /**
107
-     * Unblock the user.
108
-     *
109
-     * @param  integer  $id Id of the user.
110
-     * @return \Illuminate\Http\Response
111
-     */
112
-    public function unblock($id)
113
-    {
114
-        return new $this->modelResource($this->repo->unblock($id));
115
-    }
106
+	/**
107
+	 * Unblock the user.
108
+	 *
109
+	 * @param  integer  $id Id of the user.
110
+	 * @return \Illuminate\Http\Response
111
+	 */
112
+	public function unblock($id)
113
+	{
114
+		return new $this->modelResource($this->repo->unblock($id));
115
+	}
116 116
 
117
-    /**
118
-     * Logout the user.
119
-     *
120
-     * @return \Illuminate\Http\Response
121
-     */
122
-    public function logout()
123
-    {
124
-        return new GeneralResource($this->loginProxy->logout());
125
-    }
117
+	/**
118
+	 * Logout the user.
119
+	 *
120
+	 * @return \Illuminate\Http\Response
121
+	 */
122
+	public function logout()
123
+	{
124
+		return new GeneralResource($this->loginProxy->logout());
125
+	}
126 126
 
127
-    /**
128
-     * Handle a registration request.
129
-     *
130
-     * @param Register $request
131
-     * @return \Illuminate\Http\Response
132
-     */
133
-    public function register(Register $request)
134
-    {
135
-        return new $this->modelResource($this->repo->register($request->only('name', 'email', 'password')));
136
-    }
127
+	/**
128
+	 * Handle a registration request.
129
+	 *
130
+	 * @param Register $request
131
+	 * @return \Illuminate\Http\Response
132
+	 */
133
+	public function register(Register $request)
134
+	{
135
+		return new $this->modelResource($this->repo->register($request->only('name', 'email', 'password')));
136
+	}
137 137
 
138
-    /**
139
-     * Handle a login request to the application.
140
-     *
141
-     * @param Login $request
142
-     * @return \Illuminate\Http\Response
143
-     */
144
-    public function login(Login $request)
145
-    {
146
-        $result = $this->loginProxy->login($request->only('email', 'password'), $request->get('admin'));
138
+	/**
139
+	 * Handle a login request to the application.
140
+	 *
141
+	 * @param Login $request
142
+	 * @return \Illuminate\Http\Response
143
+	 */
144
+	public function login(Login $request)
145
+	{
146
+		$result = $this->loginProxy->login($request->only('email', 'password'), $request->get('admin'));
147 147
 
148
-        return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
149
-    }
148
+		return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
149
+	}
150 150
 
151
-    /**
152
-     * Handle a social login request of the none admin to the application.
153
-     *
154
-     * @param LoginSocial $request
155
-     * @return \Illuminate\Http\Response
156
-     */
157
-    public function loginSocial(LoginSocial $request)
158
-    {
159
-        $result = $this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type'));
151
+	/**
152
+	 * Handle a social login request of the none admin to the application.
153
+	 *
154
+	 * @param LoginSocial $request
155
+	 * @return \Illuminate\Http\Response
156
+	 */
157
+	public function loginSocial(LoginSocial $request)
158
+	{
159
+		$result = $this->repo->loginSocial($request->get('auth_code'), $request->get('access_token'), $request->get('type'));
160 160
 
161
-        return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
162
-    }
161
+		return (new $this->modelResource($result['user']))->additional(['meta' => $result['tokens']]);
162
+	}
163 163
 
164
-    /**
165
-     * Assign the given groups to the given user.
166
-     *
167
-     * @param AssignGroups $request
168
-     * @return \Illuminate\Http\Response
169
-     */
170
-    public function assignGroups(AssignGroups $request)
171
-    {
172
-        return new $this->modelResource($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')));
173
-    }
164
+	/**
165
+	 * Assign the given groups to the given user.
166
+	 *
167
+	 * @param AssignGroups $request
168
+	 * @return \Illuminate\Http\Response
169
+	 */
170
+	public function assignGroups(AssignGroups $request)
171
+	{
172
+		return new $this->modelResource($this->repo->assignGroups($request->get('user_id'), $request->get('group_ids')));
173
+	}
174 174
 
175
-    /**
176
-     * Send a reset link to the given user.
177
-     *
178
-     * @param SendReset $request
179
-     * @return \Illuminate\Http\Response
180
-     */
181
-    public function sendReset(SendReset $request)
182
-    {
183
-        return new GeneralResource($this->repo->sendReset($request->get('email')));
184
-    }
175
+	/**
176
+	 * Send a reset link to the given user.
177
+	 *
178
+	 * @param SendReset $request
179
+	 * @return \Illuminate\Http\Response
180
+	 */
181
+	public function sendReset(SendReset $request)
182
+	{
183
+		return new GeneralResource($this->repo->sendReset($request->get('email')));
184
+	}
185 185
 
186
-    /**
187
-     * Reset the given user's password.
188
-     *
189
-     * @param ResetPassword $request
190
-     * @return \Illuminate\Http\Response
191
-     */
192
-    public function resetPassword(ResetPassword $request)
193
-    {
194
-        return new GeneralResource($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')));
195
-    }
186
+	/**
187
+	 * Reset the given user's password.
188
+	 *
189
+	 * @param ResetPassword $request
190
+	 * @return \Illuminate\Http\Response
191
+	 */
192
+	public function resetPassword(ResetPassword $request)
193
+	{
194
+		return new GeneralResource($this->repo->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')));
195
+	}
196 196
 
197
-    /**
198
-     * Change the logged in user password.
199
-     *
200
-     * @param ChangePassword $request
201
-     * @return \Illuminate\Http\Response
202
-     */
203
-    public function changePassword(ChangePassword $request)
204
-    {
205
-        return new GeneralResource($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')));
206
-    }
197
+	/**
198
+	 * Change the logged in user password.
199
+	 *
200
+	 * @param ChangePassword $request
201
+	 * @return \Illuminate\Http\Response
202
+	 */
203
+	public function changePassword(ChangePassword $request)
204
+	{
205
+		return new GeneralResource($this->repo->changePassword($request->only('old_password', 'password', 'password_confirmation')));
206
+	}
207 207
 
208
-    /**
209
-     * Confirm email using the confirmation code.
210
-     *
211
-     * @param ConfirmEmail $request
212
-     * @return \Illuminate\Http\Response
213
-     */
214
-    public function confirmEmail(ConfirmEmail $request)
215
-    {
216
-        return new GeneralResource($this->repo->confirmEmail($request->only('confirmation_code')));
217
-    }
208
+	/**
209
+	 * Confirm email using the confirmation code.
210
+	 *
211
+	 * @param ConfirmEmail $request
212
+	 * @return \Illuminate\Http\Response
213
+	 */
214
+	public function confirmEmail(ConfirmEmail $request)
215
+	{
216
+		return new GeneralResource($this->repo->confirmEmail($request->only('confirmation_code')));
217
+	}
218 218
 
219
-    /**
220
-     * Resend the email confirmation mail.
221
-     *
222
-     * @param ResendEmailConfirmation $request
223
-     * @return \Illuminate\Http\Response
224
-     */
225
-    public function resendEmailConfirmation(ResendEmailConfirmation $request)
226
-    {
227
-        return new GeneralResource($this->repo->sendConfirmationEmail($request->get('email')));
228
-    }
219
+	/**
220
+	 * Resend the email confirmation mail.
221
+	 *
222
+	 * @param ResendEmailConfirmation $request
223
+	 * @return \Illuminate\Http\Response
224
+	 */
225
+	public function resendEmailConfirmation(ResendEmailConfirmation $request)
226
+	{
227
+		return new GeneralResource($this->repo->sendConfirmationEmail($request->get('email')));
228
+	}
229 229
 
230
-    /**
231
-     * Refresh the expired login token.
232
-     *
233
-     * @param RefreshToken $request
234
-     * @return \Illuminate\Http\Response
235
-     */
236
-    public function refreshToken(RefreshToken $request)
237
-    {
238
-        return new GeneralResource($this->loginProxy->refreshToken($request->get('refresh_token')));
239
-    }
230
+	/**
231
+	 * Refresh the expired login token.
232
+	 *
233
+	 * @param RefreshToken $request
234
+	 * @return \Illuminate\Http\Response
235
+	 */
236
+	public function refreshToken(RefreshToken $request)
237
+	{
238
+		return new GeneralResource($this->loginProxy->refreshToken($request->get('refresh_token')));
239
+	}
240 240
 
241
-    /**
242
-     * Paginate all users with in the given group.
243
-     *
244
-     * @param Request $request
245
-     * @param  string $groupName The name of the requested group.
246
-     * @return \Illuminate\Http\Response
247
-     */
248
-    public function group(Request $request, $groupName)
249
-    {
250
-        return $this->modelResource::collection($this->repo->group($request->all(), $groupName, $this->relations, $request->query('perPage'), $request->query('sortBy'), $request->query('desc')));
251
-    }
241
+	/**
242
+	 * Paginate all users with in the given group.
243
+	 *
244
+	 * @param Request $request
245
+	 * @param  string $groupName The name of the requested group.
246
+	 * @return \Illuminate\Http\Response
247
+	 */
248
+	public function group(Request $request, $groupName)
249
+	{
250
+		return $this->modelResource::collection($this->repo->group($request->all(), $groupName, $this->relations, $request->query('perPage'), $request->query('sortBy'), $request->query('desc')));
251
+	}
252 252
 
253
-    /**
254
-     * Save the given data to the logged in user.
255
-     *
256
-     * @param SaveProfile $request
257
-     * @return \Illuminate\Http\Response
258
-     */
259
-    public function saveProfile(SaveProfile $request)
260
-    {
261
-        return new $this->modelResource($this->repo->saveProfile($request->only('name', 'email', 'profile_picture')));
262
-    }
253
+	/**
254
+	 * Save the given data to the logged in user.
255
+	 *
256
+	 * @param SaveProfile $request
257
+	 * @return \Illuminate\Http\Response
258
+	 */
259
+	public function saveProfile(SaveProfile $request)
260
+	{
261
+		return new $this->modelResource($this->repo->saveProfile($request->only('name', 'email', 'profile_picture')));
262
+	}
263 263
 }
Please login to merge, or discard this patch.
src/Modules/PushNotificationDevices/Routes/api.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@
 block discarded – undo
15 15
 
16 16
 Route::group(['prefix' => 'push/notification/devices'], function () {
17 17
         
18
-    Route::get('/', 'PushNotificationDeviceController@index');
19
-    Route::get('/{id}', 'PushNotificationDeviceController@find');
20
-    Route::post('/', 'PushNotificationDeviceController@insert');
21
-    Route::put('/', 'PushNotificationDeviceController@update');
22
-    Route::delete('/{id}', 'PushNotificationDeviceController@delete');
23
-    Route::get('list/deleted', 'PushNotificationDeviceController@deleted');
24
-    Route::patch('restore/{id}', 'PushNotificationDeviceController@restore');
25
-    Route::post('register/device', 'PushNotificationDeviceController@registerDevice');
18
+	Route::get('/', 'PushNotificationDeviceController@index');
19
+	Route::get('/{id}', 'PushNotificationDeviceController@find');
20
+	Route::post('/', 'PushNotificationDeviceController@insert');
21
+	Route::put('/', 'PushNotificationDeviceController@update');
22
+	Route::delete('/{id}', 'PushNotificationDeviceController@delete');
23
+	Route::get('list/deleted', 'PushNotificationDeviceController@deleted');
24
+	Route::patch('restore/{id}', 'PushNotificationDeviceController@restore');
25
+	Route::post('register/device', 'PushNotificationDeviceController@registerDevice');
26 26
 });
27 27
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/PushNotificationDevices/Providers/ModuleServiceProvider.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -6,27 +6,27 @@
 block discarded – undo
6 6
 
7 7
 class ModuleServiceProvider extends ServiceProvider
8 8
 {
9
-    /**
10
-     * Bootstrap the module services.
11
-     *
12
-     * @return void
13
-     */
14
-    public function boot()
15
-    {
16
-        $this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'push-notification-devices');
17
-        $this->loadViewsFrom(__DIR__.'/../Resources/Views', 'push-notification-devices');
9
+	/**
10
+	 * Bootstrap the module services.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function boot()
15
+	{
16
+		$this->loadTranslationsFrom(__DIR__.'/../Resources/Lang', 'push-notification-devices');
17
+		$this->loadViewsFrom(__DIR__.'/../Resources/Views', 'push-notification-devices');
18 18
 
19
-        $this->loadMigrationsFrom(module_path('push-notification-devices', 'Database/Migrations', 'app'));
20
-        $this->loadFactoriesFrom(module_path('push-notification-devices', 'Database/Factories', 'app'));
21
-    }
19
+		$this->loadMigrationsFrom(module_path('push-notification-devices', 'Database/Migrations', 'app'));
20
+		$this->loadFactoriesFrom(module_path('push-notification-devices', 'Database/Factories', 'app'));
21
+	}
22 22
 
23
-    /**
24
-     * Register the module services.
25
-     *
26
-     * @return void
27
-     */
28
-    public function register()
29
-    {
30
-        $this->app->register(RouteServiceProvider::class);
31
-    }
23
+	/**
24
+	 * Register the module services.
25
+	 *
26
+	 * @return void
27
+	 */
28
+	public function register()
29
+	{
30
+		$this->app->register(RouteServiceProvider::class);
31
+	}
32 32
 }
Please login to merge, or discard this patch.
src/Modules/PushNotificationDevices/Providers/RouteServiceProvider.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -7,73 +7,73 @@
 block discarded – undo
7 7
 
8 8
 class RouteServiceProvider extends ServiceProvider
9 9
 {
10
-    /**
11
-     * This namespace is applied to your controller routes.
12
-     *
13
-     * In addition, it is set as the URL generator's root namespace.
14
-     *
15
-     * @var string
16
-     */
17
-    protected $namespace = 'App\Modules\PushNotificationDevices\Http\Controllers';
10
+	/**
11
+	 * This namespace is applied to your controller routes.
12
+	 *
13
+	 * In addition, it is set as the URL generator's root namespace.
14
+	 *
15
+	 * @var string
16
+	 */
17
+	protected $namespace = 'App\Modules\PushNotificationDevices\Http\Controllers';
18 18
 
19
-    /**
20
-     * Define your route model bindings, pattern filters, etc.
21
-     *
22
-     * @return void
23
-     */
24
-    public function boot()
25
-    {
26
-        //
19
+	/**
20
+	 * Define your route model bindings, pattern filters, etc.
21
+	 *
22
+	 * @return void
23
+	 */
24
+	public function boot()
25
+	{
26
+		//
27 27
 
28
-        parent::boot();
29
-    }
28
+		parent::boot();
29
+	}
30 30
 
31
-    /**
32
-     * Define the routes for the module.
33
-     *
34
-     * @return void
35
-     */
36
-    public function map()
37
-    {
38
-        $this->mapWebRoutes();
31
+	/**
32
+	 * Define the routes for the module.
33
+	 *
34
+	 * @return void
35
+	 */
36
+	public function map()
37
+	{
38
+		$this->mapWebRoutes();
39 39
 
40
-        $this->mapApiRoutes();
40
+		$this->mapApiRoutes();
41 41
 
42
-        //
43
-    }
42
+		//
43
+	}
44 44
 
45
-    /**
46
-     * Define the "web" routes for the module.
47
-     *
48
-     * These routes all receive session state, CSRF protection, etc.
49
-     *
50
-     * @return void
51
-     */
52
-    protected function mapWebRoutes()
53
-    {
54
-        Route::group([
55
-            'middleware' => 'web',
56
-            'namespace'  => $this->namespace,
57
-        ], function ($router) {
58
-            require module_path('push-notification-devices', 'Routes/web.php', 'app');
59
-        });
60
-    }
45
+	/**
46
+	 * Define the "web" routes for the module.
47
+	 *
48
+	 * These routes all receive session state, CSRF protection, etc.
49
+	 *
50
+	 * @return void
51
+	 */
52
+	protected function mapWebRoutes()
53
+	{
54
+		Route::group([
55
+			'middleware' => 'web',
56
+			'namespace'  => $this->namespace,
57
+		], function ($router) {
58
+			require module_path('push-notification-devices', 'Routes/web.php', 'app');
59
+		});
60
+	}
61 61
 
62
-    /**
63
-     * Define the "api" routes for the module.
64
-     *
65
-     * These routes are typically stateless.
66
-     *
67
-     * @return void
68
-     */
69
-    protected function mapApiRoutes()
70
-    {
71
-        Route::group([
72
-            'middleware' => 'api',
73
-            'namespace'  => $this->namespace,
74
-            'prefix'     => 'api',
75
-        ], function ($router) {
76
-            require module_path('push-notification-devices', 'Routes/api.php', 'app');
77
-        });
78
-    }
62
+	/**
63
+	 * Define the "api" routes for the module.
64
+	 *
65
+	 * These routes are typically stateless.
66
+	 *
67
+	 * @return void
68
+	 */
69
+	protected function mapApiRoutes()
70
+	{
71
+		Route::group([
72
+			'middleware' => 'api',
73
+			'namespace'  => $this->namespace,
74
+			'prefix'     => 'api',
75
+		], function ($router) {
76
+			require module_path('push-notification-devices', 'Routes/api.php', 'app');
77
+		});
78
+	}
79 79
 }
Please login to merge, or discard this patch.
Database/Factories/PushNotificationDeviceFactory.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 $factory->define(App\Modules\PushNotificationDevices\PushNotificationDevice::class, function (Faker\Generator $faker) {
4
-    return [
5
-        'device_token' => $faker->sha1(),
6
-        'user_id'      => $faker->randomDigitNotNull(),
7
-        'created_at'   => $faker->dateTimeBetween('-1 years', 'now'),
8
-        'updated_at'   => $faker->dateTimeBetween('-1 years', 'now')
9
-    ];
4
+	return [
5
+		'device_token' => $faker->sha1(),
6
+		'user_id'      => $faker->randomDigitNotNull(),
7
+		'created_at'   => $faker->dateTimeBetween('-1 years', 'now'),
8
+		'updated_at'   => $faker->dateTimeBetween('-1 years', 'now')
9
+	];
10 10
 });
Please login to merge, or discard this patch.
Modules/PushNotificationDevices/Database/Seeds/AssignRelationsSeeder.php 1 patch
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
-        $adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id;
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		$adminGroupId = \DB::table('groups')->where('name', 'admin')->select('id')->first()->id;
17 17
 
18
-        /**
19
-         * Assign the permissions to the admin group.
20
-         */
21
-        \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['pushNotificationDevice'])->each(function ($permission) use ($adminGroupId) {
22
-            \DB::table('groups_permissions')->insert(
23
-                [
24
-                'permission_id' => $permission->id,
25
-                'group_id'      => $adminGroupId,
26
-                'created_at'    => \DB::raw('NOW()'),
27
-                'updated_at'    => \DB::raw('NOW()')
28
-                ]
29
-            );
30
-        });
31
-    }
18
+		/**
19
+		 * Assign the permissions to the admin group.
20
+		 */
21
+		\DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['pushNotificationDevice'])->each(function ($permission) use ($adminGroupId) {
22
+			\DB::table('groups_permissions')->insert(
23
+				[
24
+				'permission_id' => $permission->id,
25
+				'group_id'      => $adminGroupId,
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.