Completed
Push — master ( acebc9...8b745b )
by Sherif
02:05
created
src/Modules/V1/Core/ModelObservers/LogObserver.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -5,53 +5,53 @@
 block discarded – undo
5 5
  */
6 6
 class LogObserver {
7 7
 
8
-    public function saving($model)
9
-    {
10
-        //
11
-    }
12
-
13
-    public function saved($model)
14
-    {
15
-        //
16
-    }
17
-
18
-    public function creating($model)
19
-    {
20
-        //
21
-    }
22
-
23
-    public function created($model)
24
-    {
25
-        //
26
-    }
27
-
28
-    public function updating($model)
29
-    {
30
-        //
31
-    }
32
-
33
-    public function updated($model)
34
-    {
35
-        //
36
-    }
37
-
38
-    public function deleting($model)
39
-    {
40
-        //
41
-    }
42
-
43
-    public function deleted($model)
44
-    {
45
-        //
46
-    }
47
-
48
-    public function restoring($model)
49
-    {
50
-        //
51
-    }
52
-
53
-    public function restored($model)
54
-    {
55
-        //
56
-    }
8
+	public function saving($model)
9
+	{
10
+		//
11
+	}
12
+
13
+	public function saved($model)
14
+	{
15
+		//
16
+	}
17
+
18
+	public function creating($model)
19
+	{
20
+		//
21
+	}
22
+
23
+	public function created($model)
24
+	{
25
+		//
26
+	}
27
+
28
+	public function updating($model)
29
+	{
30
+		//
31
+	}
32
+
33
+	public function updated($model)
34
+	{
35
+		//
36
+	}
37
+
38
+	public function deleting($model)
39
+	{
40
+		//
41
+	}
42
+
43
+	public function deleted($model)
44
+	{
45
+		//
46
+	}
47
+
48
+	public function restoring($model)
49
+	{
50
+		//
51
+	}
52
+
53
+	public function restored($model)
54
+	{
55
+		//
56
+	}
57 57
 }
58 58
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/ModelObservers/SettingsObserver.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -5,68 +5,68 @@
 block discarded – undo
5 5
  */
6 6
 class SettingsObserver {
7 7
 
8
-    public function saving($model)
9
-    {
10
-        //
11
-    }
8
+	public function saving($model)
9
+	{
10
+		//
11
+	}
12 12
 
13
-    public function saved($model)
14
-    {
15
-        //
16
-    }
13
+	public function saved($model)
14
+	{
15
+		//
16
+	}
17 17
 
18
-    /**
19
-     * Prevent the creating of the settings.
20
-     * 
21
-     * @param  object $model the model beign created.
22
-     * @return void
23
-     */
24
-    public function creating($model)
25
-    {
26
-        \ErrorHandler::cannotCreateSetting();
27
-    }
18
+	/**
19
+	 * Prevent the creating of the settings.
20
+	 * 
21
+	 * @param  object $model the model beign created.
22
+	 * @return void
23
+	 */
24
+	public function creating($model)
25
+	{
26
+		\ErrorHandler::cannotCreateSetting();
27
+	}
28 28
 
29
-    public function created($model)
30
-    {
31
-        //
32
-    }
29
+	public function created($model)
30
+	{
31
+		//
32
+	}
33 33
 
34
-    /**
35
-     * Prevent updating of the setting key.
36
-     * 
37
-     * @param  object $model the model beign updated.
38
-     * @return void
39
-     */
40
-    public function updating($model)
41
-    {
42
-        if ($model->getOriginal('key') !== $model->key) 
43
-        {
44
-            \ErrorHandler::cannotUpdateSettingKey();
45
-        }
46
-    }
34
+	/**
35
+	 * Prevent updating of the setting key.
36
+	 * 
37
+	 * @param  object $model the model beign updated.
38
+	 * @return void
39
+	 */
40
+	public function updating($model)
41
+	{
42
+		if ($model->getOriginal('key') !== $model->key) 
43
+		{
44
+			\ErrorHandler::cannotUpdateSettingKey();
45
+		}
46
+	}
47 47
 
48
-    public function updated($model)
49
-    {
50
-        //
51
-    }
48
+	public function updated($model)
49
+	{
50
+		//
51
+	}
52 52
 
53
-    public function deleting($model)
54
-    {
55
-        //
56
-    }
53
+	public function deleting($model)
54
+	{
55
+		//
56
+	}
57 57
 
58
-    public function deleted($model)
59
-    {
60
-        //
61
-    }
58
+	public function deleted($model)
59
+	{
60
+		//
61
+	}
62 62
 
63
-    public function restoring($model)
64
-    {
65
-        //
66
-    }
63
+	public function restoring($model)
64
+	{
65
+		//
66
+	}
67 67
 
68
-    public function restored($model)
69
-    {
70
-        //
71
-    }
68
+	public function restored($model)
69
+	{
70
+		//
71
+	}
72 72
 }
73 73
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/Utl/CoreConfig.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -3,10 +3,10 @@  discard block
 block discarded – undo
3 3
 
4 4
 class CoreConfig
5 5
 {
6
-    public function getConfig()
7
-    {
8
-        return [
9
-        	'resetLink' => '{{link_here}}',
6
+	public function getConfig()
7
+	{
8
+		return [
9
+			'resetLink' => '{{link_here}}',
10 10
 			/**
11 11
 			 * Specify what relations should be used for every model.
12 12
 			 */
@@ -180,5 +180,5 @@  discard block
 block discarded – undo
180 180
 				]
181 181
 			]
182 182
 		];
183
-    }
183
+	}
184 184
 }
185 185
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/Http/Controllers/BaseApiController.php 1 patch
Indentation   +268 added lines, -268 removed lines patch added patch discarded remove patch
@@ -6,298 +6,298 @@
 block discarded – undo
6 6
 
7 7
 class BaseApiController extends Controller
8 8
 {
9
-    /**
10
-     * The config implementation.
11
-     * 
12
-     * @var array
13
-     */
14
-    protected $config;
9
+	/**
10
+	 * The config implementation.
11
+	 * 
12
+	 * @var array
13
+	 */
14
+	protected $config;
15 15
 
16
-    /**
17
-     * The relations implementation.
18
-     * 
19
-     * @var array
20
-     */
21
-    protected $relations;
16
+	/**
17
+	 * The relations implementation.
18
+	 * 
19
+	 * @var array
20
+	 */
21
+	protected $relations;
22 22
 
23
-    /**
24
-     * The repo implementation.
25
-     * 
26
-     * @var array
27
-     */
28
-    protected $repo;
23
+	/**
24
+	 * The repo implementation.
25
+	 * 
26
+	 * @var array
27
+	 */
28
+	protected $repo;
29 29
 
30
-    public function __construct()
31
-    {        
32
-        $this->config              = \CoreConfig::getConfig();
33
-        $this->model               = property_exists($this, 'model') ? $this->model : false;
34
-        $this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
35
-        $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
36
-        $this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
37
-        $this->repo                = call_user_func_array("\Core::{$this->model}", []);
38
-        $route                     = explode('@',\Route::currentRouteAction())[1];
30
+	public function __construct()
31
+	{        
32
+		$this->config              = \CoreConfig::getConfig();
33
+		$this->model               = property_exists($this, 'model') ? $this->model : false;
34
+		$this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
35
+		$this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
36
+		$this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
37
+		$this->repo                = call_user_func_array("\Core::{$this->model}", []);
38
+		$route                     = explode('@',\Route::currentRouteAction())[1];
39 39
 
40
-        $this->checkPermission($route);
41
-        $this->setRelations($route);
42
-        $this->setSessions();
43
-    }
40
+		$this->checkPermission($route);
41
+		$this->setRelations($route);
42
+		$this->setSessions();
43
+	}
44 44
 
45
-    /**
46
-     * Fetch all records with relations from storage.
47
-     * 
48
-     * @param  string  $sortBy The name of the column to sort by.
49
-     * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
50
-     * @return \Illuminate\Http\Response
51
-     */
52
-    public function index($sortBy = 'created_at', $desc = 1) 
53
-    {
54
-        if ($this->repo)
55
-        {
56
-            return \Response::json($this->repo->all($this->relations, $sortBy, $desc), 200);
57
-        }
58
-    }
45
+	/**
46
+	 * Fetch all records with relations from storage.
47
+	 * 
48
+	 * @param  string  $sortBy The name of the column to sort by.
49
+	 * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
50
+	 * @return \Illuminate\Http\Response
51
+	 */
52
+	public function index($sortBy = 'created_at', $desc = 1) 
53
+	{
54
+		if ($this->repo)
55
+		{
56
+			return \Response::json($this->repo->all($this->relations, $sortBy, $desc), 200);
57
+		}
58
+	}
59 59
 
60
-    /**
61
-     * Fetch the single object with relations from storage.
62
-     * 
63
-     * @param  integer $id Id of the requested model.
64
-     * @return \Illuminate\Http\Response
65
-     */
66
-    public function find($id) 
67
-    {
68
-        if ($this->repo) 
69
-        {
70
-            return \Response::json($this->repo->find($id, $this->relations), 200);
71
-        }
72
-    }
60
+	/**
61
+	 * Fetch the single object with relations from storage.
62
+	 * 
63
+	 * @param  integer $id Id of the requested model.
64
+	 * @return \Illuminate\Http\Response
65
+	 */
66
+	public function find($id) 
67
+	{
68
+		if ($this->repo) 
69
+		{
70
+			return \Response::json($this->repo->find($id, $this->relations), 200);
71
+		}
72
+	}
73 73
 
74
-    /**
75
-     * Paginate all records with relations from storage
76
-     * that matche the given query.
77
-     * 
78
-     * @param  string  $query   The search text.
79
-     * @param  integer $perPage Number of rows per page default 15.
80
-     * @param  string  $sortBy  The name of the column to sort by.
81
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
82
-     * @return \Illuminate\Http\Response
83
-     */
84
-    public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
85
-    {
86
-        if ($this->repo) 
87
-        {
88
-            return \Response::json($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc), 200);
89
-        }
90
-    }
74
+	/**
75
+	 * Paginate all records with relations from storage
76
+	 * that matche the given query.
77
+	 * 
78
+	 * @param  string  $query   The search text.
79
+	 * @param  integer $perPage Number of rows per page default 15.
80
+	 * @param  string  $sortBy  The name of the column to sort by.
81
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
82
+	 * @return \Illuminate\Http\Response
83
+	 */
84
+	public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
85
+	{
86
+		if ($this->repo) 
87
+		{
88
+			return \Response::json($this->repo->search($query, $perPage, $this->relations, $sortBy, $desc), 200);
89
+		}
90
+	}
91 91
 
