Completed
Push — master ( 634be5...2c8eb1 )
by Sherif
10:27
created
src/Modules/V1/Acl/Http/Controllers/UsersController.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -7,219 +7,219 @@
 block discarded – undo
7 7
 
8 8
 class UsersController extends BaseApiController
9 9
 {
10
-    /**
11
-     * The name of the model that is used by the base api controller 
12
-     * to preform actions like (add, edit ... etc).
13
-     * @var string
14
-     */
15
-    protected $model               = 'users';
16
-
17
-    /**
18
-     * List of all route actions that the base api controller
19
-     * will skip permissions check for them.
20
-     * @var array
21
-     */
22
-    protected $skipPermissionCheck = ['account', 'logout', 'sendreset'];
23
-
24
-    /**
25
-     * List of all route actions that the base api controller
26
-     * will skip login check for them.
27
-     * @var array
28
-     */
29
-    protected $skipLoginCheck      = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken'];
30
-
31
-    /**
32
-     * The validations rules used by the base api controller
33
-     * to check before add.
34
-     * @var array
35
-     */
36
-    protected $validationRules     = [
37
-        'user_name'     => 'string|unique:users,user_name,{id}', 
38
-        'email'         => 'required|email|unique:users,email,{id}', 
39
-        'password'      => 'min:6'
40
-    ];
41
-
42
-    /**
43
-     * Return the logged in user account.
44
-     * 
45
-     * @return \Illuminate\Http\Response
46
-     */
47
-    public function account()
48
-    {
49
-        $relations = $this->relations && $this->relations['account'] ? $this->relations['account'] : [];
50
-        return \Response::json(\Core::users()->account($relations), 200);
51
-    }
52
-
53
-    /**
54
-     * Block the user.
55
-     *
56
-     * @param  integer  $id
57
-     * @return \Illuminate\Http\Response
58
-     */
59
-    public function block($id)
60
-    {
61
-        return \Response::json(\Core::users()->block($id), 200);
62
-    }
63
-
64
-    /**
65
-     * Unblock the user.
66
-     *
67
-     * @param  integer  $id
68
-     * @return \Illuminate\Http\Response
69
-     */
70
-    public function unblock($id)
71
-    {
72
-        return \Response::json(\Core::users()->unblock($id), 200);
73
-    }
74
-
75
-    /**
76
-     * Logout the user.
77
-     * 
78
-     * @return \Illuminate\Http\Response
79
-     */
80
-    public function logout()
81
-    {
82
-        return \Response::json(\Core::users()->logout(), 200);
83
-    }
84
-
85
-    /**
86
-     * Handle a registration request.
87
-     *
88
-     * @param  \Illuminate\Http\Request  $request
89
-     * @return \Illuminate\Http\Response
90
-     */
91
-    public function register(Request $request)
92
-    {
93
-        $this->validate($request, [
94
-            'user_name'     => 'string|unique:users,user_name,{id}', 
95
-            'email'         => 'required|email|unique:users,email,{id}', 
96
-            'password'      => 'required|min:6'
97
-            ]);
98
-
99
-        return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
100
-    }
101
-
102
-    /**
103
-     * Handle a login request of the none admin to the application.
104
-     *
105
-     * @param  \Illuminate\Http\Request  $request
106
-     * @return \Illuminate\Http\Response
107
-     */
108
-    public function login(Request $request)
109
-    {
110
-        $this->validate($request, [
111
-            'email'    => 'required|email', 
112
-            'password' => 'required|min:6',
113
-            'admin'    => 'boolean'
114
-            ]);
115
-
116
-        return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
117
-    }
118
-
119
-    /**
120
-     * Handle a social login request of the none admin to the application.
121
-     *
122
-     * @param  \Illuminate\Http\Request  $request
123
-     * @return \Illuminate\Http\Response
124
-     */
125
-    public function loginSocial(Request $request)
126
-    {
127
-        $this->validate($request, [
128
-            'auth_code'    => 'required_without:access_token',
129
-            'access_token' => 'required_without:auth_code',
130
-            'type'         => 'required|in:facebook,google'
131
-            ]);
132
-
133
-        return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200);
134
-    }
135
-
136
-    /**
137
-     * Handle an assign groups to user request.
138
-     *
139
-     * @param  \Illuminate\Http\Request  $request
140
-     * @return \Illuminate\Http\Response
141
-     */
142
-    public function assigngroups(Request $request)
143
-    {
144
-        $this->validate($request, [
145
-            'group_ids' => 'required|exists:groups,id', 
146
-            'user_id'   => 'required|exists:users,id'
147
-            ]);
148
-
149
-        return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
150
-    }
151
-
152
-    /**
153
-     * Send a reset link to the given user.
154
-     *
155
-     * @param  \Illuminate\Http\Request  $request
156
-     * @return \Illuminate\Http\Response
157
-     */
158
-    public function sendreset(Request $request)
159
-    {
160
-        $this->validate($request, ['email' => 'required|email', 'url' => 'required|url']);
161
-
162
-        return \Response::json(\Core::users()->sendReset($request->only('email'), $request->get('url')), 200);
163
-    }
164
-
165
-    /**
166
-     * Reset the given user's password.
167
-     *
168
-     * @param  \Illuminate\Http\Request  $request
169
-     * @return \Illuminate\Http\Response
170
-     */
171
-    public function resetpassword(Request $request)
172
-    {
173
-        $this->validate($request, [
174
-            'token'                 => 'required',
175
-            'email'                 => 'required|email',
176
-            'password'              => 'required|confirmed|min:6',
177
-            'password_confirmation' => 'required',
178
-        ]);
179
-
180
-        return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
181
-    }
182
-
183
-    /**
184
-     * Change the logged in user password.
185
-     *
186
-     * @param  \Illuminate\Http\Request  $request
187
-     * @return \Illuminate\Http\Response
188
-     */
189
-    public function changePassword(Request $request)
190
-    {
191
-        $this->validate($request, [
192
-            'old_password'          => 'required',
193
-            'password'              => 'required|confirmed|min:6',
194
-            'password_confirmation' => 'required',
195
-        ]);
196
-
197
-        return \Response::json(\Core::users()->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
198
-    }
199
-
200
-    /**
201
-     * Refresh the expired login token.
202
-     *
203
-     * @return \Illuminate\Http\Response
204
-     */
205
-    public function refreshtoken()
206
-    {
207
-        return \Response::json(\Core::users()->refreshtoken(), 200);
208
-    }
209
-
210
-    /**
211
-     * Paginate all users with inthe given group.
212
-     * 
213
-     * @param  \Illuminate\Http\Request  $request
214
-     * @param  string $groupName
215
-     * @param  integer $perPage
216
-     * @param  string  $sortBy
217
-     * @param  boolean $desc
218
-     * @return \Illuminate\Http\Response
219
-     */
220
-    public function group(Request $request, $groupName, $perPage = 15, $sortBy = 'created_at', $desc = 1)
221
-    {
222
-        $relations = $this->relations && $this->relations['group'] ? $this->relations['group'] : [];
223
-        return \Response::json(\Core::users()->group($request->all(), $groupName, $relations, $perPage, $sortBy, $desc), 200);
224
-    }
10
+	/**
11
+	 * The name of the model that is used by the base api controller 
12
+	 * to preform actions like (add, edit ... etc).
13
+	 * @var string
14
+	 */
15
+	protected $model               = 'users';
16
+
17
+	/**
18
+	 * List of all route actions that the base api controller
19
+	 * will skip permissions check for them.
20
+	 * @var array
21
+	 */
22
+	protected $skipPermissionCheck = ['account', 'logout', 'sendreset'];
23
+
24
+	/**
25
+	 * List of all route actions that the base api controller
26
+	 * will skip login check for them.
27
+	 * @var array
28
+	 */
29
+	protected $skipLoginCheck      = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken'];
30
+
31
+	/**
32
+	 * The validations rules used by the base api controller
33
+	 * to check before add.
34
+	 * @var array
35
+	 */
36
+	protected $validationRules     = [
37
+		'user_name'     => 'string|unique:users,user_name,{id}', 
38
+		'email'         => 'required|email|unique:users,email,{id}', 
39
+		'password'      => 'min:6'
40
+	];
41
+
42
+	/**
43
+	 * Return the logged in user account.
44
+	 * 
45
+	 * @return \Illuminate\Http\Response
46
+	 */
47
+	public function account()
48
+	{
49
+		$relations = $this->relations && $this->relations['account'] ? $this->relations['account'] : [];
50
+		return \Response::json(\Core::users()->account($relations), 200);
51
+	}
52
+
53
+	/**
54
+	 * Block the user.
55
+	 *
56
+	 * @param  integer  $id
57
+	 * @return \Illuminate\Http\Response
58
+	 */
59
+	public function block($id)
60
+	{
61
+		return \Response::json(\Core::users()->block($id), 200);
62
+	}
63
+
64
+	/**
65
+	 * Unblock the user.
66
+	 *
67
+	 * @param  integer  $id
68
+	 * @return \Illuminate\Http\Response
69
+	 */
70
+	public function unblock($id)
71
+	{
72
+		return \Response::json(\Core::users()->unblock($id), 200);
73
+	}
74
+
75
+	/**
76
+	 * Logout the user.
77
+	 * 
78
+	 * @return \Illuminate\Http\Response
79
+	 */
80
+	public function logout()
81
+	{
82
+		return \Response::json(\Core::users()->logout(), 200);
83
+	}
84
+
85
+	/**
86
+	 * Handle a registration request.
87
+	 *
88
+	 * @param  \Illuminate\Http\Request  $request
89
+	 * @return \Illuminate\Http\Response
90
+	 */
91
+	public function register(Request $request)
92
+	{
93
+		$this->validate($request, [
94
+			'user_name'     => 'string|unique:users,user_name,{id}', 
95
+			'email'         => 'required|email|unique:users,email,{id}', 
96
+			'password'      => 'required|min:6'
97
+			]);
98
+
99
+		return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
100
+	}
101
+
102
+	/**
103
+	 * Handle a login request of the none admin to the application.
104
+	 *
105
+	 * @param  \Illuminate\Http\Request  $request
106
+	 * @return \Illuminate\Http\Response
107
+	 */
108
+	public function login(Request $request)
109
+	{
110
+		$this->validate($request, [
111
+			'email'    => 'required|email', 
112
+			'password' => 'required|min:6',
113
+			'admin'    => 'boolean'
114
+			]);
115
+
116
+		return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
117
+	}
118
+
119
+	/**
120
+	 * Handle a social login request of the none admin to the application.
121
+	 *
122
+	 * @param  \Illuminate\Http\Request  $request
123
+	 * @return \Illuminate\Http\Response
124
+	 */
125
+	public function loginSocial(Request $request)
126
+	{
127
+		$this->validate($request, [
128
+			'auth_code'    => 'required_without:access_token',
129
+			'access_token' => 'required_without:auth_code',
130
+			'type'         => 'required|in:facebook,google'
131
+			]);
132
+
133
+		return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200);
134
+	}
135
+
136
+	/**
137
+	 * Handle an assign groups to user request.
138
+	 *
139
+	 * @param  \Illuminate\Http\Request  $request
140
+	 * @return \Illuminate\Http\Response
141
+	 */
142
+	public function assigngroups(Request $request)
143
+	{
144
+		$this->validate($request, [
145
+			'group_ids' => 'required|exists:groups,id', 
146
+			'user_id'   => 'required|exists:users,id'
147
+			]);
148
+
149
+		return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
150
+	}
151
+
152
+	/**
153
+	 * Send a reset link to the given user.
154
+	 *
155
+	 * @param  \Illuminate\Http\Request  $request
156
+	 * @return \Illuminate\Http\Response
157
+	 */
158
+	public function sendreset(Request $request)
159
+	{
160
+		$this->validate($request, ['email' => 'required|email', 'url' => 'required|url']);
161
+
162
+		return \Response::json(\Core::users()->sendReset($request->only('email'), $request->get('url')), 200);
163
+	}
164
+
165
+	/**
166
+	 * Reset the given user's password.
167
+	 *
168
+	 * @param  \Illuminate\Http\Request  $request
169
+	 * @return \Illuminate\Http\Response
170
+	 */
171
+	public function resetpassword(Request $request)
172
+	{
173
+		$this->validate($request, [
174
+			'token'                 => 'required',
175
+			'email'                 => 'required|email',
176
+			'password'              => 'required|confirmed|min:6',
177
+			'password_confirmation' => 'required',
178
+		]);
179
+
180
+		return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
181
+	}
182
+
183
+	/**
184
+	 * Change the logged in user password.
185
+	 *
186
+	 * @param  \Illuminate\Http\Request  $request
187
+	 * @return \Illuminate\Http\Response
188
+	 */
189
+	public function changePassword(Request $request)
190
+	{
191
+		$this->validate($request, [
192
+			'old_password'          => 'required',
193
+			'password'              => 'required|confirmed|min:6',
194
+			'password_confirmation' => 'required',
195
+		]);
196
+
197
+		return \Response::json(\Core::users()->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
198
+	}
199
+
200
+	/**
201
+	 * Refresh the expired login token.
202
+	 *
203
+	 * @return \Illuminate\Http\Response
204
+	 */
205
+	public function refreshtoken()
206
+	{
207
+		return \Response::json(\Core::users()->refreshtoken(), 200);
208
+	}
209
+
210
+	/**
211
+	 * Paginate all users with inthe given group.
212
+	 * 
213
+	 * @param  \Illuminate\Http\Request  $request
214
+	 * @param  string $groupName
215
+	 * @param  integer $perPage
216
+	 * @param  string  $sortBy
217
+	 * @param  boolean $desc
218
+	 * @return \Illuminate\Http\Response
219
+	 */
220
+	public function group(Request $request, $groupName, $perPage = 15, $sortBy = 'created_at', $desc = 1)
221
+	{
222
+		$relations = $this->relations && $this->relations['group'] ? $this->relations['group'] : [];
223
+		return \Response::json(\Core::users()->group($request->all(), $groupName, $relations, $perPage, $sortBy, $desc), 200);
224
+	}
225 225
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Utl/ErrorHandler.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -2,105 +2,105 @@
 block discarded – undo
2 2
 
3 3
 class ErrorHandler
4 4
 {
5
-    public function unAuthorized()
6
-    {
7
-        $error = ['status' => 401, 'message' => trans('errors.unAuthorized')];
8
-        abort($error['status'], $error['message']);
9
-    }
10
-
11
-    public function tokenExpired()
12
-    {
13
-        $error = ['status' => 403, 'message' => trans('errors.tokenExpired')];
14
-        abort($error['status'], $error['message']);
15
-    }
16
-
17
-     public function noPermissions()
18
-    {
19
-        $error = ['status' => 403, 'message' => trans('errors.noPermissions')];
20
-        abort($error['status'], $error['message']);
21
-    }
22
-
23
-    public function loginFailed()
24
-    {
25
-        $error = ['status' => 400, 'message' => trans('errors.loginFailed')];
26
-        abort($error['status'], $error['message']);
27
-    }
28
-
29
-    public function noSocialEmail()
30
-    {
31
-        $error = ['status' => 400, 'message' => trans('errors.noSocialEmail')];
32
-        abort($error['status'], $error['message']);
33
-    }
34
-
35
-    public function userAlreadyRegistered()
36
-    {
37
-        $error = ['status' => 400, 'message' => trans('errors.userAlreadyRegistered')];
38
-        abort($error['status'], $error['message']);
39
-    }
40
-
41
-    public function connectionError()
42
-    {
43
-        $error = ['status' => 400, 'message' => trans('errors.connectionError')];
44
-        abort($error['status'], $error['message']);
45
-    }
46
-
47
-    public function redisNotRunning()
48
-    {
49
-        $error = ['status' => 400, 'message' => trans('errors.redisNotRunning')];
50
-        abort($error['status'], $error['message']);
51
-    }
52
-
53
-    public function dbQueryError()
54
-    {
55
-        $error = ['status' => 400, 'message' => trans('errors.dbQueryError')];
56
-        abort($error['status'], $error['message']);
57
-    }
58
-
59
-    public function cannotCreateSetting()
60
-    {
61
-        $error = ['status' => 400, 'message' => trans('errors.cannotCreateSetting')];
62
-        abort($error['status'], $error['message']);
63
-    }
64
-
65
-    public function cannotUpdateSettingKey()
66
-    {
67
-        $error = ['status' => 400, 'message' => trans('errors.cannotUpdateSettingKey')];
68
-        abort($error['status'], $error['message']);
69
-    }
70
-
71
-    public function userIsBlocked()
72
-    {
73
-        $error = ['status' => 403, 'message' => trans('errors.userIsBlocked')];
74
-        abort($error['status'], $error['message']);
75
-    }
76
-
77
-    public function invalidResetToken()
78
-    {
79
-        $error = ['status' => 400, 'message' => trans('errors.invalidResetToken')];
80
-        abort($error['status'], $error['message']);
81
-    }
82
-
83
-    public function invalidResetPassword()
84
-    {
85
-        $error = ['status' => 400, 'message' => trans('errors.invalidResetPassword')];
86
-        abort($error['status'], $error['message']);
87
-    }
88
-
89
-    public function invalidOldPassword()
90
-    {
91
-        $error = ['status' => 400, 'message' => trans('errors.invalidOldPassword')];
92
-        abort($error['status'], $error['message']);
93
-    }
94
-
95
-    public function notFound($text)
96
-    {
97
-        $error = ['status' => 404, 'message' => trans('errors.notFound', ['replace' => $text])];
98
-        abort($error['status'], $error['message']);
99
-    }
100
-
101
-    public function generalError()
102
-    {
103
-        $error = ['status' => 404, 'message' => trans('errors.generalError')];
104
-        abort($error['status'], $error['message']);
105
-    }
5
+	public function unAuthorized()
6
+	{
7
+		$error = ['status' => 401, 'message' => trans('errors.unAuthorized')];
8
+		abort($error['status'], $error['message']);
9
+	}
10
+
11
+	public function tokenExpired()
12
+	{
13
+		$error = ['status' => 403, 'message' => trans('errors.tokenExpired')];
14
+		abort($error['status'], $error['message']);
15
+	}
16
+
17
+	 public function noPermissions()
18
+	{
19
+		$error = ['status' => 403, 'message' => trans('errors.noPermissions')];
20
+		abort($error['status'], $error['message']);
21
+	}
22
+
23
+	public function loginFailed()
24
+	{
25
+		$error = ['status' => 400, 'message' => trans('errors.loginFailed')];
26
+		abort($error['status'], $error['message']);
27
+	}
28
+
29
+	public function noSocialEmail()
30
+	{
31
+		$error = ['status' => 400, 'message' => trans('errors.noSocialEmail')];
32
+		abort($error['status'], $error['message']);
33
+	}
34
+
35
+	public function userAlreadyRegistered()
36
+	{
37
+		$error = ['status' => 400, 'message' => trans('errors.userAlreadyRegistered')];
38
+		abort($error['status'], $error['message']);
39
+	}
40
+
41
+	public function connectionError()
42
+	{
43
+		$error = ['status' => 400, 'message' => trans('errors.connectionError')];
44
+		abort($error['status'], $error['message']);
45
+	}
46
+
47
+	public function redisNotRunning()
48
+	{
49
+		$error = ['status' => 400, 'message' => trans('errors.redisNotRunning')];
50
+		abort($error['status'], $error['message']);
51
+	}
52
+
53
+	public function dbQueryError()
54
+	{
55
+		$error = ['status' => 400, 'message' => trans('errors.dbQueryError')];
56
+		abort($error['status'], $error['message']);
57
+	}
58
+
59
+	public function cannotCreateSetting()
60
+	{
61
+		$error = ['status' => 400, 'message' => trans('errors.cannotCreateSetting')];
62
+		abort($error['status'], $error['message']);
63
+	}
64
+
65
+	public function cannotUpdateSettingKey()
66
+	{
67
+		$error = ['status' => 400, 'message' => trans('errors.cannotUpdateSettingKey')];
68
+		abort($error['status'], $error['message']);
69
+	}
70
+
71
+	public function userIsBlocked()
72
+	{
73
+		$error = ['status' => 403, 'message' => trans('errors.userIsBlocked')];
74
+		abort($error['status'], $error['message']);
75
+	}
76
+
77
+	public function invalidResetToken()
78
+	{
79
+		$error = ['status' => 400, 'message' => trans('errors.invalidResetToken')];
80
+		abort($error['status'], $error['message']);
81
+	}
82
+
83
+	public function invalidResetPassword()
84
+	{
85
+		$error = ['status' => 400, 'message' => trans('errors.invalidResetPassword')];
86
+		abort($error['status'], $error['message']);
87
+	}
88
+
89
+	public function invalidOldPassword()
90
+	{
91
+		$error = ['status' => 400, 'message' => trans('errors.invalidOldPassword')];
92
+		abort($error['status'], $error['message']);
93
+	}
94
+
95
+	public function notFound($text)
96
+	{
97
+		$error = ['status' => 404, 'message' => trans('errors.notFound', ['replace' => $text])];
98
+		abort($error['status'], $error['message']);
99
+	}
100
+
101
+	public function generalError()
102
+	{
103
+		$error = ['status' => 404, 'message' => trans('errors.generalError')];
104
+		abort($error['status'], $error['message']);
105
+	}
106 106
 }
107 107
\ No newline at end of file
Please login to merge, or discard this patch.