Completed
Push — master ( 5049fe...5fd7f0 )
by Sherif
02:43
created
src/Modules/V1/Acl/Repositories/UserRepository.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -202,7 +202,7 @@
 block discarded – undo
202 202
      * Reset the given user's password.
203 203
      *
204 204
      * @param  array  $credentials
205
-     * @return integer
205
+     * @return false|null
206 206
      */
207 207
     public function resetPassword($credentials)
208 208
     {
Please login to merge, or discard this patch.
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -4,232 +4,232 @@
 block discarded – undo
4 4
 
5 5
 class UserRepository extends AbstractRepository
6 6
 {
7
-    /**
8
-     * Return the model full namespace.
9
-     * 
10
-     * @return string
11
-     */
12
-    protected function getModel()
13
-    {
14
-        return 'App\Modules\V1\Acl\AclUser';
15
-    }
16
-
17
-    /**
18
-     * Check if the logged in user or the given user 
19
-     * has the given permissions on the given model.
20
-     * 
21
-     * @param  string  $nameOfPermission
22
-     * @param  string  $model            
23
-     * @param  boolean $user
24
-     * @return boolean
25
-     */
26
-    public function can($nameOfPermission, $model, $user = false )
27
-    {       
28
-        $user        = $user ?: \JWTAuth::parseToken()->authenticate();
29
-        $permissions = [];
30
-        \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
31
-            $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
32
-        });
7
+	/**
8
+	 * Return the model full namespace.
9
+	 * 
10
+	 * @return string
11
+	 */
12
+	protected function getModel()
13
+	{
14
+		return 'App\Modules\V1\Acl\AclUser';
15
+	}
16
+
17
+	/**
18
+	 * Check if the logged in user or the given user 
19
+	 * has the given permissions on the given model.
20
+	 * 
21
+	 * @param  string  $nameOfPermission
22
+	 * @param  string  $model            
23
+	 * @param  boolean $user
24
+	 * @return boolean
25
+	 */
26
+	public function can($nameOfPermission, $model, $user = false )
27
+	{       
28
+		$user        = $user ?: \JWTAuth::parseToken()->authenticate();
29
+		$permissions = [];
30
+		\Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
31
+			$permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
32
+		});
33 33
         