92
-    /**
93
-     * Fetch records from the storage based on the given
94
-     * condition.
95
-     * 
96
-     * @param  \Illuminate\Http\Request  $request
97
-     * @param  string  $sortBy The name of the column to sort by.
98
-     * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
99
-     * @return \Illuminate\Http\Response
100
-     */
101
-    public function findby(Request $request, $sortBy = 'created_at', $desc = 1) 
102
-    {
103
-        if ($this->repo) 
104
-        {
105
-            return \Response::json($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc), 200);
106
-        }
107
-    }
92
+	/**
93
+	 * Fetch records from the storage based on the given
94
+	 * condition.
95
+	 * 
96
+	 * @param  \Illuminate\Http\Request  $request
97
+	 * @param  string  $sortBy The name of the column to sort by.
98
+	 * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
99
+	 * @return \Illuminate\Http\Response
100
+	 */
101
+	public function findby(Request $request, $sortBy = 'created_at', $desc = 1) 
102
+	{
103
+		if ($this->repo) 
104
+		{
105
+			return \Response::json($this->repo->findBy($request->all(), $this->relations, $sortBy, $desc), 200);
106
+		}
107
+	}
108 108
 
109
-    /**
110
-     * Fetch the first record from the storage based on the given
111
-     * condition.
112
-     * 
113
-     * @param  \Illuminate\Http\Request  $request
114
-     * @return \Illuminate\Http\Response
115
-     */
116
-    public function first(Request $request) 
117
-    {
118
-        if ($this->repo) 
119
-        {
120
-            return \Response::json($this->repo->first($request->all(), $this->relations), 200);
121
-        }
122
-    }
109
+	/**
110
+	 * Fetch the first record from the storage based on the given
111
+	 * condition.
112
+	 * 
113
+	 * @param  \Illuminate\Http\Request  $request
114
+	 * @return \Illuminate\Http\Response
115
+	 */
116
+	public function first(Request $request) 
117
+	{
118
+		if ($this->repo) 
119
+		{
120
+			return \Response::json($this->repo->first($request->all(), $this->relations), 200);
121
+		}
122
+	}
123 123
 
124
-    /**
125
-     * Paginate all records with relations from storage.
126
-     * 
127
-     * @param  integer $perPage Number of rows per page default 15.
128
-     * @param  string  $sortBy  The name of the column to sort by.
129
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
130
-     * @return \Illuminate\Http\Response
131
-     */
132
-    public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
133
-    {
134
-        if ($this->repo) 
135
-        {
136
-            return \Response::json($this->repo->paginate($perPage, $this->relations, $sortBy, $desc), 200);
137
-        }
138
-    }
124
+	/**
125
+	 * Paginate all records with relations from storage.
126
+	 * 
127
+	 * @param  integer $perPage Number of rows per page default 15.
128
+	 * @param  string  $sortBy  The name of the column to sort by.
129
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
130
+	 * @return \Illuminate\Http\Response
131
+	 */
132
+	public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
133
+	{
134
+		if ($this->repo) 
135
+		{
136
+			return \Response::json($this->repo->paginate($perPage, $this->relations, $sortBy, $desc), 200);
137
+		}
138
+	}
139 139
 
140
-    /**
141
-     * Fetch all records with relations based on
142
-     * the given condition from storage in pages.
143
-     * 
144
-     * @param  \Illuminate\Http\Request  $request
145
-     * @param  integer $perPage Number of rows per page default 15.
146
-     * @param  string  $sortBy  The name of the column to sort by.
147
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
148
-     * @return \Illuminate\Http\Response
149
-     */
150
-    public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
151
-    {
152
-        if ($this->repo) 
153
-        {
154
-            return \Response::json($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200);
155
-        }
156
-    }
140
+	/**
141
+	 * Fetch all records with relations based on
142
+	 * the given condition from storage in pages.
143
+	 * 
144
+	 * @param  \Illuminate\Http\Request  $request
145
+	 * @param  integer $perPage Number of rows per page default 15.
146
+	 * @param  string  $sortBy  The name of the column to sort by.
147
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
148
+	 * @return \Illuminate\Http\Response
149
+	 */
150
+	public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
151
+	{
152
+		if ($this->repo) 
153
+		{
154
+			return \Response::json($this->repo->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200);
155
+		}
156
+	}
157 157
 
158
-    /**
159
-     * Save the given model to storage.
160
-     * 
161
-     * @param  \Illuminate\Http\Request  $request
162
-     * @return \Illuminate\Http\Response
163
-     */
164
-    public function save(Request $request) 
165
-    {
166
-        foreach ($this->validationRules as &$rule) 
167
-        {
168
-            if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
169
-            {
170
-                $rule .= ',deleted_at,NULL';
171
-            }
158
+	/**
159
+	 * Save the given model to storage.
160
+	 * 
161
+	 * @param  \Illuminate\Http\Request  $request
162
+	 * @return \Illuminate\Http\Response
163
+	 */
164
+	public function save(Request $request) 
165
+	{
166
+		foreach ($this->validationRules as &$rule) 
167
+		{
168
+			if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
169
+			{
170
+				$rule .= ',deleted_at,NULL';
171
+			}
172 172
 
173
-            if ($request->has('id')) 
174
-            {
175
-                $rule = str_replace('{id}', $request->get('id'), $rule);
176
-            }
177
-            else
178
-            {
179
-                $rule = str_replace(',{id}', '', $rule);
180
-            }
181
-        }
173
+			if ($request->has('id')) 
174
+			{
175
+				$rule = str_replace('{id}', $request->get('id'), $rule);
176
+			}
177
+			else
178
+			{
179
+				$rule = str_replace(',{id}', '', $rule);
180
+			}
181
+		}
182 182
         
183
-        $this->validate($request, $this->validationRules);
183
+		$this->validate($request, $this->validationRules);
184 184
 
185
-        if ($this->repo) 
186
-        {
187
-            return \Response::json($this->repo->save($request->all()), 200);
188
-        }
189
-    }
185
+		if ($this->repo) 
186
+		{
187
+			return \Response::json($this->repo->save($request->all()), 200);
188
+		}
189
+	}
190 190
 
191
-    /**
192
-     * Delete by the given id from storage.
193
-     * 
194
-     * @param  integer $id Id of the deleted model.
195
-     * @return \Illuminate\Http\Response
196
-     */
197
-    public function delete($id) 
198
-    {
199
-        if ($this->repo) 
200
-        {
201
-            return \Response::json($this->repo->delete($id), 200);
202
-        }
203
-    }
191
+	/**
192
+	 * Delete by the given id from storage.
193
+	 * 
194
+	 * @param  integer $id Id of the deleted model.
195
+	 * @return \Illuminate\Http\Response
196
+	 */
197
+	public function delete($id) 
198
+	{
199
+		if ($this->repo) 
200
+		{
201
+			return \Response::json($this->repo->delete($id), 200);
202
+		}
203
+	}
204 204
 
205
-    /**
206
-     * Return the deleted models in pages based on the given conditions.
207
-     *
208
-     * @param  \Illuminate\Http\Request  $request
209
-     * @param  integer $perPage Number of rows per page default 15.
210
-     * @param  string  $sortBy  The name of the column to sort by.
211
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
212
-     * @return \Illuminate\Http\Response
213
-     */
214
-    public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
215
-    {
216
-        return \Response::json($this->repo->deleted($request->all(), $perPage, $sortBy, $desc), 200);
217
-    }
205
+	/**
206
+	 * Return the deleted models in pages based on the given conditions.
207
+	 *
208
+	 * @param  \Illuminate\Http\Request  $request
209
+	 * @param  integer $perPage Number of rows per page default 15.
210
+	 * @param  string  $sortBy  The name of the column to sort by.
211
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
212
+	 * @return \Illuminate\Http\Response
213
+	 */
214
+	public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
215
+	{
216
+		return \Response::json($this->repo->deleted($request->all(), $perPage, $sortBy, $desc), 200);
217
+	}
218 218
 
219
-    /**
220
-     * Restore the deleted model.
221
-     * 
222
-     * @param  integer $id Id of the restored model.
223
-     * @return \Illuminate\Http\Response
224
-     */
225
-    public function restore($id) 
226
-    {
227
-        if ($this->repo) 
228
-        {
229
-            return \Response::json($this->repo->restore($id), 200);
230
-        }
231
-    }
219
+	/**
220
+	 * Restore the deleted model.
221
+	 * 
222
+	 * @param  integer $id Id of the restored model.
223
+	 * @return \Illuminate\Http\Response
224
+	 */
225
+	public function restore($id) 
226
+	{
227
+		if ($this->repo) 
228
+		{
229
+			return \Response::json($this->repo->restore($id), 200);
230
+		}
231
+	}
232 232
 
233
-    /**
234
-     * Check if the logged in user can do the given permission.
235
-     * 
236
-     * @param  string $permission
237
-     * @return void
238
-     */
239
-    private function checkPermission($permission)
240
-    {
241
-        $permission = $permission !== 'index' ? $permission : 'list';
242
-        if ( ! in_array($permission, $this->skipLoginCheck)) 
243
-        {
244
-            $user = \JWTAuth::parseToken()->authenticate();
245
-            if ($user->blocked)
246
-            {
247
-                \ErrorHandler::userIsBlocked();
248
-            }
233
+	/**
234
+	 * Check if the logged in user can do the given permission.
235
+	 * 
236
+	 * @param  string $permission
237
+	 * @return void
238
+	 */
239
+	private function checkPermission($permission)
240
+	{
241
+		$permission = $permission !== 'index' ? $permission : 'list';
242
+		if ( ! in_array($permission, $this->skipLoginCheck)) 
243
+		{
244
+			$user = \JWTAuth::parseToken()->authenticate();
245
+			if ($user->blocked)
246
+			{
247
+				\ErrorHandler::userIsBlocked();
248
+			}
249 249
             
250
-            if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model))
251
-            {
252
-                \ErrorHandler::noPermissions();
253
-            }
254
-        }
255
-    }
250
+			if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model))
251
+			{
252
+				\ErrorHandler::noPermissions();
253
+			}
254
+		}
255
+	}
256 256
 
257
-    /**
258
-     * Set sessions based on the given headers in the request.
259
-     * 
260
-     * @return void
261
-     */
262
-    private function setSessions()
263
-    {
264
-        \Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
257
+	/**
258
+	 * Set sessions based on the given headers in the request.
259
+	 * 
260
+	 * @return void
261
+	 */
262
+	private function setSessions()
263
+	{
264
+		\Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
265 265
 
266
-        $locale = \Request::header('locale');
267
-        switch ($locale) 
268
-        {
269
-            case 'en':
270
-            \App::setLocale('en');
271
-            \Session::put('locale', 'en');
272
-            break;
266
+		$locale = \Request::header('locale');
267
+		switch ($locale) 
268
+		{
269
+			case 'en':
270
+			\App::setLocale('en');
271
+			\Session::put('locale', 'en');
272
+			break;
273 273
 
274
-            case 'ar':
275
-            \App::setLocale('ar');
276
-            \Session::put('locale', 'ar');
277
-            break;
274
+			case 'ar':
275
+			\App::setLocale('ar');
276
+			\Session::put('locale', 'ar');
277
+			break;
278 278
 
279
-            case 'all':
280
-            \App::setLocale('en');
281
-            \Session::put('locale', 'all');
282
-            break;
279
+			case 'all':
280
+			\App::setLocale('en');
281
+			\Session::put('locale', 'all');
282
+			break;
283 283
 
284
-            default:
285
-            \App::setLocale('en');
286
-            \Session::put('locale', 'en');
287
-            break;
288
-        }
289
-    }
284
+			default:
285
+			\App::setLocale('en');
286
+			\Session::put('locale', 'en');
287
+			break;
288
+		}
289
+	}
290 290
 
291
-    /**
292
-     * Set relation based on the called api.
293
-     * 
294
-     * @param  string $route
295
-     * @return void
296
-     */
297
-    private function setRelations($route)
298
-    {
299
-        $route           = $route !== 'index' ? $route : 'list';
300
-        $relations       = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
301
-        $this->relations = $relations && $relations[$route] ? $relations[$route] : [];
302
-    }
291
+	/**
292
+	 * Set relation based on the called api.
293
+	 * 
294
+	 * @param  string $route
295
+	 * @return void
296
+	 */
297
+	private function setRelations($route)
298
+	{
299
+		$route           = $route !== 'index' ? $route : 'list';
300
+		$relations       = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
301
+		$this->relations = $relations && $relations[$route] ? $relations[$route] : [];
302
+	}
303 303
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Console/Commands/GenerateDoc.php 1 patch
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -6,270 +6,270 @@
 block discarded – undo
6 6
 
7 7
 class GenerateDoc extends Command