34
-        return in_array($nameOfPermission, $permissions);
35
-    }
36
-
37
-    /**
38
-     * Check if the logged in user has the given group.
39
-     * 
40
-     * @param  string  $groupName
41
-     * @return boolean
42
-     */
43
-    public function hasGroup($groupName)
44
-    {
45
-        $groups = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
46
-        return $groups->lists('name')->search($groupName, true) === false ? false : true;
47
-    }
48
-
49
-    /**
50
-     * Assign the given group ids to the given user.
51
-     * 
52
-     * @param  integer $user_id    
53
-     * @param  array   $group_ids
54
-     * @return object
55
-     */
56
-    public function assignGroups($user_id, $group_ids)
57
-    {
58
-        \DB::transaction(function () use ($user_id, $group_ids) {
59
-            $user = \Core::users()->find($user_id);
60
-            $user->groups()->detach();
61
-            $user->groups()->attach($group_ids);
62
-        });
63
-
64
-        return \Core::users()->find($user_id);
65
-    }
66
-
67
-    /**
68
-     * Handle a login request to the application.
69
-     * 
70
-     * @param  array $credentials    
71
-     * @return string
72
-     */
73
-    public function login($credentials)
74
-    {
75
-        if ($this->isBlocked($credentials['email'])) 
76
-        {
77
-            \ErrorHandler::userIsBlocked();
78
-        }
79
-        else if ($token = \JWTAuth::attempt($credentials))
80
-        {
81
-            return $token;
82
-        }
83
-        else
84
-        {
85
-            \ErrorHandler::loginFailed();
86
-        }
87
-    }
88
-
89
-    /**
90
-     * Handle a registration request.
91
-     * 
92
-     * @param  array $credentials
93
-     * @return string
94
-     */
95
-    public function register($credentials)
96
-    {
97
-        return \JWTAuth::fromUser(\Core::users()->model->create($credentials));
98
-    }
99
-
100
-    /**
101
-     * Logout the user.
102
-     * 
103
-     * @return boolean
104
-     */
105
-    public function logout()
106
-    {
107
-        return \JWTAuth::invalidate(\JWTAuth::getToken());
108
-    }
109
-
110
-    /**
111
-     * Block the user.
112
-     *
113
-     * @param  integer $user_id
114
-     * @return object
115
-     */
116
-    public function block($user_id)
117
-    {
118
-        if ( ! $this->hasGroup('Admin'))
119
-        {
120
-            \ErrorHandler::noPermissions();
121
-        }
122
-
123
-        $user          = \Core::users()->find($user_id);
124
-        $user->blocked = 1;
125
-        $user->save();
34
+		return in_array($nameOfPermission, $permissions);
35
+	}
36
+
37
+	/**
38
+	 * Check if the logged in user has the given group.
39
+	 * 
40
+	 * @param  string  $groupName
41
+	 * @return boolean
42
+	 */
43
+	public function hasGroup($groupName)
44
+	{
45
+		$groups = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
46
+		return $groups->lists('name')->search($groupName, true) === false ? false : true;
47
+	}
48
+
49
+	/**
50
+	 * Assign the given group ids to the given user.
51
+	 * 
52
+	 * @param  integer $user_id    
53
+	 * @param  array   $group_ids
54
+	 * @return object
55
+	 */
56
+	public function assignGroups($user_id, $group_ids)
57
+	{
58
+		\DB::transaction(function () use ($user_id, $group_ids) {
59
+			$user = \Core::users()->find($user_id);
60
+			$user->groups()->detach();
61
+			$user->groups()->attach($group_ids);
62
+		});
63
+
64
+		return \Core::users()->find($user_id);
65
+	}
66
+
67
+	/**
68
+	 * Handle a login request to the application.
69
+	 * 
70
+	 * @param  array $credentials    
71
+	 * @return string
72
+	 */
73
+	public function login($credentials)
74
+	{
75
+		if ($this->isBlocked($credentials['email'])) 
76
+		{
77
+			\ErrorHandler::userIsBlocked();
78
+		}
79
+		else if ($token = \JWTAuth::attempt($credentials))
80
+		{
81
+			return $token;
82
+		}
83
+		else
84
+		{
85
+			\ErrorHandler::loginFailed();
86
+		}
87
+	}
88
+
89
+	/**
90
+	 * Handle a registration request.
91
+	 * 
92
+	 * @param  array $credentials
93
+	 * @return string
94
+	 */
95
+	public function register($credentials)
96
+	{
97
+		return \JWTAuth::fromUser(\Core::users()->model->create($credentials));
98
+	}
99
+
100
+	/**
101
+	 * Logout the user.
102
+	 * 
103
+	 * @return boolean
104
+	 */
105
+	public function logout()
106
+	{
107
+		return \JWTAuth::invalidate(\JWTAuth::getToken());
108
+	}
109
+
110
+	/**
111
+	 * Block the user.
112
+	 *
113
+	 * @param  integer $user_id
114
+	 * @return object
115
+	 */
116
+	public function block($user_id)
117
+	{
118
+		if ( ! $this->hasGroup('Admin'))
119
+		{
120
+			\ErrorHandler::noPermissions();
121
+		}
122
+
123
+		$user          = \Core::users()->find($user_id);
124
+		$user->blocked = 1;
125
+		$user->save();
126 126
         
127
-        return $user;
128
-    }
129
-
130
-    /**
131
-     * Unblock the user.
132
-     *
133
-     * @param  integer $user_id
134
-     * @return object
135
-     */
136
-    public function unblock($user_id)
137
-    {
138
-        if ( ! $this->hasGroup('Admin'))
139
-        {
140
-            \ErrorHandler::noPermissions();
141
-        }
142
-
143
-        $user          = \Core::users()->find($user_id);
144
-        $user->blocked = 0;
145
-        $user->save();
146
-
147
-        return $user;
148
-    }
149
-
150
-    /**
151
-     * Check if the user blocked or not.
152
-     *
153
-     * @param  string $email
154
-     * @return boolean
155
-     */
156
-    public function isBlocked($email)
157
-    {
158
-        $user = \Core::users()->first(['email' => $email]);
159
-        if ( ! $user) 
160
-        {
161
-            \ErrorHandler::notFound('email or password');
162
-        }
163
-
164
-        return $user->blocked;
165
-    }
166
-
167
-    /**
168
-     * Handle the editing of the user profile.
169
-     * 
170
-     * @param  array $profile
171
-     * @return object
172
-     */
173
-    public function editProfile($profile)
174
-    {
175
-        unset($profile['email']);
176
-        unset($profile['password']);
177
-        $profile['id'] = \JWTAuth::parseToken()->authenticate()->id;
127
+		return $user;
128
+	}
129
+
130
+	/**
131
+	 * Unblock the user.
132
+	 *
133
+	 * @param  integer $user_id
134
+	 * @return object
135
+	 */
136
+	public function unblock($user_id)
137
+	{
138
+		if ( ! $this->hasGroup('Admin'))
139
+		{
140
+			\ErrorHandler::noPermissions();
141
+		}
142
+
143
+		$user          = \Core::users()->find($user_id);
144
+		$user->blocked = 0;
145
+		$user->save();
146
+
147
+		return $user;
148
+	}
149
+
150
+	/**
151
+	 * Check if the user blocked or not.
152
+	 *
153
+	 * @param  string $email
154
+	 * @return boolean
155
+	 */
156
+	public function isBlocked($email)
157
+	{
158
+		$user = \Core::users()->first(['email' => $email]);
159
+		if ( ! $user) 
160
+		{
161
+			\ErrorHandler::notFound('email or password');
162
+		}
163
+
164
+		return $user->blocked;
165
+	}
166
+
167
+	/**
168
+	 * Handle the editing of the user profile.
169
+	 * 
170
+	 * @param  array $profile
171
+	 * @return object
172
+	 */
173
+	public function editProfile($profile)
174
+	{
175
+		unset($profile['email']);
176
+		unset($profile['password']);
177
+		$profile['id'] = \JWTAuth::parseToken()->authenticate()->id;
178 178
         
179
-        return $this->save($profile);
180
-    }
181
-
182
-    /**
183
-     * Send a reset link to the given user.
184
-     *
185
-     * @param  string  $email
186
-     * @return void
187
-     */
188
-    public function sendReset($email)
189
-    {
190
-        $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
191
-            $message->subject('Your Password Reset Link');
192
-        });
193
-
194
-        switch ($response) 
195
-        {
196
-            case \Password::INVALID_USER:
197
-                \ErrorHandler::notFound('email');
198
-        }
199
-    }
200
-
201
-    /**
202
-     * Reset the given user's password.
203
-     *
204
-     * @param  array  $credentials
205
-     * @return integer
206
-     */
207
-    public function resetPassword($credentials)
208
-    {
209
-        $token    = false;
210
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
211
-            $user->password = $password;
212
-            $user->save();
213
-
214
-            $token = \JWTAuth::fromUser($user);
215
-        });
216
-
217
-
218
-        switch ($response) {
219
-            case \Password::PASSWORD_RESET:
220
-                return $token;
179
+		return $this->save($profile);
180
+	}
181
+
182
+	/**
183
+	 * Send a reset link to the given user.
184
+	 *
185
+	 * @param  string  $email
186
+	 * @return void
187
+	 */
188
+	public function sendReset($email)
189
+	{
190
+		$response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
191
+			$message->subject('Your Password Reset Link');
192
+		});
193
+
194
+		switch ($response) 
195
+		{
196
+			case \Password::INVALID_USER:
197
+				\ErrorHandler::notFound('email');
198
+		}
199
+	}
200
+
201
+	/**
202
+	 * Reset the given user's password.
203
+	 *
204
+	 * @param  array  $credentials
205
+	 * @return integer
206
+	 */
207
+	public function resetPassword($credentials)
208
+	{
209
+		$token    = false;
210
+		$response = \Password::reset($credentials, function ($user, $password) use (&$token) {
211
+			$user->password = $password;
212
+			$user->save();
213
+
214
+			$token = \JWTAuth::fromUser($user);
215
+		});
216
+
217
+
218
+		switch ($response) {
219
+			case \Password::PASSWORD_RESET:
220
+				return $token;
221 221
                 
222
-            case \Password::INVALID_TOKEN:
223
-                \ErrorHandler::invalidResetToken('token');
222
+			case \Password::INVALID_TOKEN:
223
+				\ErrorHandler::invalidResetToken('token');
224 224
 
225
-            case \Password::INVALID_PASSWORD:
226
-                \ErrorHandler::invalidResetPassword('email');
225
+			case \Password::INVALID_PASSWORD:
226
+				\ErrorHandler::invalidResetPassword('email');
227 227
 
228
-            case \Password::INVALID_USER:
229
-                \ErrorHandler::notFound('user');
228
+			case \Password::INVALID_USER:
229
+				\ErrorHandler::notFound('user');
230 230
 
231
-            default:
232
-                \ErrorHandler::generalError();
233
-        }
234
-    }
231
+			default:
232
+				\ErrorHandler::generalError();
233
+		}
234
+	}
235 235
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
      * @param  boolean $user