8 8
 {
9
-    /**
10
-     * The name and signature of the console command.
11
-     *
12
-     * @var string
13
-     */
14
-    protected $signature = 'doc:generate';
9
+	/**
10
+	 * The name and signature of the console command.
11
+	 *
12
+	 * @var string
13
+	 */
14
+	protected $signature = 'doc:generate';
15 15
 
16
-    /**
17
-     * The console command description.
18
-     *
19
-     * @var string
20
-     */
21
-    protected $description = 'Generate api documentation';
16
+	/**
17
+	 * The console command description.
18
+	 *
19
+	 * @var string
20
+	 */
21
+	protected $description = 'Generate api documentation';
22 22
 
23
-    /**
24
-     * Create a new command instance.
25
-     *
26
-     * @return void
27
-     */
28
-    public function __construct()
29
-    {
30
-        parent::__construct();
31
-    }
23
+	/**
24
+	 * Create a new command instance.
25
+	 *
26
+	 * @return void
27
+	 */
28
+	public function __construct()
29
+	{
30
+		parent::__construct();
31
+	}
32 32
 
33
-    /**
34
-     * Execute the console command.
35
-     *
36
-     * @return mixed
37
-     */
38
-    public function handle()
39
-    {
40
-        $docData           = [];
41
-        $docData['models'] = [];
42
-        $routes            = $this->getRoutes();
43
-        foreach ($routes as $route) 
44
-        {
45
-            if ($route) 
46
-            {
47
-                $actoinArray       = explode('@', $route['action']);
48
-                $controller        = $actoinArray[0];
49
-                $method            = $actoinArray[1];
50
-                $route['name']     = $method !== 'index' ? $method : 'list';
33
+	/**
34
+	 * Execute the console command.
35
+	 *
36
+	 * @return mixed
37
+	 */
38
+	public function handle()
39
+	{
40
+		$docData           = [];
41
+		$docData['models'] = [];
42
+		$routes            = $this->getRoutes();
43
+		foreach ($routes as $route) 
44
+		{
45
+			if ($route) 
46
+			{
47
+				$actoinArray       = explode('@', $route['action']);
48
+				$controller        = $actoinArray[0];
49
+				$method            = $actoinArray[1];
50
+				$route['name']     = $method !== 'index' ? $method : 'list';
51 51
                 
52
-                $reflectionClass   = new \ReflectionClass($controller);
53
-                $reflectionMethod  = $reflectionClass->getMethod($method);
54
-                $classProperties   = $reflectionClass->getDefaultProperties();
55
-                $skipLoginCheck    = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false;
56
-                $validationRules   = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false;
52
+				$reflectionClass   = new \ReflectionClass($controller);
53
+				$reflectionMethod  = $reflectionClass->getMethod($method);
54
+				$classProperties   = $reflectionClass->getDefaultProperties();
55
+				$skipLoginCheck    = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false;
56
+				$validationRules   = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false;
57 57
                 
58
-                $route['response'] = $this->getResponseObject($classProperties['model'], $route['name']);
58
+				$route['response'] = $this->getResponseObject($classProperties['model'], $route['name']);
59 59
 
60
-                $this->processDocBlock($route, $reflectionMethod);
61
-                $this->getHeaders($route, $reflectionClass, $method, $skipLoginCheck);
62
-                $this->getPostData($route, $reflectionMethod, $validationRules);
60
+				$this->processDocBlock($route, $reflectionMethod);
61
+				$this->getHeaders($route, $reflectionClass, $method, $skipLoginCheck);
62
+				$this->getPostData($route, $reflectionMethod, $validationRules);
63 63
 
64
-                preg_match('/api\/v1\/([^#]+)\//iU', $route['uri'], $module);
65
-                preg_match('/api\/v1\/' . $module[1] . '\/([^#]+)\//iU', $route['uri'], $model);
66
-                $docData['modules'][$module[1]][$model[1]][] = $route;
64
+				preg_match('/api\/v1\/([^#]+)\//iU', $route['uri'], $module);
65
+				preg_match('/api\/v1\/' . $module[1] . '\/([^#]+)\//iU', $route['uri'], $model);
66
+				$docData['modules'][$module[1]][$model[1]][] = $route;
67 67
 
68
-                $this->getModels($classProperties['model'], $docData);
69
-            }
70
-        }
68
+				$this->getModels($classProperties['model'], $docData);
69
+			}
70
+		}
71 71
         
72
-        $docData['errors'] = $this->getErrors();
73
-        \File::put(app_path('Modules/V1/Core/Resources/api.json'), json_encode($docData));
74
-    }
72
+		$docData['errors'] = $this->getErrors();
73
+		\File::put(app_path('Modules/V1/Core/Resources/api.json'), json_encode($docData));
74
+	}
75 75
 
76
-    /**
77
-     * Get list of all registered routes.
78
-     * 
79
-     * @return collection
80
-     */
81
-    protected function getRoutes()
82
-    {
83
-        return collect(\Route::getRoutes())->map(function ($route) {
84
-            if (strpos($route->uri(), 'api/v') !== false) 
85
-            {
86
-                return [
87
-                    'method' => $route->methods()[0],
88
-                    'uri'    => $route->uri(),
89
-                    'action' => $route->getActionName()
90
-                ];
91
-            }
92
-            return false;
93
-        })->all();
94
-    }
76
+	/**
77
+	 * Get list of all registered routes.
78
+	 * 
79
+	 * @return collection
80
+	 */
81
+	protected function getRoutes()
82
+	{
83
+		return collect(\Route::getRoutes())->map(function ($route) {
84
+			if (strpos($route->uri(), 'api/v') !== false) 
85
+			{
86
+				return [
87
+					'method' => $route->methods()[0],
88
+					'uri'    => $route->uri(),
89
+					'action' => $route->getActionName()
90
+				];
91
+			}
92
+			return false;
93
+		})->all();
94
+	}
95 95
 
96
-    /**
97
-     * Generate headers for the given route.
98
-     * 
99
-     * @param  array  &$route
100
-     * @param  object $reflectionClass
101
-     * @param  string $method
102
-     * @param  array  $skipLoginCheck
103
-     * @return void
104
-     */
105
-    protected function getHeaders(&$route, $reflectionClass, $method, $skipLoginCheck)
106
-    {
107
-        $route['headers'] = [
108
-        'Accept'         => 'application/json',
109
-        'Content-Type'   => 'application/json',
110
-        'locale'         => 'The language of the returned data: ar, en or all.',
111
-        'time-zone-diff' => 'Timezone difference between UTC and Local Time',
112
-        ];
96
+	/**
97
+	 * Generate headers for the given route.
98
+	 * 
99
+	 * @param  array  &$route
100
+	 * @param  object $reflectionClass
101
+	 * @param  string $method
102
+	 * @param  array  $skipLoginCheck
103
+	 * @return void
104
+	 */
105
+	protected function getHeaders(&$route, $reflectionClass, $method, $skipLoginCheck)
106
+	{
107
+		$route['headers'] = [
108
+		'Accept'         => 'application/json',
109
+		'Content-Type'   => 'application/json',
110
+		'locale'         => 'The language of the returned data: ar, en or all.',
111
+		'time-zone-diff' => 'Timezone difference between UTC and Local Time',
112
+		];
113 113
 
114 114
 
115
-        if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
116
-        {
117
-            $route['headers']['Authrization'] = 'bearer {token}';
118
-        }
119
-    }
115
+		if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
116
+		{
117
+			$route['headers']['Authrization'] = 'bearer {token}';
118
+		}
119
+	}
120 120
 
121
-    /**
122
-     * Generate description and params for the given route
123
-     * based on the docblock.
124
-     * 
125
-     * @param  array  &$route
126
-     * @param  object $reflectionMethod]
127
-     * @return void
128
-     */
129
-    protected function processDocBlock(&$route, $reflectionMethod)
130
-    {
131
-        $factory              = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
132
-        $docblock             = $factory->create($reflectionMethod->getDocComment());
133
-        $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
134
-        $params               = $docblock->getTagsByName('param');
135
-        foreach ($params as $param) 
136
-        {
137
-            $name = $param->getVariableName();
138
-            if ($name !== 'request') 
139
-            {
140
-                $route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
141
-            }
142
-        }
143
-    }
121
+	/**
122
+	 * Generate description and params for the given route
123
+	 * based on the docblock.
124
+	 * 
125
+	 * @param  array  &$route
126
+	 * @param  object $reflectionMethod]
127
+	 * @return void
128
+	 */
129
+	protected function processDocBlock(&$route, $reflectionMethod)
130
+	{
131
+		$factory              = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
132
+		$docblock             = $factory->create($reflectionMethod->getDocComment());
133
+		$route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
134
+		$params               = $docblock->getTagsByName('param');
135
+		foreach ($params as $param) 
136
+		{
137
+			$name = $param->getVariableName();
138
+			if ($name !== 'request') 
139
+			{
140
+				$route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
141
+			}
142
+		}
143
+	}
144 144
 
145
-    /**
146
-     * Generate post body for the given route.
147
-     * 
148
-     * @param  array  &$route
149
-     * @param  object $reflectionMethod
150
-     * @param  array  $validationRules
151
-     * @return void
152
-     */
153
-    protected function getPostData(&$route, $reflectionMethod, $validationRules)
154
-    {
155
-        if ($route['method'] == 'POST') 
156
-        {
157
-            $body = $this->getMethodBody($reflectionMethod);
145
+	/**
146
+	 * Generate post body for the given route.
147
+	 * 
148
+	 * @param  array  &$route
149
+	 * @param  object $reflectionMethod
150
+	 * @param  array  $validationRules
151
+	 * @return void
152
+	 */
153
+	protected function getPostData(&$route, $reflectionMethod, $validationRules)
154
+	{
155
+		if ($route['method'] == 'POST') 
156
+		{
157
+			$body = $this->getMethodBody($reflectionMethod);
158 158
 
159
-            preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
160
-            if (count($match)) 
161
-            {
162
-                if ($match[1] == '$this->validationRules')
163
-                {
164
-                    $route['body'] = $validationRules;
165
-                }
166
-                else
167
-                {
168
-                    $route['body'] = eval('return ' . $match[1] . ';');
169
-                }
159
+			preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
160
+			if (count($match)) 
161
+			{
162
+				if ($match[1] == '$this->validationRules')
163
+				{
164
+					$route['body'] = $validationRules;
165
+				}
166
+				else
167
+				{
168
+					$route['body'] = eval('return ' . $match[1] . ';');
169
+				}
170 170
 
171
-                foreach ($route['body'] as &$rule) 
172
-                {
173
-                    if(strpos($rule, 'unique'))
174
-                    {
175
-                        $rule = substr($rule, 0, strpos($rule, 'unique') + 6);
176
-                    }
177
-                    elseif(strpos($rule, 'exists'))
178
-                    {
179
-                        $rule = substr($rule, 0, strpos($rule, 'exists') - 1);
180
-                    }
181
-                }
182
-            }
183
-            else
184
-            {
185
-                $route['body'] = 'conditions';
186
-            }
187
-        }
188
-    }
171
+				foreach ($route['body'] as &$rule) 
172
+				{
173
+					if(strpos($rule, 'unique'))
174
+					{
175
+						$rule = substr($rule, 0, strpos($rule, 'unique') + 6);
176
+					}
177
+					elseif(strpos($rule, 'exists'))
178
+					{
179
+						$rule = substr($rule, 0, strpos($rule, 'exists') - 1);
180
+					}
181
+				}
182
+			}
183
+			else
184
+			{
185
+				$route['body'] = 'conditions';
186
+			}
187
+		}
188
+	}
189 189
 
190
-    /**
191
-     * Generate application errors.
192
-     * 
193
-     * @return array
194
-     */
195
-    protected function getErrors()
196
-    {
197
-        $errors          = [];
198
-        $reflectionClass = new \ReflectionClass('App\Modules\V1\Core\Utl\ErrorHandler');
199
-        foreach ($reflectionClass->getMethods() as $method) 
200
-        {
201
-            $methodName       = $method->getName();
202
-            $reflectionMethod = $reflectionClass->getMethod($methodName);
203
-            $body             = $this->getMethodBody($reflectionMethod);
190
+	/**
191
+	 * Generate application errors.
192
+	 * 
193
+	 * @return array
194
+	 */
195
+	protected function getErrors()
196
+	{
197
+		$errors          = [];
198
+		$reflectionClass = new \ReflectionClass('App\Modules\V1\Core\Utl\ErrorHandler');
199
+		foreach ($reflectionClass->getMethods() as $method) 
200
+		{
201
+			$methodName       = $method->getName();
202
+			$reflectionMethod = $reflectionClass->getMethod($methodName);
203
+			$body             = $this->getMethodBody($reflectionMethod);
204 204
 
205
-            preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
205
+			preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
206 206
 
207
-            if (count($match)) 
208
-            {
209
-                $errors[$match[1]][] = $methodName;
210
-            }
211
-        }
207
+			if (count($match)) 
208
+			{
209
+				$errors[$match[1]][] = $methodName;
210
+			}
211
+		}
212 212
 
213
-        return $errors;
214
-    }
213
+		return $errors;
214
+	}
215 215
 
216
-    /**
217
-     * Get the given method body code.
218
-     * 
219
-     * @param  object $reflectionMethod
220
-     * @return string
221
-     */
222
-    protected function getMethodBody($reflectionMethod)
223
-    {
224
-        $filename   = $reflectionMethod->getFileName();
225
-        $start_line = $reflectionMethod->getStartLine() - 1;
226
-        $end_line   = $reflectionMethod->getEndLine();
227
-        $length     = $end_line - $start_line;         
228
-        $source     = file($filename);
229
-        $body       = implode("", array_slice($source, $start_line, $length));
230
-        $body       = trim(preg_replace('/\s+/', '', $body));
216
+	/**
217
+	 * Get the given method body code.
218
+	 * 
219
+	 * @param  object $reflectionMethod
220
+	 * @return string
221
+	 */
222
+	protected function getMethodBody($reflectionMethod)
223
+	{
224
+		$filename   = $reflectionMethod->getFileName();
225
+		$start_line = $reflectionMethod->getStartLine() - 1;
226
+		$end_line   = $reflectionMethod->getEndLine();
227
+		$length     = $end_line - $start_line;         
228
+		$source     = file($filename);
229
+		$body       = implode("", array_slice($source, $start_line, $length));
230
+		$body       = trim(preg_replace('/\s+/', '', $body));
231 231
 
232
-        return $body;
233
-    }
232
+		return $body;
233
+	}
234 234
 
235
-    /**
236
-     * Get example object of all availble models.
237
-     * 
238
-     * @param  string $modelName
239
-     * @param  object $docData
240
-     * @return string
241
-     */
242
-    protected function getModels($modelName, &$docData)
243
-    {
244
-        if ($modelName && ! array_key_exists($modelName, $docData['models'])) 
245
-        {
246
-            $modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass;
247
-            $model      = factory($modelClass)->make();
248
-            $modelArr   = $model->toArray();
235
+	/**
236
+	 * Get example object of all availble models.
237
+	 * 
238
+	 * @param  string $modelName
239
+	 * @param  object $docData
240
+	 * @return string
241
+	 */
242
+	protected function getModels($modelName, &$docData)
243
+	{
244
+		if ($modelName && ! array_key_exists($modelName, $docData['models'])) 
245
+		{
246
+			$modelClass = call_user_func_array("\Core::{$modelName}", [])->modelClass;
247
+			$model      = factory($modelClass)->make();
248
+			$modelArr   = $model->toArray();
249 249
 
250
-            if ( $model->trans && ! $model->trans->count()) 
251
-            {
252
-                $modelArr['trans'] = [
253
-                    'en' => factory($modelClass . 'Translation')->make()->toArray()
254
-                ];
255
-            }
250
+			if ( $model->trans && ! $model->trans->count()) 
251
+			{
252
+				$modelArr['trans'] = [
253
+					'en' => factory($modelClass . 'Translation')->make()->toArray()
254
+				];
255
+			}
256 256
 
257
-            $docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT);
258
-        }
259
-    }
257
+			$docData['models'][$modelName] = json_encode($modelArr, JSON_PRETTY_PRINT);
258
+		}
259
+	}
260 260
 
261
-    /**
262
-     * Get the route response object type.
263
-     * 
264
-     * @param  string $modelName
265
-     * @param  string $method
266
-     * @return array
267
-     */
268
-    protected function getResponseObject($modelName, $method)
269
-    {
270
-        $config    = \CoreConfig::getConfig();
271
-        $relations = array_key_exists($modelName, $config['relations']) ? array_key_exists($method, $config['relations'][$modelName]) ? $config['relations'][$modelName] : false : false;
261
+	/**
262
+	 * Get the route response object type.
263
+	 * 
264
+	 * @param  string $modelName
265
+	 * @param  string $method
266
+	 * @return array
267
+	 */
268
+	protected function getResponseObject($modelName, $method)
269
+	{
270
+		$config    = \CoreConfig::getConfig();
271
+		$relations = array_key_exists($modelName, $config['relations']) ? array_key_exists($method, $config['relations'][$modelName]) ? $config['relations'][$modelName] : false : false;
272 272
 
273
-        return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false;
274
-    }
273
+		return $relations ? [$modelName => $relations && $relations[$method] ? $relations[$method] : []] : false;
274
+	}
275 275
 }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Repositories/UserRepository.php 1 patch