24 24
      * @return boolean
25 25
      */
26
-    public function can($nameOfPermission, $model, $user = false )
26
+    public function can($nameOfPermission, $model, $user = false)
27 27
     {       
28 28
         $user        = $user ?: \JWTAuth::parseToken()->authenticate();
29 29
         $permissions = [];
30
-        \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function ($permission) use (&$permissions, $model){
30
+        \Core::users()->find($user->id, ['groups.permissions'])->groups->lists('permissions')->each(function($permission) use (&$permissions, $model){
31 31
             $permissions = array_merge($permissions, $permission->where('model', $model)->lists('name')->toArray()); 
32 32
         });
33 33
         
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      */
56 56
     public function assignGroups($user_id, $group_ids)
57 57
     {
58
-        \DB::transaction(function () use ($user_id, $group_ids) {
58
+        \DB::transaction(function() use ($user_id, $group_ids) {
59 59
             $user = \Core::users()->find($user_id);
60 60
             $user->groups()->detach();
61 61
             $user->groups()->attach($group_ids);
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
      */
188 188
     public function sendReset($email)
189 189
     {
190
-        $response = \Password::sendResetLink($email, function (\Illuminate\Mail\Message $message) {
190
+        $response = \Password::sendResetLink($email, function(\Illuminate\Mail\Message $message) {
191 191
             $message->subject('Your Password Reset Link');
192 192
         });
193 193
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
     public function resetPassword($credentials)
208 208
     {
209 209
         $token    = false;
210
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
210
+        $response = \Password::reset($credentials, function($user, $password) use (&$token) {
211 211
             $user->password = $password;
212 212
             $user->save();
213 213
 
Please login to merge, or discard this patch.
src/Modules/V1/Core/Utl/ErrorHandler.php 2 patches
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -2,81 +2,81 @@
 block discarded – undo
2 2
 
3 3
 class ErrorHandler
4 4
 {
5
-    public function unAuthorized()
6
-    {
7
-        $error = ['status' => 401, 'message' => 'Please login before any action'];
8
-        abort($error['status'], $error['message']);
9
-    }
5
+	public function unAuthorized()
6
+	{
7
+		$error = ['status' => 401, 'message' => 'Please login before any action'];
8
+		abort($error['status'], $error['message']);
9
+	}
10 10
 
11
-    public function tokenExpired()
12
-    {
13
-        $error = ['status' => 403, 'message' => 'Login token expired'];
14
-        abort($error['status'], $error['message']);
15
-    }
11
+	public function tokenExpired()
12
+	{
13
+		$error = ['status' => 403, 'message' => 'Login token expired'];
14
+		abort($error['status'], $error['message']);
15
+	}
16 16
 
17
-     public function noPermissions()
18
-    {
19
-        $error = ['status' => 403, 'message' => 'No permissions'];
20
-        abort($error['status'], $error['message']);
21
-    }
17
+	 public function noPermissions()
18
+	{
19
+		$error = ['status' => 403, 'message' => 'No permissions'];
20
+		abort($error['status'], $error['message']);
21
+	}
22 22
 
23
-    public function loginFailed()
24
-    {
25
-        $error = ['status' => 400, 'message' => 'Wrong mail or password'];
26
-        abort($error['status'], $error['message']);
27
-    }
23
+	public function loginFailed()
24
+	{
25
+		$error = ['status' => 400, 'message' => 'Wrong mail or password'];
26
+		abort($error['status'], $error['message']);
27
+	}
28 28
 
29
-    public function redisNotRunning()
30
-    {
31
-        $error = ['status' => 400, 'message' => 'Your redis notification server isn\'t running'];
32
-        abort($error['status'], $error['message']);
33
-    }
29
+	public function redisNotRunning()
30
+	{
31
+		$error = ['status' => 400, 'message' => 'Your redis notification server isn\'t running'];
32
+		abort($error['status'], $error['message']);
33
+	}
34 34
 
35
-    public function dbQueryError()
36
-    {
37
-        $error = ['status' => 400, 'message' => 'Please check the given inputes'];
38
-        abort($error['status'], $error['message']);
39
-    }
35
+	public function dbQueryError()
36
+	{
37
+		$error = ['status' => 400, 'message' => 'Please check the given inputes'];
38
+		abort($error['status'], $error['message']);
39
+	}
40 40
 
41
-    public function cannotCreateSetting()
42
-    {
43
-        $error = ['status' => 400, 'message' => 'Can\'t create setting'];
44
-        abort($error['status'], $error['message']);
45
-    }
41
+	public function cannotCreateSetting()
42
+	{
43
+		$error = ['status' => 400, 'message' => 'Can\'t create setting'];
44
+		abort($error['status'], $error['message']);
45
+	}
46 46
 
47
-    public function cannotUpdateSettingKey()
48
-    {
49
-        $error = ['status' => 400, 'message' => 'Can\'t update setting key'];
50
-        abort($error['status'], $error['message']);
51
-    }
47
+	public function cannotUpdateSettingKey()
48
+	{
49
+		$error = ['status' => 400, 'message' => 'Can\'t update setting key'];
50
+		abort($error['status'], $error['message']);
51
+	}
52 52
 
53
-    public function userIsBlocked()
54
-    {
55
-        $error = ['status' => 403, 'message' => 'You have been blocked'];
56
-        abort($error['status'], $error['message']);
57
-    }
53
+	public function userIsBlocked()
54
+	{
55
+		$error = ['status' => 403, 'message' => 'You have been blocked'];
56
+		abort($error['status'], $error['message']);
57
+	}
58 58
 
59
-    public function invalidResetToken()
60
-    {
61
-        $error = ['status' => 400, 'message' => 'Reset password token is invalid'];
62
-        abort($error['status'], $error['message']);
63
-    }
59
+	public function invalidResetToken()
60
+	{
61
+		$error = ['status' => 400, 'message' => 'Reset password token is invalid'];
62
+		abort($error['status'], $error['message']);
63
+	}
64 64
 
65
-    public function invalidResetPassword()
66
-    {
67
-        $error = ['status' => 400, 'message' => 'Reset password is invalid'];
68
-        abort($error['status'], $error['message']);
69
-    }
65
+	public function invalidResetPassword()
66
+	{
67
+		$error = ['status' => 400, 'message' => 'Reset password is invalid'];
68
+		abort($error['status'], $error['message']);
69
+	}
70 70
 
71
-    public function notFound($text)
72
-    {
73
-        $error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found'];
74
-        abort($error['status'], $error['message']);
75
-    }
71
+	public function notFound($text)
72
+	{
73
+		$error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found'];
74
+		abort($error['status'], $error['message']);
75
+	}
76 76
 
77
-    public function generalError()
78
-    {
79
-        $error = ['status' => 404, 'message' => 'Something went wrong'];
80
-        abort($error['status'], $error['message']);
81
-    }
77
+	public function generalError()
78
+	{
79
+		$error = ['status' => 404, 'message' => 'Something went wrong'];
80
+		abort($error['status'], $error['message']);
81
+	}
82 82
 }
83 83
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
 
71 71
     public function notFound($text)
72 72
     {
73
-        $error = ['status' => 404, 'message' => 'The requested ' . $text . ' not found'];
73
+        $error = ['status' => 404, 'message' => 'The requested '.$text.' not found'];
74 74
         abort($error['status'], $error['message']);
75 75
     }
76 76
 
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Http/Controllers/UsersController.php 2 patches
Indentation   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -7,167 +7,167 @@
 block discarded – undo
7 7
 
8 8
 class UsersController extends BaseApiController
9 9
 {
10
-    /**
11
-     * The name of the model that is used by the base api controller 
12
-     * to preform actions like (add, edit ... etc).
13
-     * @var string
14
-     */
15
-    protected $model               = 'users';
16
-
17
-    /**
18
-     * List of all route actions that the base api controller
19
-     * will skip permissions check for them.
20
-     * @var array
21
-     */
22
-    protected $skipPermissionCheck = ['account', 'logout', 'block', 'unblock', 'editprofile', 'sendreset'];
23
-
24
-    /**
25
-     * List of all route actions that the base api controller
26
-     * will skip login check for them.
27
-     * @var array
28
-     */
29
-    protected $skipLoginCheck      = ['login', 'register', 'sendreset', 'resetpassword'];
30
-
31
-    /**
32
-     * The validations rules used by the base api controller
33
-     * to check before add.
34
-     * @var array
35
-     */
36
-    protected $validationRules     = [
37
-    'email'    => 'required|email|unique:users,email,{id}',
38
-    'password' => 'min:6'
39
-    ];
40
-
41
-    /**
42
-     * Return the logged in user account.
43
-     * 
44
-     * @return object
45
-     */
46
-    public function getAccount()
47
-    {
48
-       $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
49
-       return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find(\JWTAuth::parseToken()->authenticate()->id, $relations), 200);
50
-    }
51
-
52
-    /**
53
-     * Block the user.
54
-     *
55
-     * @param  integer  $user_id
56
-     * @return void
57
-     */
58
-    public function getBlock($user_id)
59
-    {
60
-        return \Response::json(\Core::users()->block($user_id), 200);
61
-    }
62
-
63
-    /**
64
-     * Unblock the user.
65
-     *
66
-     * @param  integer  $user_id
67
-     * @return void
68
-     */
69
-    public function getUnblock($user_id)
70
-    {
71
-        return \Response::json(\Core::users()->unblock($user_id), 200);
72
-    }
73
-
74
-    /**
75
-     * Logout the user.
76
-     * 
77
-     * @return void
78
-     */
79
-    public function getLogout()
80
-    {
81
-        return \Response::json(\Core::users()->logout(), 200);
82
-    }
83
-
84
-    /**
85
-     * Handle a registration request.
86
-     *
87
-     * @param  \Illuminate\Http\Request  $request
88
-     * @return \Illuminate\Http\Response
89
-     */
90
-    public function postRegister(Request $request)
91
-    {
92
-        $this->validate($request, [
93
-            'email'    => 'email|unique:users,email,{id}', 
94
-            'password' => 'min:6'
95
-            ]);
96
-
97
-        return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
98
-    }
99
-
100
-    /**
101
-     * Handle a login request to the application.
102
-     *
103
-     * @param  \Illuminate\Http\Request  $request
104
-     * @return \Illuminate\Http\Response
105
-     */
106
-    public function postLogin(Request $request)
107
-    {
108
-        $this->validate($request, [
109
-            'email'    => 'required|email', 
110
-            'password' => 'required|min:6'
111
-            ]);
112
-
113
-        return \Response::json(\Core::users()->login($request->only('email', 'password')), 200);
114
-    }
115
-
116
-    /**
117
-     * Handle an assign groups to user request.
118
-     *
119
-     * @param  \Illuminate\Http\Request  $request
120
-     * @return \Illuminate\Http\Response
121
-     */
122
-    public function postAssigngroups(Request $request)
123
-    {
124
-        $this->validate($request, [
125
-            'group_ids' => 'required|exists:groups,id', 
126
-            'user_id'   => 'required|exists:users,id'
127
-            ]);
128
-
129
-        return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
130
-    }
131
-
132
-    /**
133
-     * Handle the editing of the user profile.
134
-     *
135
-     * @param  \Illuminate\Http\Request  $request
136
-     * @return \Illuminate\Http\Response
137
-     */
138
-    public function postEditprofile(Request $request)
139
-    {
140
-        return \Response::json(\Core::users()->editProfile($request->all()), 200);
141
-    }
142
-
143
-    /**
144
-     * Send a reset link to the given user.
145
-     *
146
-     * @param  \Illuminate\Http\Request  $request
147
-     * @return \Illuminate\Http\Response
148
-     */
149
-    public function postSendreset(Request $request)
150
-    {
151
-        $this->validate($request, ['email' => 'required|email']);
152
-
153
-        return \Response::json(\Core::users()->sendReset($request->only('email')), 200);
154
-    }
155
-
156
-    /**
157
-     * Reset the given user's password.
158
-     *
159
-     * @param  \Illuminate\Http\Request  $request
160
-     * @return \Illuminate\Http\Response
161
-     */
162
-    public function postResetpassword(Request $request)
163
-    {
164
-        $this->validate($request, [
165
-            'token'                 => 'required',
166
-            'email'                 => 'required|email',
167
-            'password'              => 'required|confirmed|min:6',
168
-            'password_confirmation' => 'required',
169
-        ]);
170
-
171
-        return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
172
-    }
10
+	/**
11
+	 * The name of the model that is used by the base api controller 
12
+	 * to preform actions like (add, edit ... etc).
13
+	 * @var string
14
+	 */
15
+	protected $model               = 'users';
16
+
17
+	/**
18
+	 * List of all route actions that the base api controller
19
+	 * will skip permissions check for them.
20
+	 * @var array
21
+	 */
22
+	protected $skipPermissionCheck = ['account', 'logout', 'block', 'unblock', 'editprofile', 'sendreset'];
23
+
24
+	/**
25
+	 * List of all route actions that the base api controller
26
+	 * will skip login check for them.
27
+	 * @var array
28
+	 */
29
+	protected $skipLoginCheck      = ['login', 'register', 'sendreset', 'resetpassword'];
30
+
31
+	/**
32
+	 * The validations rules used by the base api controller
33
+	 * to check before add.
34
+	 * @var array
35
+	 */
36
+	protected $validationRules     = [
37
+	'email'    => 'required|email|unique:users,email,{id}',
38
+	'password' => 'min:6'
39
+	];
40
+
41
+	/**
42
+	 * Return the logged in user account.
43
+	 * 
44
+	 * @return object
45
+	 */
46
+	public function getAccount()
47
+	{
48
+	   $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
49
+	   return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find(\JWTAuth::parseToken()->authenticate()->id, $relations), 200);
50
+	}
51
+
52
+	/**
53
+	 * Block the user.
54
+	 *
55
+	 * @param  integer  $user_id
56
+	 * @return void
57
+	 */
58
+	public function getBlock($user_id)
59
+	{
60
+		return \Response::json(\Core::users()->block($user_id), 200);
61
+	}
62
+
63
+	/**
64
+	 * Unblock the user.
65
+	 *
66
+	 * @param  integer  $user_id
67
+	 * @return void
68
+	 */
69
+	public function getUnblock($user_id)
70
+	{
71
+		return \Response::json(\Core::users()->unblock($user_id), 200);
72
+	}
73
+
74
+	/**
75
+	 * Logout the user.
76
+	 * 
77
+	 * @return void
78
+	 */
79
+	public function getLogout()
80
+	{
81
+		return \Response::json(\Core::users()->logout(), 200);
82
+	}
83
+
84
+	/**
85
+	 * Handle a registration request.
86
+	 *
87
+	 * @param  \Illuminate\Http\Request  $request
88
+	 * @return \Illuminate\Http\Response
89
+	 */
90
+	public function postRegister(Request $request)
91
+	{
92
+		$this->validate($request, [
93
+			'email'    => 'email|unique:users,email,{id}', 
94
+			'password' => 'min:6'
95
+			]);
96
+
97
+		return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
98
+	}
99
+
100
+	/**
101
+	 * Handle a login request to the application.
102
+	 *
103
+	 * @param  \Illuminate\Http\Request  $request
104
+	 * @return \Illuminate\Http\Response
105
+	 */
106
+	public function postLogin(Request $request)
107
+	{
108
+		$this->validate($request, [
109
+			'email'    => 'required|email', 
110
+			'password' => 'required|min:6'
111
+			]);
112
+
113
+		return \Response::json(\Core::users()->login($request->only('email', 'password')), 200);
114
+	}
115
+
116
+	/**
117
+	 * Handle an assign groups to user request.
118
+	 *
119
+	 * @param  \Illuminate\Http\Request  $request
120
+	 * @return \Illuminate\Http\Response
121
+	 */
122
+	public function postAssigngroups(Request $request)
123
+	{
124
+		$this->validate($request, [
125
+			'group_ids' => 'required|exists:groups,id', 
126
+			'user_id'   => 'required|exists:users,id'
127
+			]);
128
+
129
+		return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
130
+	}
131
+
132
+	/**
133
+	 * Handle the editing of the user profile.
134
+	 *
135
+	 * @param  \Illuminate\Http\Request  $request
136
+	 * @return \Illuminate\Http\Response
137
+	 */
138
+	public function postEditprofile(Request $request)
139
+	{
140
+		return \Response::json(\Core::users()->editProfile($request->all()), 200);
141
+	}
142
+
143
+	/**
144
+	 * Send a reset link to the given user.
145
+	 *
146
+	 * @param  \Illuminate\Http\Request  $request
147
+	 * @return \Illuminate\Http\Response
148
+	 */
149
+	public function postSendreset(Request $request)
150
+	{
151
+		$this->validate($request, ['email' => 'required|email']);
152
+
153
+		return \Response::json(\Core::users()->sendReset($request->only('email')), 200);
154
+	}
155
+
156
+	/**
157
+	 * Reset the given user's password.
158
+	 *
159
+	 * @param  \Illuminate\Http\Request  $request
160
+	 * @return \Illuminate\Http\Response
161
+	 */
162
+	public function postResetpassword(Request $request)
163
+	{
164
+		$this->validate($request, [
165
+			'token'                 => 'required',
166
+			'email'                 => 'required|email',
167
+			'password'              => 'required|confirmed|min:6',
168
+			'password_confirmation' => 'required',
169
+		]);
170
+
171
+		return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
172
+	}
173 173
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      * to preform actions like (add, edit ... etc).
13 13
      * @var string
14 14
      */
15
-    protected $model               = 'users';
15
+    protected $model = 'users';
16 16
 
17 17
     /**
18 18
      * List of all route actions that the base api controller
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
      * will skip login check for them.
27 27
      * @var array
28 28
      */
29
-    protected $skipLoginCheck      = ['login', 'register', 'sendreset', 'resetpassword'];
29
+    protected $skipLoginCheck = ['login', 'register', 'sendreset', 'resetpassword'];
30 30
 
31 31
     /**
32 32
      * The validations rules used by the base api controller
33 33
      * to check before add.
34 34
      * @var array
35 35
      */
36
-    protected $validationRules     = [
36
+    protected $validationRules = [
37 37
     'email'    => 'required|email|unique:users,email,{id}',
38 38
     'password' => 'min:6'
39 39
     ];
Please login to merge, or discard this patch.
src/Modules/V1/Acl/AclUser.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -6,66 +6,66 @@
 block discarded – undo
6 6
 
7 7
 class AclUser extends User {
8 8
 
9
-    use SoftDeletes;
10
-    protected $table    = 'users';
11
-    protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
-    protected $hidden   = ['password', 'remember_token','deleted_at'];
13
-    protected $guarded  = ['id'];
14
-    protected $fillable = ['name', 'email', 'password'];
15
-    protected $appends  = ['permissions'];
9
+	use SoftDeletes;
10
+	protected $table    = 'users';
11
+	protected $dates    = ['created_at', 'updated_at', 'deleted_at'];
12
+	protected $hidden   = ['password', 'remember_token','deleted_at'];
13
+	protected $guarded  = ['id'];
14
+	protected $fillable = ['name', 'email', 'password'];
15
+	protected $appends  = ['permissions'];
16 16
     
17
-    public function getCreatedAtAttribute($value)
18
-    {
19
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
20
-    }
17
+	public function getCreatedAtAttribute($value)
18
+	{
19
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
20
+	}
21 21
 
22
-    public function getUpdatedAtAttribute($value)
23
-    {
24
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
25
-    }
22
+	public function getUpdatedAtAttribute($value)
23
+	{
24
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
25
+	}
26 26
 
27
-    public function getDeletedAtAttribute($value)
28
-    {
29
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
30
-    }
27
+	public function getDeletedAtAttribute($value)
28
+	{
29
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
30
+	}
31 31
 
32
-    /**
33
-     * Encrypt the password attribute before
34
-     * saving it in the storage.
35
-     * 
36
-     * @param string $value 
37
-     */
38
-    public function setPasswordAttribute($value)
39
-    {
40
-        $this->attributes['password'] = bcrypt($value);
41
-    }
32
+	/**
33
+	 * Encrypt the password attribute before
34
+	 * saving it in the storage.
35
+	 * 
36
+	 * @param string $value 
37
+	 */
38
+	public function setPasswordAttribute($value)
39
+	{
40
+		$this->attributes['password'] = bcrypt($value);
41
+	}
42 42
 
43
-    public function logs()
44
-    {
45
-        return $this->hasMany('App\Modules\V1\Logging\Log', 'user_id');
46
-    }
43
+	public function logs()
44
+	{
45
+		return $this->hasMany('App\Modules\V1\Logging\Log', 'user_id');
46
+	}
47 47
 
48
-    public function groups()
49
-    {
50
-        return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
51
-    }
48
+	public function groups()
49
+	{
50
+		return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps();
51
+	}
52 52
 
53
-    public function getPermissionsAttribute()
54
-    {
55
-        $permissions = [];
56
-        foreach ($this->groups as $group)
57
-        {
58
-            $group->permissions->each(function ($permission) use (&$permissions){
59
-                $permissions[$permission->model][$permission->id] = $permission->name;
60
-            });
61
-        }
53
+	public function getPermissionsAttribute()
54
+	{
55
+		$permissions = [];
56
+		foreach ($this->groups as $group)
57
+		{
58
+			$group->permissions->each(function ($permission) use (&$permissions){
59
+				$permissions[$permission->model][$permission->id] = $permission->name;
60
+			});
61
+		}
62 62
 
63
-        return \Illuminate\Database\Eloquent\Collection::make($permissions);
64
-    }
63
+		return \Illuminate\Database\Eloquent\Collection::make($permissions);
64
+	}
65 65
 
66
-    public static function boot()
67
-    {
68
-        parent::boot();
69
-        parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver'));
70
-    }
66
+	public static function boot()
67
+	{
68
+		parent::boot();
69
+		parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver'));
70
+	}
71 71
 }
Please login to merge, or discard this patch.
Modules/V1/Acl/Database/Migrations/2015_12_20_124154_password_resets.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -5,27 +5,27 @@
 block discarded – undo
5 5
 
6 6
 class PasswordResets extends Migration
7 7
 {
8
-    /**
9
-     * Run the migrations.
10
-     *
11
-     * @return void
12
-     */
13
-    public function up()
14
-    {
15
-        Schema::create('password_resets', function (Blueprint $table) {
16
-            $table->string('email')->index();
17
-            $table->string('token')->index();
18
-            $table->timestamp('created_at');
19
-        });
20
-    }
8
+	/**
9
+	 * Run the migrations.
10
+	 *
11
+	 * @return void
12
+	 */
13
+	public function up()
14
+	{
15
+		Schema::create('password_resets', function (Blueprint $table) {
16
+			$table->string('email')->index();
17
+			$table->string('token')->index();
18
+			$table->timestamp('created_at');
19
+		});
20
+	}
21 21
 
22
-    /**
23
-     * Reverse the migrations.
24
-     *
25
-     * @return void
26
-     */
27
-    public function down()
28
-    {
29
-        Schema::drop('password_resets');
30
-    }
22
+	/**
23
+	 * Reverse the migrations.
24
+	 *
25
+	 * @return void
26
+	 */
27
+	public function down()
28
+	{
29
+		Schema::drop('password_resets');
30
+	}
31 31
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
      */
13 13
     public function up()
14 14
     {
15
-        Schema::create('password_resets', function (Blueprint $table) {
15
+        Schema::create('password_resets', function(Blueprint $table) {
16 16
             $table->string('email')->index();
17 17
             $table->string('token')->index();
18 18
             $table->timestamp('created_at');
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Database/Migrations/2015_12_20_124153_users.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@
 block discarded – undo
13 13
 	public function up()
14 14
 	{
15 15
 		Schema::create('users', function (Blueprint $table) {
16
-            $table->increments('id');
17
-            $table->string('name',100)->nullable();
18
-            $table->string('email')->unique();
19
-            $table->string('password', 60);
20
-            $table->boolean('blocked', 0);
21
-            $table->softDeletes();
22
-            $table->rememberToken();
23
-            $table->timestamps();
24
-        });
16
+			$table->increments('id');
17
+			$table->string('name',100)->nullable();
18
+			$table->string('email')->unique();
19
+			$table->string('password', 60);
20
+			$table->boolean('blocked', 0);
21
+			$table->softDeletes();
22
+			$table->rememberToken();
23
+			$table->timestamps();
24
+		});
25 25
 	}
26 26
 
27 27
 	/**
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@
 block discarded – undo
12 12
 	 */
13 13
 	public function up()
14 14
 	{
15
-		Schema::create('users', function (Blueprint $table) {
15
+		Schema::create('users', function(Blueprint $table) {
16 16
             $table->increments('id');
17
-            $table->string('name',100)->nullable();
17
+            $table->string('name', 100)->nullable();
18 18
             $table->string('email')->unique();
19 19
             $table->string('password', 60);
20 20
             $table->boolean('blocked', 0);
Please login to merge, or discard this patch.
src/ApiSkeletonServiceProvider.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -6,26 +6,26 @@
 block discarded – undo
6 6
 
7 7
 class ApiSkeletonServiceProvider extends ServiceProvider
8 8
 {
9
-    /**
10
-     * Perform post-registration booting of services.
11
-     *
12
-     * @return void
13
-     */
14
-    public function boot()
15
-    {
16
-        $this->publishes([
17
-            __DIR__.'/Modules'               => app_path('Modules'),
18
-            __DIR__.'/Modules/V1/Acl/emails' => base_path('resources/views/auth/emails'),
19
-            ]);
20
-    }
9
+	/**
10
+	 * Perform post-registration booting of services.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function boot()
15
+	{
16
+		$this->publishes([
17
+			__DIR__.'/Modules'               => app_path('Modules'),
18
+			__DIR__.'/Modules/V1/Acl/emails' => base_path('resources/views/auth/emails'),
19
+			]);
20
+	}
21 21
 
22
-    /**
23
-     * Register any package services.
24
-     *
25
-     * @return void
26
-     */
27
-    public function register()
28
-    {
29
-        //
30
-    }
22
+	/**
23
+	 * Register any package services.
24
+	 *
25
+	 * @return void
26
+	 */
27
+	public function register()
28
+	{
29
+		//
30
+	}
31 31
 }
32 32
\ No newline at end of file
Please login to merge, or discard this patch.