Indentation   +353 added lines, -353 removed lines patch added patch discarded remove patch
@@ -4,364 +4,364 @@
 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
-     * Return the logged in user account.
19
-     *
20
-     * @param  array   $relations
21
-     * @return boolean
22
-     */
23
-    public function account($relations = [])
24
-    {
25
-        $permissions = [];
26
-        $user        = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations);
27
-        foreach ($user->groups()->get() as $group)
28
-        {
29
-            $group->permissions->each(function ($permission) use (&$permissions){
30
-                $permissions[$permission->model][$permission->id] = $permission->name;
31
-            });
32
-        }
33
-        $user->permissions = $permissions;
34
-
35
-       return $user;
36
-    }
37
-
38
-    /**
39
-     * Check if the logged in user or the given user 
40
-     * has the given permissions on the given model.
41
-     * 
42
-     * @param  string  $nameOfPermission
43
-     * @param  string  $model            
44
-     * @param  boolean $user
45
-     * @return boolean
46
-     */
47
-    public function can($nameOfPermission, $model, $user = false )
48
-    {      
49
-        $user        = $user ?: \JWTAuth::parseToken()->authenticate();
50
-        $permissions = [];
51
-
52
-        if ( ! $user = $this->find($user->id, ['groups.permissions'])) 
53
-        {
54
-            \ErrorHandler::tokenExpired();
55
-        }
56
-
57
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
58
-            $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
59
-        });
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
+	 * Return the logged in user account.
19
+	 *
20
+	 * @param  array   $relations
21
+	 * @return boolean
22
+	 */
23
+	public function account($relations = [])
24
+	{
25
+		$permissions = [];
26
+		$user        = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations);
27
+		foreach ($user->groups()->get() as $group)
28
+		{
29
+			$group->permissions->each(function ($permission) use (&$permissions){
30
+				$permissions[$permission->model][$permission->id] = $permission->name;
31
+			});
32
+		}
33
+		$user->permissions = $permissions;
34
+
35
+	   return $user;
36
+	}
37
+
38
+	/**
39
+	 * Check if the logged in user or the given user 
40
+	 * has the given permissions on the given model.
41
+	 * 
42
+	 * @param  string  $nameOfPermission
43
+	 * @param  string  $model            
44
+	 * @param  boolean $user
45
+	 * @return boolean
46
+	 */
47
+	public function can($nameOfPermission, $model, $user = false )
48
+	{      
49
+		$user        = $user ?: \JWTAuth::parseToken()->authenticate();
50
+		$permissions = [];
51
+
52
+		if ( ! $user = $this->find($user->id, ['groups.permissions'])) 
53
+		{
54
+			\ErrorHandler::tokenExpired();
55
+		}
56
+
57
+		$user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
58
+			$permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
59
+		});
60 60
         
61
-        return in_array($nameOfPermission, $permissions);
62
-    }
63
-
64
-    /**
65
-     * Check if the logged in user has the given group.
66
-     * 
67
-     * @param  string  $groupName
68
-     * @param  integer $userId
69
-     * @return boolean
70
-     */
71
-    public function hasGroup($groupName, $userId = fa;se)
72
-    {
73
-        $userId = $userId ?: \JWTAuth::parseToken()->authenticate()->id;
74
-        $groups = $this->find($userId)->groups;
75
-        return $groups->pluck('name')->search($groupName, true) === false ? false : true;
76
-    }
77
-
78
-    /**
79
-     * Assign the given group ids to the given user.
80
-     * 
81
-     * @param  integer $user_id    
82
-     * @param  array   $group_ids
83
-     * @return object
84
-     */
85
-    public function assignGroups($user_id, $group_ids)
86
-    {
87
-        \DB::transaction(function () use ($user_id, $group_ids) {
88
-            $user = $this->find($user_id);
89
-            $user->groups()->detach();
90
-            $user->groups()->attach($group_ids);
91
-        });
92
-
93
-        return $this->find($user_id);
94
-    }
95
-
96
-    /**
97
-     * Handle a login request to the application.
98
-     * 
99
-     * @param  array   $credentials    
100
-     * @param  boolean $adminLogin
101
-     * @return array
102
-     */
103
-    public function login($credentials, $adminLogin = false)
104
-    {
105
-        if ( ! $user = $this->first(['email' => $credentials['email']])) 
106
-        {
107
-            \ErrorHandler::loginFailed();
108
-        }
109
-        else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
110
-        {
111
-            \ErrorHandler::loginFailed();
112
-        }
113
-        else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
114
-        {
115
-            \ErrorHandler::loginFailed();
116
-        }
117
-        else if ($user->blocked)
118
-        {
119
-            \ErrorHandler::userIsBlocked();
120
-        }
121
-        else if ($token = \JWTAuth::attempt($credentials))
122
-        {
123
-            return ['token' => $token];
124
-        }
125
-        else
126
-        {
127
-            \ErrorHandler::loginFailed();
128
-        }
129
-    }
130
-
131
-    /**
132
-     * Handle a social login request of the none admin to the application.
133
-     * 
134
-     * @param  array   $credentials
135
-     * @return array
136
-     */
137
-    public function loginSocial($credentials)
138
-    {
139
-        $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
140
-        $user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
141
-
142
-        if ( ! $user->email)
143
-        {
144
-            \ErrorHandler::noSocialEmail();
145
-        }
146
-
147
-        if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
148
-        {
149
-            $data = ['email' => $user->email, 'password' => ''];
150
-            return $this->register($data);
151
-        }
152
-        else
153
-        {
154
-            if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
155
-            {
156
-                \ErrorHandler::userAlreadyRegistered();
157
-            }
158
-            return $this->login(['email' => $registeredUser->email, 'password' => ''], false);
159
-        }
160
-    }
61
+		return in_array($nameOfPermission, $permissions);
62
+	}
63
+
64
+	/**
65
+	 * Check if the logged in user has the given group.
66
+	 * 
67
+	 * @param  string  $groupName
68
+	 * @param  integer $userId
69
+	 * @return boolean
70
+	 */
71
+	public function hasGroup($groupName, $userId = fa;se)
72
+	{
73
+		$userId = $userId ?: \JWTAuth::parseToken()->authenticate()->id;
74
+		$groups = $this->find($userId)->groups;
75
+		return $groups->pluck('name')->search($groupName, true) === false ? false : true;
76
+	}
77
+
78
+	/**
79
+	 * Assign the given group ids to the given user.
80
+	 * 
81
+	 * @param  integer $user_id    
82
+	 * @param  array   $group_ids
83
+	 * @return object
84
+	 */
85
+	public function assignGroups($user_id, $group_ids)
86
+	{
87
+		\DB::transaction(function () use ($user_id, $group_ids) {
88
+			$user = $this->find($user_id);
89
+			$user->groups()->detach();
90
+			$user->groups()->attach($group_ids);
91
+		});
92
+
93
+		return $this->find($user_id);
94
+	}
95
+
96
+	/**
97
+	 * Handle a login request to the application.
98
+	 * 
99
+	 * @param  array   $credentials    
100
+	 * @param  boolean $adminLogin
101
+	 * @return array
102
+	 */
103
+	public function login($credentials, $adminLogin = false)
104
+	{
105
+		if ( ! $user = $this->first(['email' => $credentials['email']])) 
106
+		{
107
+			\ErrorHandler::loginFailed();
108
+		}
109
+		else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
110
+		{
111
+			\ErrorHandler::loginFailed();
112
+		}
113
+		else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
114
+		{
115
+			\ErrorHandler::loginFailed();
116
+		}
117
+		else if ($user->blocked)
118
+		{
119
+			\ErrorHandler::userIsBlocked();
120
+		}
121
+		else if ($token = \JWTAuth::attempt($credentials))
122
+		{
123
+			return ['token' => $token];
124
+		}
125
+		else
126
+		{
127
+			\ErrorHandler::loginFailed();
128
+		}
129
+	}
130
+
131
+	/**
132
+	 * Handle a social login request of the none admin to the application.
133
+	 * 
134
+	 * @param  array   $credentials
135
+	 * @return array
136
+	 */
137
+	public function loginSocial($credentials)
138
+	{
139
+		$access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
140
+		$user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
141
+
142
+		if ( ! $user->email)
143
+		{
144
+			\ErrorHandler::noSocialEmail();
145
+		}
146
+
147
+		if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
148
+		{
149
+			$data = ['email' => $user->email, 'password' => ''];
150
+			return $this->register($data);
151
+		}
152
+		else
153
+		{
154
+			if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
155
+			{
156
+				\ErrorHandler::userAlreadyRegistered();
157
+			}
158
+			return $this->login(['email' => $registeredUser->email, 'password' => ''], false);
159
+		}
160
+	}
161 161
     
162
-    /**
163
-     * Handle a registration request.
164
-     * 
165
-     * @param  array $credentials
166
-     * @return array
167
-     */
168
-    public function register($credentials)
169
-    {
170
-        return ['token' => \JWTAuth::fromUser($this->model->create($credentials))];
171
-    }
172
-
173
-    /**
174
-     * Logout the user.
175
-     * 
176
-     * @return boolean
177
-     */
178
-    public function logout()
179
-    {
180
-        return \JWTAuth::invalidate(\JWTAuth::getToken());
181
-    }
182
-
183
-    /**
184
-     * Block the user.
185
-     *
186
-     * @param  integer $user_id
187
-     * @return object
188
-     */
189
-    public function block($user_id)
190
-    {
191
-        if ( ! $user = $this->find($user_id)) 
192
-        {
193
-            \ErrorHandler::notFound('user');
194
-        }
195
-        if ( ! $this->hasGroup('Admin'))
196
-        {
197
-            \ErrorHandler::noPermissions();
198
-        }
199
-        else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
200
-        {
201
-            \ErrorHandler::noPermissions();
202
-        }
203
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
204
-        {
205
-            \ErrorHandler::noPermissions();
206
-        }
207
-
208
-        $user->blocked = 1;
209
-        $user->save();
162
+	/**
163
+	 * Handle a registration request.
164
+	 * 
165
+	 * @param  array $credentials
166
+	 * @return array
167
+	 */
168
+	public function register($credentials)
169
+	{
170
+		return ['token' => \JWTAuth::fromUser($this->model->create($credentials))];
171
+	}
172
+
173
+	/**
174
+	 * Logout the user.
175
+	 * 
176
+	 * @return boolean
177
+	 */
178
+	public function logout()
179
+	{
180
+		return \JWTAuth::invalidate(\JWTAuth::getToken());
181
+	}
182
+
183
+	/**
184
+	 * Block the user.
185
+	 *
186
+	 * @param  integer $user_id
187
+	 * @return object
188
+	 */
189
+	public function block($user_id)
190
+	{
191
+		if ( ! $user = $this->find($user_id)) 
192
+		{
193
+			\ErrorHandler::notFound('user');
194
+		}
195
+		if ( ! $this->hasGroup('Admin'))
196
+		{
197
+			\ErrorHandler::noPermissions();
198
+		}
199
+		else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
200
+		{
201
+			\ErrorHandler::noPermissions();
202
+		}
203
+		else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
204
+		{
205
+			\ErrorHandler::noPermissions();
206
+		}
207
+
208
+		$user->blocked = 1;
209
+		$user->save();
210 210
         
211
-        return $user;
212
-    }
213
-
214
-    /**
215
-     * Unblock the user.
216
-     *
217
-     * @param  integer $user_id
218
-     * @return object
219
-     */
220
-    public function unblock($user_id)
221
-    {
222
-        if ( ! $this->hasGroup('Admin'))
223
-        {
224
-            \ErrorHandler::noPermissions();
225
-        }
226
-
227
-        $user          = $this->find($user_id);
228
-        $user->blocked = 0;
229
-        $user->save();
230
-
231
-        return $user;
232
-    }
233
-
234
-    /**
235
-     * Send a reset link to the given user.
236
-     *
237
-     * @param  string  $email
238
-     * @return void
239
-     */
240
-    public function sendReset($email)
241
-    {
242
-        if ( ! $user = $this->model->where('email', $email)->first())
243
-        {
244
-            \ErrorHandler::notFound('email');
245
-        }
246
-
247
-        $url   = $this->config['resetLink'];
248
-        $token = \Password::getRepository()->create($user);
211
+		return $user;
212
+	}
213
+
214
+	/**
215
+	 * Unblock the user.
216
+	 *
217
+	 * @param  integer $user_id
218
+	 * @return object
219
+	 */
220
+	public function unblock($user_id)
221
+	{
222
+		if ( ! $this->hasGroup('Admin'))
223
+		{
224
+			\ErrorHandler::noPermissions();
225
+		}
226
+
227
+		$user          = $this->find($user_id);
228
+		$user->blocked = 0;
229
+		$user->save();
230
+
231
+		return $user;
232
+	}
233
+
234
+	/**
235
+	 * Send a reset link to the given user.
236
+	 *
237
+	 * @param  string  $email
238
+	 * @return void
239
+	 */
240
+	public function sendReset($email)
241
+	{
242
+		if ( ! $user = $this->model->where('email', $email)->first())
243
+		{
244
+			\ErrorHandler::notFound('email');
245
+		}
246
+
247
+		$url   = $this->config['resetLink'];
248
+		$token = \Password::getRepository()->create($user);
249 249
         
250
-        \Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) {
251
-            $m->to($user->email, $user->name)->subject('Your Password Reset Link');
252
-        });
253
-    }
254
-
255
-    /**
256
-     * Reset the given user's password.
257
-     *
258
-     * @param  array  $credentials
259
-     * @return array
260
-     */
261
-    public function resetPassword($credentials)
262
-    {
263
-        $token    = false;
264
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
265
-            $user->password = $password;
266
-            $user->save();
267
-
268
-            $token = \JWTAuth::fromUser($user);
269
-        });
270
-
271
-        switch ($response) {
272
-            case \Password::PASSWORD_RESET:
273
-                return ['token' => $token];
250
+		\Mail::send('acl::resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) {
251
+			$m->to($user->email, $user->name)->subject('Your Password Reset Link');
252
+		});
253
+	}
254
+
255
+	/**
256
+	 * Reset the given user's password.
257
+	 *
258
+	 * @param  array  $credentials
259
+	 * @return array
260
+	 */
261
+	public function resetPassword($credentials)
262
+	{
263
+		$token    = false;
264
+		$response = \Password::reset($credentials, function ($user, $password) use (&$token) {
265
+			$user->password = $password;
266
+			$user->save();
267
+
268
+			$token = \JWTAuth::fromUser($user);
269
+		});
270
+
271
+		switch ($response) {
272
+			case \Password::PASSWORD_RESET:
273
+				return ['token' => $token];
274 274
                 
275
-            case \Password::INVALID_TOKEN:
276
-                \ErrorHandler::invalidResetToken('token');
277
-
278
-            case \Password::INVALID_PASSWORD:
279
-                \ErrorHandler::invalidResetPassword('email');
280
-
281
-            case \Password::INVALID_USER:
282
-                \ErrorHandler::notFound('user');
283
-
284
-            default:
285
-                \ErrorHandler::generalError();
286
-        }
287
-    }
288
-
289
-    /**
290
-     * Change the logged in user password.
291
-     *
292
-     * @param  array  $credentials
293
-     * @return void
294
-     */
295
-    public function changePassword($credentials)
296
-    {
297
-        $user = \JWTAuth::parseToken()->authenticate();
298
-        if ( ! \Hash::check($credentials['old_password'], $user->password)) 
299
-        {
300
-            \ErrorHandler::invalidOldPassword();
301
-        }
302
-
303
-        $user->password = $credentials['password'];
304
-        $user->save();
305
-    }
306
-
307
-    /**
308
-     * Refresh the expired login token.
309
-     *
310
-     * @return array
311
-     */
312
-    public function refreshtoken()
313
-    {
314
-        $token = \JWTAuth::parseToken()->refresh();
315
-
316
-        return ['token' => $token];
317
-    }
318
-
319
-    /**
320
-     * Paginate all users in the given group based on the given conditions.
321
-     * 
322
-     * @param  string  $groupName
323
-     * @param  array   $relations
324
-     * @param  integer $perPage
325
-     * @param  string  $sortBy
326
-     * @param  boolean $desc
327
-     * @return \Illuminate\Http\Response
328
-     */
329
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
330
-    {   
331
-        unset($conditions['page']);
332
-        $conditions = $this->constructConditions($conditions, $this->model);
333
-        $sort       = $desc ? 'desc' : 'asc';
334
-        $model      = call_user_func_array("{$this->getModel()}::with", array($relations));
335
-
336
-        $model->whereHas('groups', function($q) use ($groupName){
337
-            $q->where('name', $groupName);
338
-        });
275
+			case \Password::INVALID_TOKEN:
276
+				\ErrorHandler::invalidResetToken('token');
277
+
278
+			case \Password::INVALID_PASSWORD:
279
+				\ErrorHandler::invalidResetPassword('email');
280
+
281
+			case \Password::INVALID_USER:
282
+				\ErrorHandler::notFound('user');
283
+
284
+			default:
285
+				\ErrorHandler::generalError();
286
+		}
287
+	}
288
+
289
+	/**
290
+	 * Change the logged in user password.
291
+	 *
292
+	 * @param  array  $credentials
293
+	 * @return void
294
+	 */
295
+	public function changePassword($credentials)
296
+	{
297
+		$user = \JWTAuth::parseToken()->authenticate();
298
+		if ( ! \Hash::check($credentials['old_password'], $user->password)) 
299
+		{
300
+			\ErrorHandler::invalidOldPassword();
301
+		}
302
+
303
+		$user->password = $credentials['password'];
304
+		$user->save();
305
+	}
306
+
307
+	/**
308
+	 * Refresh the expired login token.
309
+	 *
310
+	 * @return array
311
+	 */
312
+	public function refreshtoken()
313
+	{
314
+		$token = \JWTAuth::parseToken()->refresh();
315
+
316
+		return ['token' => $token];
317
+	}
318
+
319
+	/**
320
+	 * Paginate all users in the given group based on the given conditions.
321
+	 * 
322
+	 * @param  string  $groupName
323
+	 * @param  array   $relations
324
+	 * @param  integer $perPage
325
+	 * @param  string  $sortBy
326
+	 * @param  boolean $desc
327
+	 * @return \Illuminate\Http\Response
328
+	 */
329
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
330
+	{   
331
+		unset($conditions['page']);
332
+		$conditions = $this->constructConditions($conditions, $this->model);
333
+		$sort       = $desc ? 'desc' : 'asc';
334
+		$model      = call_user_func_array("{$this->getModel()}::with", array($relations));
335
+
336
+		$model->whereHas('groups', function($q) use ($groupName){
337
+			$q->where('name', $groupName);
338
+		});
339 339
 
340 340
         
341
-        if (count($conditions['conditionValues']))
342
-        {
343
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
344
-        }
345
-
346
-        if ($perPage) 
347
-        {
348
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
349
-        }
350
-
351
-        return $model->orderBy($sortBy, $sort)->get();
352
-    }
353
-
354
-    /**
355
-     * Save the given data to the logged in user.
356
-     *
357
-     * @param  array $credentials
358
-     * @return object
359
-     */
360
-    public function saveProfile($credentials) 
361
-    {
362
-        $user = \JWTAuth::parseToken()->authenticate();
363
-        $user->save($credentials);
364
-
365
-        return $user;
366
-    }
341
+		if (count($conditions['conditionValues']))
342
+		{
343
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
344
+		}
345
+
346
+		if ($perPage) 
347
+		{
348
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
349
+		}
350
+
351
+		return $model->orderBy($sortBy, $sort)->get();
352
+	}
353
+
354
+	/**
355
+	 * Save the given data to the logged in user.
356
+	 *
357
+	 * @param  array $credentials
358
+	 * @return object
359
+	 */
360
+	public function saveProfile($credentials) 
361
+	{
362
+		$user = \JWTAuth::parseToken()->authenticate();
363
+		$user->save($credentials);
364
+
365
+		return $user;
366
+	}
367 367
 }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Http/Controllers/UsersController.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -7,250 +7,250 @@
 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';
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 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', 'changePassword'];
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', 'changePassword'];
23 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'];
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 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
-        'name'     => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', 
38
-        'email'    => 'required|email|unique:users,email,{id},id,email,NOT_NULL', 
39
-        'password' => 'nullable|min:6'
40
-    ];
31
+	/**
32
+	 * The validations rules used by the base api controller
33
+	 * to check before add.
34
+	 * @var array
35
+	 */
36
+	protected $validationRules     = [
37
+		'name'     => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', 
38
+		'email'    => 'required|email|unique:users,email,{id},id,email,NOT_NULL', 
39
+		'password' => 'nullable|min:6'
40
+	];
41 41
 
42
-    /**
43
-     * Return the logged in user account.
44
-     * 
45
-     * @return \Illuminate\Http\Response
46
-     */
47
-    public function account()
48
-    {
49
-        return \Response::json(\Core::users()->account($this->relations), 200);
50
-    }
42
+	/**
43
+	 * Return the logged in user account.
44
+	 * 
45
+	 * @return \Illuminate\Http\Response
46
+	 */
47
+	public function account()
48
+	{
49
+		return \Response::json(\Core::users()->account($this->relations), 200);
50
+	}
51 51
 
52
-    /**
53
-     * Block the user.
54
-     *
55
-     * @param  integer  $id Id of the user.
56
-     * @return \Illuminate\Http\Response
57
-     */
58
-    public function block($id)
59
-    {
60
-        return \Response::json(\Core::users()->block($id), 200);
61
-    }
52
+	/**
53
+	 * Block the user.
54
+	 *
55
+	 * @param  integer  $id Id of the user.
56
+	 * @return \Illuminate\Http\Response
57
+	 */
58
+	public function block($id)
59
+	{
60
+		return \Response::json(\Core::users()->block($id), 200);
61
+	}
62 62
 
63
-    /**
64
-     * Unblock the user.
65
-     *
66
-     * @param  integer  $id Id of the user.
67
-     * @return \Illuminate\Http\Response
68
-     */
69
-    public function unblock($id)
70
-    {
71
-        return \Response::json(\Core::users()->unblock($id), 200);
72
-    }
63
+	/**
64
+	 * Unblock the user.
65
+	 *
66
+	 * @param  integer  $id Id of the user.
67
+	 * @return \Illuminate\Http\Response
68
+	 */
69
+	public function unblock($id)
70
+	{
71
+		return \Response::json(\Core::users()->unblock($id), 200);
72
+	}
73 73
 
74
-    /**
75
-     * Logout the user.
76
-     * 
77
-     * @return \Illuminate\Http\Response
78
-     */
79
-    public function logout()
80
-    {
81
-        return \Response::json(\Core::users()->logout(), 200);
82
-    }
74
+	/**
75
+	 * Logout the user.
76
+	 * 
77
+	 * @return \Illuminate\Http\Response
78
+	 */
79
+	public function logout()
80
+	{
81
+		return \Response::json(\Core::users()->logout(), 200);
82
+	}
83 83
 
84
-    /**
85
-     * Handle a registration request.
86
-     *
87
-     * @param  \Illuminate\Http\Request  $request
88
-     * @return \Illuminate\Http\Response
89
-     */
90
-    public function register(Request $request)
91
-    {
92
-        $this->validate($request, [
93
-            'name'     => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', 
94
-            'email'    => 'required|email|unique:users,email,{id},id,email,NOT_NULL', 
95
-            'password' => 'required|min:6'
96
-            ]);
84
+	/**
85
+	 * Handle a registration request.
86
+	 *
87
+	 * @param  \Illuminate\Http\Request  $request
88
+	 * @return \Illuminate\Http\Response
89
+	 */
90
+	public function register(Request $request)
91
+	{
92
+		$this->validate($request, [
93
+			'name'     => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', 
94
+			'email'    => 'required|email|unique:users,email,{id},id,email,NOT_NULL', 
95
+			'password' => 'required|min:6'
96
+			]);
97 97
 
98
-        return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
99
-    }
98
+		return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
99
+	}
100 100
 
101
-    /**
102
-     * Handle a login request of the none admin to the application.
103
-     *
104
-     * @param  \Illuminate\Http\Request  $request
105
-     * @return \Illuminate\Http\Response
106
-     */
107
-    public function login(Request $request)
108
-    {
109
-        $this->validate($request, [
110
-            'email'    => 'required|email', 
111
-            'password' => 'required|min:6',
112
-            'admin'    => 'boolean'
113
-            ]);
101
+	/**
102
+	 * Handle a login request of the none admin to the application.
103
+	 *
104
+	 * @param  \Illuminate\Http\Request  $request
105
+	 * @return \Illuminate\Http\Response
106
+	 */
107
+	public function login(Request $request)
108
+	{
109
+		$this->validate($request, [
110
+			'email'    => 'required|email', 
111
+			'password' => 'required|min:6',
112
+			'admin'    => 'boolean'
113
+			]);
114 114
 
115
-        return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
116
-    }
115
+		return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
116
+	}
117 117
 
118
-    /**
119
-     * Handle a social login request of the none admin to the application.
120
-     *
121
-     * @param  \Illuminate\Http\Request  $request
122
-     * @return \Illuminate\Http\Response
123
-     */
124
-    public function loginSocial(Request $request)
125
-    {
126
-        $this->validate($request, [
127
-            'auth_code'    => 'required_without:access_token',
128
-            'access_token' => 'required_without:auth_code',
129
-            'type'         => 'required|in:facebook,google'
130
-            ]);
118
+	/**
119
+	 * Handle a social login request of the none admin to the application.
120
+	 *
121
+	 * @param  \Illuminate\Http\Request  $request
122
+	 * @return \Illuminate\Http\Response
123
+	 */
124
+	public function loginSocial(Request $request)
125
+	{
126
+		$this->validate($request, [
127
+			'auth_code'    => 'required_without:access_token',
128
+			'access_token' => 'required_without:auth_code',
129
+			'type'         => 'required|in:facebook,google'
130
+			]);
131 131
 
132
-        return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200);
133
-    }
132
+		return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200);
133
+	}
134 134
 
135
-    /**
136
-     * Assign the given groups to the given user.
137
-     *
138
-     * @param  \Illuminate\Http\Request  $request
139
-     * @return \Illuminate\Http\Response
140
-     */
141
-    public function assigngroups(Request $request)
142
-    {
143
-        $this->validate($request, [
144
-            'group_ids' => 'required|exists:groups,id', 
145
-            'user_id'   => 'required|exists:users,id'
146
-            ]);
135
+	/**
136
+	 * Assign the given groups to the given user.
137
+	 *
138
+	 * @param  \Illuminate\Http\Request  $request
139
+	 * @return \Illuminate\Http\Response
140
+	 */
141
+	public function assigngroups(Request $request)
142
+	{
143
+		$this->validate($request, [
144
+			'group_ids' => 'required|exists:groups,id', 
145
+			'user_id'   => 'required|exists:users,id'
146
+			]);
147 147
 
148
-        return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
149
-    }
148
+		return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
149
+	}
150 150
 
151
-    /**
152
-     * Send a reset link to the given user.
153
-     *
154
-     * @param  \Illuminate\Http\Request  $request
155
-     * @return \Illuminate\Http\Response
156
-     */
157
-    public function sendreset(Request $request)
158
-    {
159
-        $this->validate($request, ['email' => 'required|email']);
151
+	/**
152
+	 * Send a reset link to the given user.
153
+	 *
154
+	 * @param  \Illuminate\Http\Request  $request
155
+	 * @return \Illuminate\Http\Response
156
+	 */
157
+	public function sendreset(Request $request)
158
+	{
159
+		$this->validate($request, ['email' => 'required|email']);
160 160
 
161
-        return \Response::json(\Core::users()->sendReset($request->only('email')), 200);
162
-    }
161
+		return \Response::json(\Core::users()->sendReset($request->only('email')), 200);
162
+	}
163 163
 
164
-    /**
165
-     * Reset the given user's password.
166
-     *
167
-     * @param  \Illuminate\Http\Request  $request
168
-     * @return \Illuminate\Http\Response
169
-     */
170
-    public function resetpassword(Request $request)
171
-    {
172
-        $this->validate($request, [
173
-            'token'                 => 'required',
174
-            'email'                 => 'required|email',
175
-            'password'              => 'required|confirmed|min:6',
176
-            'password_confirmation' => 'required',
177
-        ]);
164
+	/**
165
+	 * Reset the given user's password.
166
+	 *
167
+	 * @param  \Illuminate\Http\Request  $request
168
+	 * @return \Illuminate\Http\Response
169
+	 */
170
+	public function resetpassword(Request $request)
171
+	{
172
+		$this->validate($request, [
173
+			'token'                 => 'required',
174
+			'email'                 => 'required|email',
175
+			'password'              => 'required|confirmed|min:6',
176
+			'password_confirmation' => 'required',
177
+		]);
178 178
 
179
-        return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
180
-    }
179
+		return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
180
+	}
181 181
 
182
-    /**
183
-     * Change the logged in user password.
184
-     *
185
-     * @param  \Illuminate\Http\Request  $request
186
-     * @return \Illuminate\Http\Response
187
-     */
188
-    public function changePassword(Request $request)
189
-    {
190
-        $this->validate($request, [
191
-            'old_password'          => 'required',
192
-            'password'              => 'required|confirmed|min:6',
193
-            'password_confirmation' => 'required',
194
-        ]);
182
+	/**
183
+	 * Change the logged in user password.
184
+	 *
185
+	 * @param  \Illuminate\Http\Request  $request
186
+	 * @return \Illuminate\Http\Response
187
+	 */
188
+	public function changePassword(Request $request)
189
+	{
190
+		$this->validate($request, [
191
+			'old_password'          => 'required',
192
+			'password'              => 'required|confirmed|min:6',
193
+			'password_confirmation' => 'required',
194
+		]);
195 195
 
196
-        return \Response::json(\Core::users()->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
197
-    }
196
+		return \Response::json(\Core::users()->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
197
+	}
198 198
 
199
-    /**
200
-     * Refresh the expired login token.
201
-     *
202
-     * @return \Illuminate\Http\Response
203
-     */
204
-    public function refreshtoken()
205
-    {
206
-        return \Response::json(\Core::users()->refreshtoken(), 200);
207
-    }
199
+	/**
200
+	 * Refresh the expired login token.
201
+	 *
202
+	 * @return \Illuminate\Http\Response
203
+	 */
204
+	public function refreshtoken()
205
+	{
206
+		return \Response::json(\Core::users()->refreshtoken(), 200);
207
+	}
208 208
 
209
-    /**
210
-     * Paginate all users with inthe given group.
211
-     * 
212
-     * @param  \Illuminate\Http\Request  $request
213
-     * @param  string $groupName The name of the requested group.
214
-     * @param  integer $perPage  Number of rows per page default 15.
215
-     * @param  string  $sortBy   The name of the column to sort by.
216
-     * @param  boolean $desc     Sort ascending or descinding (1: desc, 0: asc).
217
-     * @return \Illuminate\Http\Response
218
-     */
219
-    public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1)
220
-    {
221
-        return \Response::json(\Core::users()->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200);
222
-    }
209
+	/**
210
+	 * Paginate all users with inthe given group.
211
+	 * 
212
+	 * @param  \Illuminate\Http\Request  $request
213
+	 * @param  string $groupName The name of the requested group.
214
+	 * @param  integer $perPage  Number of rows per page default 15.
215
+	 * @param  string  $sortBy   The name of the column to sort by.
216
+	 * @param  boolean $desc     Sort ascending or descinding (1: desc, 0: asc).
217
+	 * @return \Illuminate\Http\Response
218
+	 */
219
+	public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1)
220
+	{
221
+		return \Response::json(\Core::users()->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200);
222
+	}
223 223
 
224
-    /**
225
-     * Save the given data to the logged in user.
226
-     *
227
-     * @param  \Illuminate\Http\Request  $request
228
-     * @return \Illuminate\Http\Response
229
-     */
230
-    public function saveProfile(Request $request) 
231
-    {
232
-        foreach ($this->validationRules as &$rule) 
233
-        {
234
-            if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
235
-            {
236
-                $rule .= ',deleted_at,NULL';
237
-            }
224
+	/**
225
+	 * Save the given data to the logged in user.
226
+	 *
227
+	 * @param  \Illuminate\Http\Request  $request
228
+	 * @return \Illuminate\Http\Response
229
+	 */
230
+	public function saveProfile(Request $request) 
231
+	{
232
+		foreach ($this->validationRules as &$rule) 
233
+		{
234
+			if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
235
+			{
236
+				$rule .= ',deleted_at,NULL';
237
+			}
238 238
 
239
-            if ($request->has('id')) 
240
-            {
241
-                $rule = str_replace('{id}', $request->get('id'), $rule);
242
-            }
243
-            else
244
-            {
245
-                $rule = str_replace(',{id}', '', $rule);
246
-            }
247
-        }
239
+			if ($request->has('id')) 
240
+			{
241
+				$rule = str_replace('{id}', $request->get('id'), $rule);
242
+			}
243
+			else
244
+			{
245
+				$rule = str_replace(',{id}', '', $rule);
246
+			}
247
+		}
248 248
 
249
-        $this->validate($request, $this->validationRules);
249
+		$this->validate($request, $this->validationRules);
250 250
 
251
-        if ($this->model)
252
-        {
253
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->saveProfile($request->all()), 200);
254
-        }
255
-    }
251
+		if ($this->model)
252
+		{
253
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->saveProfile($request->all()), 200);
254
+		}
255
+	}
256 256
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Decorators/CachingDecorator.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -2,102 +2,102 @@
 block discarded – undo
2 2
 
3 3
 class CachingDecorator
4 4
 {
5
-    /**
6
-     * The repo implementation.
7
-     * 
8
-     * @var string
9
-     */
10
-    public $repo;
5
+	/**
6
+	 * The repo implementation.
7
+	 * 
8
+	 * @var string
9
+	 */
10
+	public $repo;
11 11
 
12
-    /**
13
-     * The cache implementation.
14
-     * 
15
-     * @var object
16
-     */
17
-    protected $cache;
12
+	/**
13
+	 * The cache implementation.
14
+	 * 
15
+	 * @var object
16
+	 */
17
+	protected $cache;
18 18
 
19
-    /**
20
-     * The modelKey implementation.
21
-     * 
22
-     * @var string
23
-     */
24
-    public $modelKey;
19
+	/**
20
+	 * The modelKey implementation.
21
+	 * 
22
+	 * @var string
23
+	 */
24
+	public $modelKey;
25 25
 
26
-    /**
27
-     * The model implementation.
28
-     * 
29
-     * @var string
30
-     */
31
-    public $model;
26
+	/**
27
+	 * The model implementation.
28
+	 * 
29
+	 * @var string
30
+	 */
31
+	public $model;
32 32
 
33
-    /**
34
-     * The cacheConfig implementation.
35
-     * 
36
-     * @var array
37
-     */
38
-    public $cacheConfig;
33
+	/**
34
+	 * The cacheConfig implementation.
35
+	 * 
36
+	 * @var array
37
+	 */
38
+	public $cacheConfig;
39 39
     
40
-    /**
41
-     * Create new CachingDecorator instance.
42
-     */
43
-    public function __construct($repo, $cache)
44
-    {   
45
-        $this->repo     = $repo;
46
-        $this->cache    = $cache;
47
-        $this->model    = $this->repo->model;
48
-        $repoClass      = explode('\\', get_class($this->repo));
49
-        $repoName       = end($repoClass);
50
-        $this->cacheTag = str_plural(lcfirst(substr($repoName, 0, strpos($repoName, 'Repository'))));
51
-    }
40
+	/**
41
+	 * Create new CachingDecorator instance.
42
+	 */
43
+	public function __construct($repo, $cache)
44
+	{   
45
+		$this->repo     = $repo;
46
+		$this->cache    = $cache;
47
+		$this->model    = $this->repo->model;
48
+		$repoClass      = explode('\\', get_class($this->repo));
49
+		$repoName       = end($repoClass);
50
+		$this->cacheTag = str_plural(lcfirst(substr($repoName, 0, strpos($repoName, 'Repository'))));
51
+	}
52 52
 
53
-    /**
54
-     * Handle the cache mechanism for the called method
55
-     * based the configurations.
56
-     * 
57
-     * @param  string $name the called method name
58
-     * @param  array  $arguments the method arguments
59
-     * @return object
60
-     */
61
-    public function __call($name, $arguments)
62
-    {
63
-        $this->setCacheConfig($name);
53
+	/**
54
+	 * Handle the cache mechanism for the called method
55
+	 * based the configurations.
56
+	 * 
57
+	 * @param  string $name the called method name
58
+	 * @param  array  $arguments the method arguments
59
+	 * @return object
60
+	 */
61
+	public function __call($name, $arguments)
62
+	{
63
+		$this->setCacheConfig($name);
64 64
 
65
-        if ($this->cacheConfig && $this->cacheConfig == 'cache') 
66
-        {
67
-            $page     = \Request::get('page') !== null ? \Request::get('page') : '1';
68
-            $cacheKey = $name . $page . \Session::get('locale') . serialize($arguments);
69
-            return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function() use ($arguments, $name) {
70
-                return call_user_func_array([$this->repo, $name], $arguments);
71
-            });
72
-        }
73
-        else if ($this->cacheConfig)
74
-        {
75
-            $this->cache->tags($this->cacheConfig)->flush();
76
-            return call_user_func_array([$this->repo, $name], $arguments);
77
-        }
65
+		if ($this->cacheConfig && $this->cacheConfig == 'cache') 
66
+		{
67
+			$page     = \Request::get('page') !== null ? \Request::get('page') : '1';
68
+			$cacheKey = $name . $page . \Session::get('locale') . serialize($arguments);
69
+			return $this->cache->tags([$this->cacheTag])->rememberForever($cacheKey, function() use ($arguments, $name) {
70
+				return call_user_func_array([$this->repo, $name], $arguments);
71
+			});
72
+		}
73
+		else if ($this->cacheConfig)
74
+		{
75
+			$this->cache->tags($this->cacheConfig)->flush();
76
+			return call_user_func_array([$this->repo, $name], $arguments);
77
+		}
78 78
 
79
-        return call_user_func_array([$this->repo, $name], $arguments);
80
-    }
79
+		return call_user_func_array([$this->repo, $name], $arguments);
80
+	}
81 81
 
82
-    /**
83
-     * Set cache config based on the called method.
84
-     * 
85
-     * @param  string $name
86
-     * @return void
87
-     */
88
-    private function setCacheConfig($name)
89
-    {   
90
-        $config            = \CoreConfig::getConfig();
91
-        $cacheConfig       = array_key_exists($this->cacheTag, $config['cacheConfig']) ? $config['cacheConfig'][$this->cacheTag] : false;
92
-        $this->cacheConfig = false;
82
+	/**
83
+	 * Set cache config based on the called method.
84
+	 * 
85
+	 * @param  string $name
86
+	 * @return void
87
+	 */
88
+	private function setCacheConfig($name)
89
+	{   
90
+		$config            = \CoreConfig::getConfig();
91
+		$cacheConfig       = array_key_exists($this->cacheTag, $config['cacheConfig']) ? $config['cacheConfig'][$this->cacheTag] : false;
92
+		$this->cacheConfig = false;
93 93
 
94
-        if ($cacheConfig && in_array($name, $cacheConfig['cache']))
95
-        {
96
-            $this->cacheConfig = 'cache';
97
-        }
98
-        else if ($cacheConfig && isset($cacheConfig['clear'][$name]))
99
-        {
100
-            $this->cacheConfig = $cacheConfig['clear'][$name];
101
-        }
102
-    }
94
+		if ($cacheConfig && in_array($name, $cacheConfig['cache']))
95
+		{
96
+			$this->cacheConfig = 'cache';
97
+		}
98
+		else if ($cacheConfig && isset($cacheConfig['clear'][$name]))
99
+		{
100
+			$this->cacheConfig = $cacheConfig['clear'][$name];
101
+		}
102
+	}
103 103
 }
104 104
\ No newline at end of file
Please login to merge, or discard this patch.