Completed
Push — master ( f8ccd7...a2ea8b )
by Sherif
13:39
created
src/Modules/V1/Core/Interfaces/RepositoryInterface.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -2,118 +2,118 @@
 block discarded – undo
2 2
 
3 3
 interface RepositoryInterface
4 4
 {
5
-    /**
6
-     * Fetch all records with relations from the storage.
7
-     * 
8
-     * @param  array  $relations
9
-     * @param  array  $sortBy
10
-     * @param  array  $desc
11
-     * @param  array  $columns
12
-     * @return collection
13
-     */
14
-    public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
5
+	/**
6
+	 * Fetch all records with relations from the storage.
7
+	 * 
8
+	 * @param  array  $relations
9
+	 * @param  array  $sortBy
10
+	 * @param  array  $desc
11
+	 * @param  array  $columns
12
+	 * @return collection
13
+	 */
14
+	public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
15 15
     
16
-    /**
17
-     * Fetch all records with relations from storage in pages 
18
-     * that matche the given query.
19
-     * 
20
-     * @param  string  $query
21
-     * @param  integer $perPage
22
-     * @param  array   $relations
23
-     * @param  array   $sortBy
24
-     * @param  array   $desc
25
-     * @param  array   $columns
26
-     * @return collection
27
-     */
28
-    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
16
+	/**
17
+	 * Fetch all records with relations from storage in pages 
18
+	 * that matche the given query.
19
+	 * 
20
+	 * @param  string  $query
21
+	 * @param  integer $perPage
22
+	 * @param  array   $relations
23
+	 * @param  array   $sortBy
24
+	 * @param  array   $desc
25
+	 * @param  array   $columns
26
+	 * @return collection
27
+	 */
28
+	public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
29 29
 
30
-    /**
31
-     * Fetch all records with relations from storage in pages.
32
-     * 
33
-     * @param  integer $perPage
34
-     * @param  array   $relations
35
-     * @param  array   $sortBy
36
-     * @param  array   $desc
37
-     * @param  array   $columns
38
-     * @return collection
39
-     */
40
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
30
+	/**
31
+	 * Fetch all records with relations from storage in pages.
32
+	 * 
33
+	 * @param  integer $perPage
34
+	 * @param  array   $relations
35
+	 * @param  array   $sortBy
36
+	 * @param  array   $desc
37
+	 * @param  array   $columns
38
+	 * @return collection
39
+	 */
40
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
41 41
     
42
-    /**
43
-     * Fetch all records with relations based on
44
-     * the given condition from storage in pages.
45
-     * 
46
-     * @param  array   $conditions array of conditions
47
-     * @param  integer $perPage
48
-     * @param  array   $relations
49
-     * @param  array   $sortBy
50
-     * @param  array   $desc
51
-     * @param  array   $columns
52
-     * @return collection
53
-     */
54
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
42
+	/**
43
+	 * Fetch all records with relations based on
44
+	 * the given condition from storage in pages.
45
+	 * 
46
+	 * @param  array   $conditions array of conditions
47
+	 * @param  integer $perPage
48
+	 * @param  array   $relations
49
+	 * @param  array   $sortBy
50
+	 * @param  array   $desc
51
+	 * @param  array   $columns
52
+	 * @return collection
53
+	 */
54
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
55 55
 
56
-     /**
57
-     * Save the given model/models to the storage.
58
-     * 
59
-     * @param  array   $data
60
-     * @return object
61
-     */
62
-    public function save(array $data);
56
+	 /**
57
+	  * Save the given model/models to the storage.
58
+	  * 
59
+	  * @param  array   $data
60
+	  * @return object
61
+	  */
62
+	public function save(array $data);
63 63
 
64
-    /**
65
-     * Update record in the storage based on the given
66
-     * condition.
67
-     * 
68
-     * @param  var     $value condition value
69
-     * @param  array   $data
70
-     * @param  string  $attribute condition column name
71
-     * @return integer affected rows
72
-     */
73
-    public function update($value, array $data, $attribute = 'id');
64
+	/**
65
+	 * Update record in the storage based on the given
66
+	 * condition.
67
+	 * 
68
+	 * @param  var     $value condition value
69
+	 * @param  array   $data
70
+	 * @param  string  $attribute condition column name
71
+	 * @return integer affected rows
72
+	 */
73
+	public function update($value, array $data, $attribute = 'id');
74 74
 
75
-    /**
76
-     * Delete record from the storage based on the given
77
-     * condition.
78
-     * 
79
-     * @param  var     $value condition value
80
-     * @param  string  $attribute condition column name
81
-     * @return integer affected rows
82
-     */
83
-    public function delete($value, $attribute = 'id');
75
+	/**
76
+	 * Delete record from the storage based on the given
77
+	 * condition.
78
+	 * 
79
+	 * @param  var     $value condition value
80
+	 * @param  string  $attribute condition column name
81
+	 * @return integer affected rows
82
+	 */
83
+	public function delete($value, $attribute = 'id');
84 84
     
85
-    /**
86
-     * Fetch records from the storage based on the given
87
-     * id.
88
-     * 
89
-     * @param  integer $id
90
-     * @param  array   $relations
91
-     * @param  array   $columns
92
-     * @return object
93
-     */
94
-    public function find($id, $relations = [], $columns = array('*'));
85
+	/**
86
+	 * Fetch records from the storage based on the given
87
+	 * id.
88
+	 * 
89
+	 * @param  integer $id
90
+	 * @param  array   $relations
91
+	 * @param  array   $columns
92
+	 * @return object
93
+	 */
94
+	public function find($id, $relations = [], $columns = array('*'));
95 95
     
96
-    /**
97
-     * Fetch records from the storage based on the given
98
-     * condition.
99
-     * 
100
-     * @param  array   $conditions array of conditions
101
-     * @param  array   $relations
102
-     * @param  array   $sortBy
103
-     * @param  array   $desc
104
-     * @param  array   $columns
105
-     * @return collection
106
-     */
107
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
96
+	/**
97
+	 * Fetch records from the storage based on the given
98
+	 * condition.
99
+	 * 
100
+	 * @param  array   $conditions array of conditions
101
+	 * @param  array   $relations
102
+	 * @param  array   $sortBy
103
+	 * @param  array   $desc
104
+	 * @param  array   $columns
105
+	 * @return collection
106
+	 */
107
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
108 108
 
109
-    /**
110
-     * Fetch the first record fro the storage based on the given
111
-     * condition.
112
-     * 
113
-     * @param  array   $conditions array of conditions
114
-     * @param  array   $relations
115
-     * @param  array   $columns
116
-     * @return object
117
-     */
118
-    public function first($conditions, $relations = [], $columns = array('*'));
109
+	/**
110
+	 * Fetch the first record fro the storage based on the given
111
+	 * condition.
112
+	 * 
113
+	 * @param  array   $conditions array of conditions
114
+	 * @param  array   $relations
115
+	 * @param  array   $columns
116
+	 * @return object
117
+	 */
118
+	public function first($conditions, $relations = [], $columns = array('*'));
119 119
 }
120 120
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/Http/Controllers/BaseApiController.php 3 patches
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -6,307 +6,307 @@
 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 object
27
-     */
28
-    protected $repo;
23
+	/**
24
+	 * The repo implementation.
25
+	 * 
26
+	 * @var object
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
-        \Auth::shouldUse('api');
242
-        $this->middleware('auth:api', ['except' => $this->skipLoginCheck]);
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
+		\Auth::shouldUse('api');
242
+		$this->middleware('auth:api', ['except' => $this->skipLoginCheck]);
243 243
         
244
-        if ($user = \Auth::user()) 
245
-        {
246
-            $permission       = $permission !== 'index' ? $permission : 'list';
247
-            $isPasswordClient = $user->token()->client->password_client;
244
+		if ($user = \Auth::user()) 
245
+		{
246
+			$permission       = $permission !== 'index' ? $permission : 'list';
247
+			$isPasswordClient = $user->token()->client->password_client;
248 248
 
249
-            if ($user->blocked)
250
-            {
251
-                \ErrorHandler::userIsBlocked();
252
-            }
249
+			if ($user->blocked)
250
+			{
251
+				\ErrorHandler::userIsBlocked();
252
+			}
253 253
 
254
-            if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model)))
255
-            {}
256
-            elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) 
257
-            {}
258
-            else
259
-            {
254
+			if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model)))
255
+			{}
256
+			elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) 
257
+			{}
258
+			else
259
+			{
260 260
 
261
-                \ErrorHandler::noPermissions();
262
-            }
263
-        }
264
-    }
261
+				\ErrorHandler::noPermissions();
262
+			}
263
+		}
264
+	}
265 265
 
266
-    /**
267
-     * Set sessions based on the given headers in the request.
268
-     * 
269
-     * @return void
270
-     */
271
-    private function setSessions()
272
-    {
273
-        \Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
266
+	/**
267
+	 * Set sessions based on the given headers in the request.
268
+	 * 
269
+	 * @return void
270
+	 */
271
+	private function setSessions()
272
+	{
273
+		\Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
274 274
 
275
-        $locale = \Request::header('locale');
276
-        switch ($locale) 
277
-        {
278
-            case 'en':
279
-            \App::setLocale('en');
280
-            \Session::put('locale', 'en');
281
-            break;
275
+		$locale = \Request::header('locale');
276
+		switch ($locale) 
277
+		{
278
+			case 'en':
279
+			\App::setLocale('en');
280
+			\Session::put('locale', 'en');
281
+			break;
282 282
 
283
-            case 'ar':
284
-            \App::setLocale('ar');
285
-            \Session::put('locale', 'ar');
286
-            break;
283
+			case 'ar':
284
+			\App::setLocale('ar');
285
+			\Session::put('locale', 'ar');
286
+			break;
287 287
 
288
-            case 'all':
289
-            \App::setLocale('en');
290
-            \Session::put('locale', 'all');
291
-            break;
288
+			case 'all':
289
+			\App::setLocale('en');
290
+			\Session::put('locale', 'all');
291
+			break;
292 292
 
293
-            default:
294
-            \App::setLocale('en');
295
-            \Session::put('locale', 'en');
296
-            break;
297
-        }
298
-    }
293
+			default:
294
+			\App::setLocale('en');
295
+			\Session::put('locale', 'en');
296
+			break;
297
+		}
298
+	}
299 299
 
300
-    /**
301
-     * Set relation based on the called api.
302
-     * 
303
-     * @param  string $route
304
-     * @return void
305
-     */
306
-    private function setRelations($route)
307
-    {
308
-        $route           = $route !== 'index' ? $route : 'list';
309
-        $relations       = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
310
-        $this->relations = $relations && isset($relations[$route]) ? $relations[$route] : [];
311
-    }
300
+	/**
301
+	 * Set relation based on the called api.
302
+	 * 
303
+	 * @param  string $route
304
+	 * @return void
305
+	 */
306
+	private function setRelations($route)
307
+	{
308
+		$route           = $route !== 'index' ? $route : 'list';
309
+		$relations       = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
310
+		$this->relations = $relations && isset($relations[$route]) ? $relations[$route] : [];
311
+	}
312 312
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
         $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
36 36
         $this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
37 37
         $this->repo                = call_user_func_array("\Core::{$this->model}", []);
38
-        $route                     = explode('@',\Route::currentRouteAction())[1];
38
+        $route                     = explode('@', \Route::currentRouteAction())[1];
39 39
 
40 40
         $this->checkPermission($route);
41 41
         $this->setRelations($route);
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 
254 254
             if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model)))
255 255
             {}
256
-            elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) 
256
+            elseif ( ! $isPasswordClient && $user->tokenCan($this->model.'-'.$permission)) 
257 257
             {}
258 258
             else
259 259
             {
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -173,8 +173,7 @@  discard block
 block discarded – undo
173 173
             if ($request->has('id')) 
174 174
             {
175 175
                 $rule = str_replace('{id}', $request->get('id'), $rule);
176
-            }
177
-            else
176
+            } else
178 177
             {
179 178
                 $rule = str_replace(',{id}', '', $rule);
180 179
             }
@@ -252,10 +251,8 @@  discard block
 block discarded – undo
252 251
             }
253 252
 
254 253
             if ($isPasswordClient && (in_array($permission, $this->skipPermissionCheck) || \Core::users()->can($permission, $this->model)))
255
-            {}
256
-            elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) 
257
-            {}
258
-            else
254
+            {} elseif ( ! $isPasswordClient && $user->tokenCan($this->model . '-' . $permission)) 
255
+            {} else
259 256
             {
260 257
 
261 258
                 \ErrorHandler::noPermissions();
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Repositories/UserRepository.php 4 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
      * Reset the given user's password.
240 240
      *
241 241
      * @param  array  $credentials
242
-     * @return array
242
+     * @return string|null
243 243
      */
244 244
     public function resetPassword($credentials)
245 245
     {
@@ -322,7 +322,6 @@  discard block
 block discarded – undo
322 322
     /**
323 323
      * Save the given data to the logged in user.
324 324
      *
325
-     * @param  array $credentials
326 325
      * @return void
327 326
      */
328 327
     public function saveProfile($data) 
Please login to merge, or discard this patch.
Indentation   +383 added lines, -383 removed lines patch added patch discarded remove patch
@@ -5,394 +5,394 @@
 block discarded – undo
5 5
 
6 6
 class UserRepository extends AbstractRepository
7 7
 {
8
-    /**
9
-     * Return the model full namespace.
10
-     * 
11
-     * @return string
12
-     */
13
-    protected function getModel()
14
-    {
15
-        return 'App\Modules\V1\Acl\AclUser';
16
-    }
17
-
18
-
19
-    /**
20
-     * Return the logged in user account.
21
-     *
22
-     * @param  array   $relations
23
-     * @return boolean
24
-     */
25
-    public function account($relations = [])
26
-    {
27
-        $permissions = [];
28
-        $user        = \Core::users()->find(\Auth::id(), $relations);
29
-        foreach ($user->groups()->get() as $group)
30
-        {
31
-            $group->permissions->each(function ($permission) use (&$permissions){
32
-                $permissions[$permission->model][$permission->id] = $permission->name;
33
-            });
34
-        }
35
-        $user->permissions = $permissions;
36
-
37
-       return $user;
38
-    }
39
-
40
-    /**
41
-     * Check if the logged in user or the given user 
42
-     * has the given permissions on the given model.
43
-     * 
44
-     * @param  string  $nameOfPermission
45
-     * @param  string  $model            
46
-     * @param  boolean $user
47
-     * @return boolean
48
-     */
49
-    public function can($nameOfPermission, $model, $user = false)
50
-    {      
51
-        $user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52
-        $permissions = [];
53
-
54
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
55
-            $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
56
-        });
8
+	/**
9
+	 * Return the model full namespace.
10
+	 * 
11
+	 * @return string
12
+	 */
13
+	protected function getModel()
14
+	{
15
+		return 'App\Modules\V1\Acl\AclUser';
16
+	}
17
+
18
+
19
+	/**
20
+	 * Return the logged in user account.
21
+	 *
22
+	 * @param  array   $relations
23
+	 * @return boolean
24
+	 */
25
+	public function account($relations = [])
26
+	{
27
+		$permissions = [];
28
+		$user        = \Core::users()->find(\Auth::id(), $relations);
29
+		foreach ($user->groups()->get() as $group)
30
+		{
31
+			$group->permissions->each(function ($permission) use (&$permissions){
32
+				$permissions[$permission->model][$permission->id] = $permission->name;
33
+			});
34
+		}
35
+		$user->permissions = $permissions;
36
+
37
+	   return $user;
38
+	}
39
+
40
+	/**
41
+	 * Check if the logged in user or the given user 
42
+	 * has the given permissions on the given model.
43
+	 * 
44
+	 * @param  string  $nameOfPermission
45
+	 * @param  string  $model            
46
+	 * @param  boolean $user
47
+	 * @return boolean
48
+	 */
49
+	public function can($nameOfPermission, $model, $user = false)
50
+	{      
51
+		$user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52
+		$permissions = [];
53
+
54
+		$user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
55
+			$permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
56
+		});
57 57
         
58
-        return in_array($nameOfPermission, $permissions);
59
-    }
60
-
61
-    /**
62
-     * Check if the logged in user has the given group.
63
-     * 
64
-     * @param  string  $groupName
65
-     * @param  integer $userId
66
-     * @return boolean
67
-     */
68
-    public function hasGroup($groupName, $userId = false)
69
-    {
70
-        $userId = $userId ?: \Auth::id();
71
-        $groups = $this->find($userId)->groups;
72
-        return $groups->pluck('name')->search($groupName, true) === false ? false : true;
73
-    }
74
-
75
-    /**
76
-     * Assign the given group ids to the given user.
77
-     * 
78
-     * @param  integer $user_id    
79
-     * @param  array   $group_ids
80
-     * @return object
81
-     */
82
-    public function assignGroups($user_id, $group_ids)
83
-    {
84
-        \DB::transaction(function () use ($user_id, $group_ids) {
85
-            $user = $this->find($user_id);
86
-            $user->groups()->detach();
87
-            $user->groups()->attach($group_ids);
88
-        });
89
-
90
-        return $this->find($user_id);
91
-    }
92
-
93
-    /**
94
-     * Handle a login request to the application.
95
-     * 
96
-     * @param  array   $credentials    
97
-     * @param  boolean $adminLogin
98
-     * @return object
99
-     */
100
-    public function login($credentials, $adminLogin = false)
101
-    {
102
-        if ( ! $user = $this->first(['email' => $credentials['email']])) 
103
-        {
104
-            \ErrorHandler::loginFailed();
105
-        }
106
-        else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
107
-        {
108
-            \ErrorHandler::loginFailed();
109
-        }
110
-        else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
111
-        {
112
-            \ErrorHandler::loginFailed();
113
-        }
114
-        else if ($user->blocked)
115
-        {
116
-            \ErrorHandler::userIsBlocked();
117
-        }
118
-        else if ( ! $user->confirmed)
119
-        {
120
-            \ErrorHandler::emailNotConfirmed();
121
-        }
122
-
123
-        return $user;
124
-    }
125
-
126
-    /**
127
-     * Handle a social login request of the none admin to the application.
128
-     * 
129
-     * @param  array   $credentials
130
-     * @return array
131
-     */
132
-    public function loginSocial($credentials)
133
-    {
134
-        $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
135
-        $user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
136
-
137
-        if ( ! $user->email)
138
-        {
139
-            \ErrorHandler::noSocialEmail();
140
-        }
141
-
142
-        if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
143
-        {
144
-            $data = ['email' => $user->email, 'password' => ''];
145
-            return $this->register($data);
146
-        }
147
-        else
148
-        {
149
-            if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150
-            {
151
-                \ErrorHandler::userAlreadyRegistered();
152
-            }
153
-
154
-            $loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy');
155
-            return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0);
156
-        }
157
-    }
58
+		return in_array($nameOfPermission, $permissions);
59
+	}
60
+
61
+	/**
62
+	 * Check if the logged in user has the given group.
63
+	 * 
64
+	 * @param  string  $groupName
65
+	 * @param  integer $userId
66
+	 * @return boolean
67
+	 */
68
+	public function hasGroup($groupName, $userId = false)
69
+	{
70
+		$userId = $userId ?: \Auth::id();
71
+		$groups = $this->find($userId)->groups;
72
+		return $groups->pluck('name')->search($groupName, true) === false ? false : true;
73
+	}
74
+
75
+	/**
76
+	 * Assign the given group ids to the given user.
77
+	 * 
78
+	 * @param  integer $user_id    
79
+	 * @param  array   $group_ids
80
+	 * @return object
81
+	 */
82
+	public function assignGroups($user_id, $group_ids)
83
+	{
84
+		\DB::transaction(function () use ($user_id, $group_ids) {
85
+			$user = $this->find($user_id);
86
+			$user->groups()->detach();
87
+			$user->groups()->attach($group_ids);
88
+		});
89
+
90
+		return $this->find($user_id);
91
+	}
92
+
93
+	/**
94
+	 * Handle a login request to the application.
95
+	 * 
96
+	 * @param  array   $credentials    
97
+	 * @param  boolean $adminLogin
98
+	 * @return object
99
+	 */
100
+	public function login($credentials, $adminLogin = false)
101
+	{
102
+		if ( ! $user = $this->first(['email' => $credentials['email']])) 
103
+		{
104
+			\ErrorHandler::loginFailed();
105
+		}
106
+		else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
107
+		{
108
+			\ErrorHandler::loginFailed();
109
+		}
110
+		else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
111
+		{
112
+			\ErrorHandler::loginFailed();
113
+		}
114
+		else if ($user->blocked)
115
+		{
116
+			\ErrorHandler::userIsBlocked();
117
+		}
118
+		else if ( ! $user->confirmed)
119
+		{
120
+			\ErrorHandler::emailNotConfirmed();
121
+		}
122
+
123
+		return $user;
124
+	}
125
+
126
+	/**
127
+	 * Handle a social login request of the none admin to the application.
128
+	 * 
129
+	 * @param  array   $credentials
130
+	 * @return array
131
+	 */
132
+	public function loginSocial($credentials)
133
+	{
134
+		$access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
135
+		$user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
136
+
137
+		if ( ! $user->email)
138
+		{
139
+			\ErrorHandler::noSocialEmail();
140
+		}
141
+
142
+		if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
143
+		{
144
+			$data = ['email' => $user->email, 'password' => ''];
145
+			return $this->register($data);
146
+		}
147
+		else
148
+		{
149
+			if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150
+			{
151
+				\ErrorHandler::userAlreadyRegistered();
152
+			}
153
+
154
+			$loginProxy = \App::make('App\Modules\V1\Acl\Proxy\LoginProxy');
155
+			return $loginProxy->login(['email' => $registeredUser->email, 'password' => ''], 0);
156
+		}
157
+	}
158 158
     
159
-    /**
160
-     * Handle a registration request.
161
-     * 
162
-     * @param  array $credentials
163
-     * @return array
164
-     */
165
-    public function register($credentials)
166
-    {
167
-        $user = $this->model->create($credentials);
168
-
169
-        if ( ! env('DISABLE_CONFIRM_EMAIL')) 
170
-        {
171
-            $this->sendConfirmationEmail($user->email);
172
-        }
173
-    }
174
-
175
-    /**
176
-     * Block the user.
177
-     *
178
-     * @param  integer $user_id
179
-     * @return object
180
-     */
181
-    public function block($user_id)
182
-    {
183
-        if ( ! $user = $this->find($user_id)) 
184
-        {
185
-            \ErrorHandler::notFound('user');
186
-        }
187
-        if ( ! $this->hasGroup('Admin'))
188
-        {
189
-            \ErrorHandler::noPermissions();
190
-        }
191
-        else if (\Auth::id() == $user_id)
192
-        {
193
-            \ErrorHandler::noPermissions();
194
-        }
195
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196
-        {
197
-            \ErrorHandler::noPermissions();
198
-        }
199
-
200
-        $user->blocked = 1;
201
-        $user->save();
159
+	/**
160
+	 * Handle a registration request.
161
+	 * 
162
+	 * @param  array $credentials
163
+	 * @return array
164
+	 */
165
+	public function register($credentials)
166
+	{
167
+		$user = $this->model->create($credentials);
168
+
169
+		if ( ! env('DISABLE_CONFIRM_EMAIL')) 
170
+		{
171
+			$this->sendConfirmationEmail($user->email);
172
+		}
173
+	}
174
+
175
+	/**
176
+	 * Block the user.
177
+	 *
178
+	 * @param  integer $user_id
179
+	 * @return object
180
+	 */
181
+	public function block($user_id)
182
+	{
183
+		if ( ! $user = $this->find($user_id)) 
184
+		{
185
+			\ErrorHandler::notFound('user');
186
+		}
187
+		if ( ! $this->hasGroup('Admin'))
188
+		{
189
+			\ErrorHandler::noPermissions();
190
+		}
191
+		else if (\Auth::id() == $user_id)
192
+		{
193
+			\ErrorHandler::noPermissions();
194
+		}
195
+		else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196
+		{
197
+			\ErrorHandler::noPermissions();
198
+		}
199
+
200
+		$user->blocked = 1;
201
+		$user->save();
202 202
         
203
-        return $user;
204
-    }
205
-
206
-    /**
207
-     * Unblock the user.
208
-     *
209
-     * @param  integer $user_id
210
-     * @return object
211
-     */
212
-    public function unblock($user_id)
213
-    {
214
-        if ( ! $this->hasGroup('Admin'))
215
-        {
216
-            \ErrorHandler::noPermissions();
217
-        }
218
-
219
-        $user          = $this->find($user_id);
220
-        $user->blocked = 0;
221
-        $user->save();
222
-
223
-        return $user;
224
-    }
225
-
226
-    /**
227
-     * Send a reset link to the given user.
228
-     *
229
-     * @param  string  $email
230
-     * @return void
231
-     */
232
-    public function sendReset($email)
233
-    {
234
-        if ( ! $user = $this->model->where('email', $email)->first())
235
-        {
236
-            \ErrorHandler::notFound('email');
237
-        }
238
-
239
-        $token = \Password::getRepository()->create($user);
240
-        \Core::notifications()->notify($user, 'ResetPassword', $token);
241
-    }
242
-
243
-    /**
244
-     * Reset the given user's password.
245
-     *
246
-     * @param  array  $credentials
247
-     * @return array
248
-     */
249
-    public function resetPassword($credentials)
250
-    {
251
-        $response = \Password::reset($credentials, function ($user, $password) {
252
-            $user->password = $password;
253
-            $user->save();
254
-        });
255
-
256
-        switch ($response) {
257
-            case \Password::PASSWORD_RESET:
258
-                return 'success';
203
+		return $user;
204
+	}
205
+
206
+	/**
207
+	 * Unblock the user.
208
+	 *
209
+	 * @param  integer $user_id
210
+	 * @return object
211
+	 */
212
+	public function unblock($user_id)
213
+	{
214
+		if ( ! $this->hasGroup('Admin'))
215
+		{
216
+			\ErrorHandler::noPermissions();
217
+		}
218
+
219
+		$user          = $this->find($user_id);
220
+		$user->blocked = 0;
221
+		$user->save();
222
+
223
+		return $user;
224
+	}
225
+
226
+	/**
227
+	 * Send a reset link to the given user.
228
+	 *
229
+	 * @param  string  $email
230
+	 * @return void
231
+	 */
232
+	public function sendReset($email)
233
+	{
234
+		if ( ! $user = $this->model->where('email', $email)->first())
235
+		{
236
+			\ErrorHandler::notFound('email');
237
+		}
238
+
239
+		$token = \Password::getRepository()->create($user);
240
+		\Core::notifications()->notify($user, 'ResetPassword', $token);
241
+	}
242
+
243
+	/**
244
+	 * Reset the given user's password.
245
+	 *
246
+	 * @param  array  $credentials
247
+	 * @return array
248
+	 */
249
+	public function resetPassword($credentials)
250
+	{
251
+		$response = \Password::reset($credentials, function ($user, $password) {
252
+			$user->password = $password;
253
+			$user->save();
254
+		});
255
+
256
+		switch ($response) {
257
+			case \Password::PASSWORD_RESET:
258
+				return 'success';
259 259
                 
260
-            case \Password::INVALID_TOKEN:
261
-                \ErrorHandler::invalidResetToken('token');
262
-
263
-            case \Password::INVALID_PASSWORD:
264
-                \ErrorHandler::invalidResetPassword('email');
265
-
266
-            case \Password::INVALID_USER:
267
-                \ErrorHandler::notFound('user');
268
-
269
-            default:
270
-                \ErrorHandler::generalError();
271
-        }
272
-    }
273
-
274
-    /**
275
-     * Change the logged in user password.
276
-     *
277
-     * @param  array  $credentials
278
-     * @return void
279
-     */
280
-    public function changePassword($credentials)
281
-    {
282
-        $user = \Auth::user();
283
-        if ( ! \Hash::check($credentials['old_password'], $user->password)) 
284
-        {
285
-            \ErrorHandler::invalidOldPassword();
286
-        }
287
-
288
-        $user->password = $credentials['password'];
289
-        $user->save();
290
-    }
291
-
292
-    /**
293
-     * Confirm email using the confirmation code.
294
-     *
295
-     * @param  string $confirmationCode
296
-     * @return void
297
-     */
298
-    public function confirmEmail($confirmationCode)
299
-    {
300
-        $user                    = $this->first(['confirmation_code' => $confirmationCode]);
301
-        $user->confirmed         = 1;
302
-        $user->confirmation_code = null;
303
-        $user->save();
304
-    }
305
-
306
-    /**
307
-     * Send the confirmation mail.
308
-     *
309
-     * @param  string $email
310
-     * @return void
311
-     */
312
-    public function sendConfirmationEmail($email)
313
-    {
314
-        $user = $this->first(['email' => $email]);
315
-        if ($user->confirmed) 
316
-        {
317
-            \ErrorHandler::emailAlreadyConfirmed();
318
-        }
319
-
320
-        $user->confirmed         = 0;
321
-        $user->confirmation_code = sha1(microtime());
322
-        $user->save();
323
-        \Core::notifications()->notify($user, 'ConfirmEmail');
324
-    }
325
-
326
-    /**
327
-     * Paginate all users in the given group based on the given conditions.
328
-     * 
329
-     * @param  string  $groupName
330
-     * @param  array   $relations
331
-     * @param  integer $perPage
332
-     * @param  string  $sortBy
333
-     * @param  boolean $desc
334
-     * @return \Illuminate\Http\Response
335
-     */
336
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
337
-    {   
338
-        unset($conditions['page']);
339
-        $conditions = $this->constructConditions($conditions, $this->model);
340
-        $sort       = $desc ? 'desc' : 'asc';
341
-        $model      = call_user_func_array("{$this->getModel()}::with", array($relations));
342
-
343
-        $model->whereHas('groups', function($q) use ($groupName){
344
-            $q->where('name', $groupName);
345
-        });
260
+			case \Password::INVALID_TOKEN:
261
+				\ErrorHandler::invalidResetToken('token');
262
+
263
+			case \Password::INVALID_PASSWORD:
264
+				\ErrorHandler::invalidResetPassword('email');
265
+
266
+			case \Password::INVALID_USER:
267
+				\ErrorHandler::notFound('user');
268
+
269
+			default:
270
+				\ErrorHandler::generalError();
271
+		}
272
+	}
273
+
274
+	/**
275
+	 * Change the logged in user password.
276
+	 *
277
+	 * @param  array  $credentials
278
+	 * @return void
279
+	 */
280
+	public function changePassword($credentials)
281
+	{
282
+		$user = \Auth::user();
283
+		if ( ! \Hash::check($credentials['old_password'], $user->password)) 
284
+		{
285
+			\ErrorHandler::invalidOldPassword();
286
+		}
287
+
288
+		$user->password = $credentials['password'];
289
+		$user->save();
290
+	}
291
+
292
+	/**
293
+	 * Confirm email using the confirmation code.
294
+	 *
295
+	 * @param  string $confirmationCode
296
+	 * @return void
297
+	 */
298
+	public function confirmEmail($confirmationCode)
299
+	{
300
+		$user                    = $this->first(['confirmation_code' => $confirmationCode]);
301
+		$user->confirmed         = 1;
302
+		$user->confirmation_code = null;
303
+		$user->save();
304
+	}
305
+
306
+	/**
307
+	 * Send the confirmation mail.
308
+	 *
309
+	 * @param  string $email
310
+	 * @return void
311
+	 */
312
+	public function sendConfirmationEmail($email)
313
+	{
314
+		$user = $this->first(['email' => $email]);
315
+		if ($user->confirmed) 
316
+		{
317
+			\ErrorHandler::emailAlreadyConfirmed();
318
+		}
319
+
320
+		$user->confirmed         = 0;
321
+		$user->confirmation_code = sha1(microtime());
322
+		$user->save();
323
+		\Core::notifications()->notify($user, 'ConfirmEmail');
324
+	}
325
+
326
+	/**
327
+	 * Paginate all users in the given group based on the given conditions.
328
+	 * 
329
+	 * @param  string  $groupName
330
+	 * @param  array   $relations
331
+	 * @param  integer $perPage
332
+	 * @param  string  $sortBy
333
+	 * @param  boolean $desc
334
+	 * @return \Illuminate\Http\Response
335
+	 */
336
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
337
+	{   
338
+		unset($conditions['page']);
339
+		$conditions = $this->constructConditions($conditions, $this->model);
340
+		$sort       = $desc ? 'desc' : 'asc';
341
+		$model      = call_user_func_array("{$this->getModel()}::with", array($relations));
342
+
343
+		$model->whereHas('groups', function($q) use ($groupName){
344
+			$q->where('name', $groupName);
345
+		});
346 346
 
347 347
         
348
-        if (count($conditions['conditionValues']))
349
-        {
350
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
351
-        }
352
-
353
-        if ($perPage) 
354
-        {
355
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
356
-        }
357
-
358
-        return $model->orderBy($sortBy, $sort)->get();
359
-    }
360
-
361
-    /**
362
-     * Save the given data to the logged in user.
363
-     *
364
-     * @param  array $credentials
365
-     * @return void
366
-     */
367
-    public function saveProfile($data) 
368
-    {
369
-        if (array_key_exists('profile_picture', $data)) 
370
-        {
371
-            $data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
372
-        }
348
+		if (count($conditions['conditionValues']))
349
+		{
350
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
351
+		}
352
+
353
+		if ($perPage) 
354
+		{
355
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
356
+		}
357
+
358
+		return $model->orderBy($sortBy, $sort)->get();
359
+	}
360
+
361
+	/**
362
+	 * Save the given data to the logged in user.
363
+	 *
364
+	 * @param  array $credentials
365
+	 * @return void
366
+	 */
367
+	public function saveProfile($data) 
368
+	{
369
+		if (array_key_exists('profile_picture', $data)) 
370
+		{
371
+			$data['profile_picture'] = \Media::uploadImageBas64($data['profile_picture'], 'admins/profile_pictures');
372
+		}
373 373
         
374
-        $data['id'] = \Auth::id();
375
-        $this->save($data);
376
-    }
377
-
378
-    /**
379
-     * Ensure access token hasn't expired or revoked.
380
-     * 
381
-     * @param  string $accessToken
382
-     * @return boolean
383
-     */
384
-    public function accessTokenExpiredOrRevoked($accessToken)
385
-    {
386
-
387
-        $accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
388
-        $data = new ValidationData();
389
-        $data->setCurrentTime(time());
390
-
391
-        if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
392
-        {
393
-            return true;
394
-        }
395
-
396
-        return false;
397
-    }
374
+		$data['id'] = \Auth::id();
375
+		$this->save($data);
376
+	}
377
+
378
+	/**
379
+	 * Ensure access token hasn't expired or revoked.
380
+	 * 
381
+	 * @param  string $accessToken
382
+	 * @return boolean
383
+	 */
384
+	public function accessTokenExpiredOrRevoked($accessToken)
385
+	{
386
+
387
+		$accessTokenRepository = \App::make('League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface');
388
+		$data = new ValidationData();
389
+		$data->setCurrentTime(time());
390
+
391
+		if ($accessToken->validate($data) === false || $accessTokenRepository->isAccessTokenRevoked($accessToken->getClaim('jti'))) 
392
+		{
393
+			return true;
394
+		}
395
+
396
+		return false;
397
+	}
398 398
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
         $user        = \Core::users()->find(\Auth::id(), $relations);
29 29
         foreach ($user->groups()->get() as $group)
30 30
         {
31
-            $group->permissions->each(function ($permission) use (&$permissions){
31
+            $group->permissions->each(function($permission) use (&$permissions){
32 32
                 $permissions[$permission->model][$permission->id] = $permission->name;
33 33
             });
34 34
         }
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
         $user        = $user ?: $this->find(\Auth::id(), ['groups.permissions']);
52 52
         $permissions = [];
53 53
 
54
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
54
+        $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model){
55 55
             $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
56 56
         });
57 57
         
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function assignGroups($user_id, $group_ids)
83 83
     {
84
-        \DB::transaction(function () use ($user_id, $group_ids) {
84
+        \DB::transaction(function() use ($user_id, $group_ids) {
85 85
             $user = $this->find($user_id);
86 86
             $user->groups()->detach();
87 87
             $user->groups()->attach($group_ids);
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
      */
249 249
     public function resetPassword($credentials)
250 250
     {
251
-        $response = \Password::reset($credentials, function ($user, $password) {
251
+        $response = \Password::reset($credentials, function($user, $password) {
252 252
             $user->password = $password;
253 253
             $user->save();
254 254
         });
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -102,20 +102,16 @@  discard block
 block discarded – undo
102 102
         if ( ! $user = $this->first(['email' => $credentials['email']])) 
103 103
         {
104 104
             \ErrorHandler::loginFailed();
105
-        }
106
-        else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
105
+        } else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
107 106
         {
108 107
             \ErrorHandler::loginFailed();
109
-        }
110
-        else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
108
+        } else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
111 109
         {
112 110
             \ErrorHandler::loginFailed();
113
-        }
114
-        else if ($user->blocked)
111
+        } else if ($user->blocked)
115 112
         {
116 113
             \ErrorHandler::userIsBlocked();
117
-        }
118
-        else if ( ! $user->confirmed)
114
+        } else if ( ! $user->confirmed)
119 115
         {
120 116
             \ErrorHandler::emailNotConfirmed();
121 117
         }
@@ -143,8 +139,7 @@  discard block
 block discarded – undo
143 139
         {
144 140
             $data = ['email' => $user->email, 'password' => ''];
145 141
             return $this->register($data);
146
-        }
147
-        else
142
+        } else
148 143
         {
149 144
             if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
150 145
             {
@@ -187,12 +182,10 @@  discard block
 block discarded – undo
187 182
         if ( ! $this->hasGroup('Admin'))
188 183
         {
189 184
             \ErrorHandler::noPermissions();
190
-        }
191
-        else if (\Auth::id() == $user_id)
185
+        } else if (\Auth::id() == $user_id)
192 186
         {
193 187
             \ErrorHandler::noPermissions();
194
-        }
195
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
188
+        } else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
196 189
         {
197 190
             \ErrorHandler::noPermissions();
198 191
         }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Database/Seeds/OauthClientsTableSeeder.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -6,82 +6,82 @@
 block discarded – undo
6 6
 
7 7
 class OauthClientsTableSeeder extends Seeder
8 8
 {
9
-    /**
10
-     * Run the database seeds.
11
-     *
12
-     * @return void
13
-     */
14
-    public function run()
15
-    {
16
-    	/**
17
-         * Insert the permissions related to oauthClients table.
18
-         */
19
-        \DB::table('permissions')->insert(
20
-        	[
21
-        		/**
22
-        		 * Users model permissions.
23
-        		 */
24
-	        	[
25
-	        	'name'       => 'list',
26
-	        	'model'      => 'oauthClients',
27
-	        	'created_at' => \DB::raw('NOW()'),
28
-	        	'updated_at' => \DB::raw('NOW()')
29
-	        	],
30
-	        	[
31
-	        	'name'       => 'find',
32
-	        	'model'      => 'oauthClients',
33
-	        	'created_at' => \DB::raw('NOW()'),
34
-	        	'updated_at' => \DB::raw('NOW()')
35
-	        	],
36
-	        	[
37
-	        	'name'       => 'search',
38
-	        	'model'      => 'oauthClients',
39
-	        	'created_at' => \DB::raw('NOW()'),
40
-	        	'updated_at' => \DB::raw('NOW()')
41
-	        	],
42
-	        	[
43
-	        	'name'       => 'paginate',
44
-	        	'model'      => 'oauthClients',
45
-	        	'created_at' => \DB::raw('NOW()'),
46
-	        	'updated_at' => \DB::raw('NOW()')
47
-	        	],
48
-	        	[
49
-	        	'name'       => 'revoke',
50
-	        	'model'      => 'oauthClients',
51
-	        	'created_at' => \DB::raw('NOW()'),
52
-	        	'updated_at' => \DB::raw('NOW()')
53
-	        	],
54
-	        	[
55
-	        	'name'       => 'unRevoke',
56
-	        	'model'      => 'oauthClients',
57
-	        	'created_at' => \DB::raw('NOW()'),
58
-	        	'updated_at' => \DB::raw('NOW()')
59
-	        	],
60
-	        	[
61
-	        	'name'       => 'first',
62
-	        	'model'      => 'oauthClients',
63
-	        	'created_at' => \DB::raw('NOW()'),
64
-	        	'updated_at' => \DB::raw('NOW()')
65
-	        	],
66
-	        	[
67
-	        	'name'       => 'findby',
68
-	        	'model'      => 'oauthClients',
69
-	        	'created_at' => \DB::raw('NOW()'),
70
-	        	'updated_at' => \DB::raw('NOW()')
71
-	        	],
72
-	        	[
73
-	        	'name'       => 'paginateby',
74
-	        	'model'      => 'oauthClients',
75
-	        	'created_at' => \DB::raw('NOW()'),
76
-	        	'updated_at' => \DB::raw('NOW()')
77
-	        	],
78
-	        	[
79
-	        	'name'       => 'save',
80
-	        	'model'      => 'oauthClients',
81
-	        	'created_at' => \DB::raw('NOW()'),
82
-	        	'updated_at' => \DB::raw('NOW()')
83
-	        	]
84
-        	]
85
-        );
86
-    }
9
+	/**
10
+	 * Run the database seeds.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function run()
15
+	{
16
+		/**
17
+		 * Insert the permissions related to oauthClients table.
18
+		 */
19
+		\DB::table('permissions')->insert(
20
+			[
21
+				/**
22
+				 * Users model permissions.
23
+				 */
24
+				[
25
+				'name'       => 'list',
26
+				'model'      => 'oauthClients',
27
+				'created_at' => \DB::raw('NOW()'),
28
+				'updated_at' => \DB::raw('NOW()')
29
+				],
30
+				[
31
+				'name'       => 'find',
32
+				'model'      => 'oauthClients',
33
+				'created_at' => \DB::raw('NOW()'),
34
+				'updated_at' => \DB::raw('NOW()')
35
+				],
36
+				[
37
+				'name'       => 'search',
38
+				'model'      => 'oauthClients',
39
+				'created_at' => \DB::raw('NOW()'),
40
+				'updated_at' => \DB::raw('NOW()')
41
+				],
42
+				[
43
+				'name'       => 'paginate',
44
+				'model'      => 'oauthClients',
45
+				'created_at' => \DB::raw('NOW()'),
46
+				'updated_at' => \DB::raw('NOW()')
47
+				],
48
+				[
49
+				'name'       => 'revoke',
50
+				'model'      => 'oauthClients',
51
+				'created_at' => \DB::raw('NOW()'),
52
+				'updated_at' => \DB::raw('NOW()')
53
+				],
54
+				[
55
+				'name'       => 'unRevoke',
56
+				'model'      => 'oauthClients',
57
+				'created_at' => \DB::raw('NOW()'),
58
+				'updated_at' => \DB::raw('NOW()')
59
+				],
60
+				[
61
+				'name'       => 'first',
62
+				'model'      => 'oauthClients',
63
+				'created_at' => \DB::raw('NOW()'),
64
+				'updated_at' => \DB::raw('NOW()')
65
+				],
66
+				[
67
+				'name'       => 'findby',
68
+				'model'      => 'oauthClients',
69
+				'created_at' => \DB::raw('NOW()'),
70
+				'updated_at' => \DB::raw('NOW()')
71
+				],
72
+				[
73
+				'name'       => 'paginateby',
74
+				'model'      => 'oauthClients',
75
+				'created_at' => \DB::raw('NOW()'),
76
+				'updated_at' => \DB::raw('NOW()')
77
+				],
78
+				[
79
+				'name'       => 'save',
80
+				'model'      => 'oauthClients',
81
+				'created_at' => \DB::raw('NOW()'),
82
+				'updated_at' => \DB::raw('NOW()')
83
+				]
84
+			]
85
+		);
86
+	}
87 87
 }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Repositories/OauthClientRepository.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -4,37 +4,37 @@
 block discarded – undo
4 4
 
5 5
 class OauthClientRepository 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\OauthClient';
15
-    }
7
+	/**
8
+	 * Return the model full namespace.
9
+	 * 
10
+	 * @return string
11
+	 */
12
+	protected function getModel()
13
+	{
14
+		return 'App\Modules\V1\Acl\OauthClient';
15
+	}
16 16
 
17
-    /**
18
-     * Revoke the given client.
19
-     *
20
-     * @param  integer  $clientId
21
-     * @return void
22
-     */
23
-    public function revoke($clientId)
24
-    {
25
-        $client = $this->find($clientId);
26
-        $client->tokens()->update(['revoked' => true]);
27
-        $this->save(['id'=> $clientId, 'revoked' => true]);
28
-    }
17
+	/**
18
+	 * Revoke the given client.
19
+	 *
20
+	 * @param  integer  $clientId
21
+	 * @return void
22
+	 */
23
+	public function revoke($clientId)
24
+	{
25
+		$client = $this->find($clientId);
26
+		$client->tokens()->update(['revoked' => true]);
27
+		$this->save(['id'=> $clientId, 'revoked' => true]);
28
+	}
29 29
 
30
-    /**
31
-     * Un revoke the given client.
32
-     *
33
-     * @param  integer  $clientId
34
-     * @return void
35
-     */
36
-    public function unRevoke($clientId)
37
-    {
38
-        $this->save(['id'=> $clientId, 'revoked' => false]);
39
-    }
30
+	/**
31
+	 * Un revoke the given client.
32
+	 *
33
+	 * @param  integer  $clientId
34
+	 * @return void
35
+	 */
36
+	public function unRevoke($clientId)
37
+	{
38
+		$this->save(['id'=> $clientId, 'revoked' => false]);
39
+	}
40 40
 }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Http/Controllers/OauthClientsController.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -8,44 +8,44 @@
 block discarded – undo
8 8
 
9 9
 class OauthClientsController extends BaseApiController
10 10
 {
11
-    /**
12
-     * The name of the model that is used by the base api controller 
13
-     * to preform actions like (add, edit ... etc).
14
-     * @var string
15
-     */
16
-    protected $model               = 'oauthClients';
11
+	/**
12
+	 * The name of the model that is used by the base api controller 
13
+	 * to preform actions like (add, edit ... etc).
14
+	 * @var string
15
+	 */
16
+	protected $model               = 'oauthClients';
17 17
 
18
-    /**
19
-     * The validations rules used by the base api controller
20
-     * to check before add.
21
-     * @var array
22
-     */
23
-    protected $validationRules  = [
24
-        'name'     => 'required|max:255',
25
-        'redirect' => 'required|url',
26
-        'user_id'  => 'required|exists:users,id',
27
-        'revoked'  => 'boolean'
28
-    ];
18
+	/**
19
+	 * The validations rules used by the base api controller
20
+	 * to check before add.
21
+	 * @var array
22
+	 */
23
+	protected $validationRules  = [
24
+		'name'     => 'required|max:255',
25
+		'redirect' => 'required|url',
26
+		'user_id'  => 'required|exists:users,id',
27
+		'revoked'  => 'boolean'
28
+	];
29 29
 
30
-    /**
31
-     * Revoke the given client.
32
-     *
33
-     * @param  integer  $clientId Id of the client
34
-     * @return \Illuminate\Http\Response
35
-     */
36
-    public function revoke($clientId)
37
-    {
38
-        return \Response::json($this->repo->revoke($clientId), 200);
39
-    }
30
+	/**
31
+	 * Revoke the given client.
32
+	 *
33
+	 * @param  integer  $clientId Id of the client
34
+	 * @return \Illuminate\Http\Response
35
+	 */
36
+	public function revoke($clientId)
37
+	{
38
+		return \Response::json($this->repo->revoke($clientId), 200);
39
+	}
40 40
 
41
-    /**
42
-     * Un revoke the given client.
43
-     *
44
-     * @param  integer  $clientId Id of the client
45
-     * @return \Illuminate\Http\Response
46
-     */
47
-    public function unRevoke($clientId)
48
-    {
49
-        return \Response::json($this->repo->unRevoke($clientId), 200);
50
-    }
41
+	/**
42
+	 * Un revoke the given client.
43
+	 *
44
+	 * @param  integer  $clientId Id of the client
45
+	 * @return \Illuminate\Http\Response
46
+	 */
47
+	public function unRevoke($clientId)
48
+	{
49
+		return \Response::json($this->repo->unRevoke($clientId), 200);
50
+	}
51 51
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,14 +13,14 @@
 block discarded – undo
13 13
      * to preform actions like (add, edit ... etc).
14 14
      * @var string
15 15
      */
16
-    protected $model               = 'oauthClients';
16
+    protected $model = 'oauthClients';
17 17
 
18 18
     /**
19 19
      * The validations rules used by the base api controller
20 20
      * to check before add.
21 21
      * @var array
22 22
      */
23
-    protected $validationRules  = [
23
+    protected $validationRules = [
24 24
         'name'     => 'required|max:255',
25 25
         'redirect' => 'required|url',
26 26
         'user_id'  => 'required|exists:users,id',
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Proxy/LoginProxy.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -5,105 +5,105 @@
 block discarded – undo
5 5
 
6 6
 class LoginProxy
7 7
 {
8
-    private $apiConsumer;
9
-
10
-    private $auth;
11
-
12
-    private $db;
13
-
14
-    private $request;
15
-
16
-    private $userRepository;
17
-
18
-    public function __construct(Application $app) 
19
-    {
20
-
21
-        $this->userRepository = $app->make('App\Modules\V1\Acl\Repositories\UserRepository');
22
-        $this->apiConsumer    = $app->make('apiconsumer');
23
-        $this->auth           = $app->make('auth');
24
-        $this->db             = $app->make('db');
25
-        $this->request        = $app->make('request');
26
-    }
27
-
28
-    /**
29
-     * Attempt to create an access token using user credentials.
30
-     *
31
-     * @param  array   $credentials
32
-     * @param  boolean $adminLogin
33
-     * @return array
34
-     */
35
-    public function login($credentials, $adminLogin = false)
36
-    {
37
-        $this->userRepository->login($credentials, $adminLogin);
38
-
39
-        return $this->proxy('password', [
40
-            'username' => $credentials['email'],
41
-            'password' => $credentials['password']
42
-        ]);
43
-    }
44
-
45
-    /**
46
-     * Attempt to refresh the access token useing the given refresh token.
47
-     * 
48
-     * @param  string $refreshToken
49
-     * @return array
50
-     */
51
-    public function refreshtoken($refreshToken)
52
-    {
53
-        return $this->proxy('refresh_token', [
54
-            'refresh_token' => $refreshToken
55
-        ]);
56
-    }
57
-
58
-    /**
59
-     * Proxy a request to the OAuth server.
60
-     *
61
-     * @param string $grantType what type of grant type should be proxied
62
-     * @param array 
63
-     */
64
-    public function proxy($grantType, array $data = [])
65
-    {
66
-        $data = array_merge($data, [
67
-            'client_id'     => env('PASSWORD_CLIENT_ID'),
68
-            'client_secret' => env('PASSWORD_CLIENT_SECRET'),
69
-            'grant_type'    => $grantType
70
-        ]);
71
-
72
-        $response = $this->apiConsumer->post('/oauth/token', $data);
73
-
74
-        if ( ! $response->isSuccessful()) 
75
-        {
76
-            if ($grantType == 'refresh_token') 
77
-            {
78
-                \ErrorHandler::invalidRefreshToken();
79
-            }
80
-
81
-            \ErrorHandler::loginFailed();
82
-        }
83
-
84
-        $data = json_decode($response->getContent());
85
-
86
-        return [
87
-            'access_token'  => $data->access_token,
88
-            'refresh_token' => $data->refresh_token,
89
-            'expires_in'    => $data->expires_in
90
-        ];
91
-    }
92
-
93
-    /**
94
-     * Logs out the user. We revoke access token and refresh token.
95
-     */
96
-    public function logout()
97
-    {
98
-        $accessToken = $this->auth->user()->token();
99
-
100
-        $this->db
101
-            ->table('oauth_refresh_tokens')
102
-            ->where('access_token_id', $accessToken->id)
103
-            ->update([
104
-                'revoked' => true
105
-            ]);
106
-
107
-        $accessToken->revoke();
108
-    }
8
+	private $apiConsumer;
9
+
10
+	private $auth;
11
+
12
+	private $db;
13
+
14
+	private $request;
15
+
16
+	private $userRepository;
17
+
18
+	public function __construct(Application $app) 
19
+	{
20
+
21
+		$this->userRepository = $app->make('App\Modules\V1\Acl\Repositories\UserRepository');
22
+		$this->apiConsumer    = $app->make('apiconsumer');
23
+		$this->auth           = $app->make('auth');
24
+		$this->db             = $app->make('db');
25
+		$this->request        = $app->make('request');
26
+	}
27
+
28
+	/**
29
+	 * Attempt to create an access token using user credentials.
30
+	 *
31
+	 * @param  array   $credentials
32
+	 * @param  boolean $adminLogin
33
+	 * @return array
34
+	 */
35
+	public function login($credentials, $adminLogin = false)
36
+	{
37
+		$this->userRepository->login($credentials, $adminLogin);
38
+
39
+		return $this->proxy('password', [
40
+			'username' => $credentials['email'],
41
+			'password' => $credentials['password']
42
+		]);
43
+	}
44
+
45
+	/**
46
+	 * Attempt to refresh the access token useing the given refresh token.
47
+	 * 
48
+	 * @param  string $refreshToken
49
+	 * @return array
50
+	 */
51
+	public function refreshtoken($refreshToken)
52
+	{
53
+		return $this->proxy('refresh_token', [
54
+			'refresh_token' => $refreshToken
55
+		]);
56
+	}
57
+
58
+	/**
59
+	 * Proxy a request to the OAuth server.
60
+	 *
61
+	 * @param string $grantType what type of grant type should be proxied
62
+	 * @param array 
63
+	 */
64
+	public function proxy($grantType, array $data = [])
65
+	{
66
+		$data = array_merge($data, [
67
+			'client_id'     => env('PASSWORD_CLIENT_ID'),
68
+			'client_secret' => env('PASSWORD_CLIENT_SECRET'),
69
+			'grant_type'    => $grantType
70
+		]);
71
+
72
+		$response = $this->apiConsumer->post('/oauth/token', $data);
73
+
74
+		if ( ! $response->isSuccessful()) 
75
+		{
76
+			if ($grantType == 'refresh_token') 
77
+			{
78
+				\ErrorHandler::invalidRefreshToken();
79
+			}
80
+
81
+			\ErrorHandler::loginFailed();
82
+		}
83
+
84
+		$data = json_decode($response->getContent());
85
+
86
+		return [
87
+			'access_token'  => $data->access_token,
88
+			'refresh_token' => $data->refresh_token,
89
+			'expires_in'    => $data->expires_in
90
+		];
91
+	}
92
+
93
+	/**
94
+	 * Logs out the user. We revoke access token and refresh token.
95
+	 */
96
+	public function logout()
97
+	{
98
+		$accessToken = $this->auth->user()->token();
99
+
100
+		$this->db
101
+			->table('oauth_refresh_tokens')
102
+			->where('access_token_id', $accessToken->id)
103
+			->update([
104
+				'revoked' => true
105
+			]);
106
+
107
+		$accessToken->revoke();
108
+	}
109 109
 }
110 110
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Reporting/Repositories/ReportRepository.php 3 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -4,67 +4,67 @@
 block discarded – undo
4 4
 
5 5
 class ReportRepository 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\Reporting\Report';
15
-    }
7
+	/**
8
+	 * Return the model full namespace.
9
+	 * 
10
+	 * @return string
11
+	 */
12
+	protected function getModel()
13
+	{
14
+		return 'App\Modules\V1\Reporting\Report';
15
+	}
16 16
 
17
-    /**
18
-     * Render the given report db view based on the given
19
-     * condition.
20
-     *
21
-     * @param  string  $reportName
22
-     * @param  array   $conditions array of conditions
23
-     * @param  integer $perPage
24
-     * @param  array   $relations
25
-     * @param  boolean   $skipPermission
26
-     * @return object
27
-     */
28
-    public function getReport($reportName, $conditions = false, $perPage = 0, $relations = [], $skipPermission = false)
29
-    {
30
-        /**
31
-         * Fetch the report from db.
32
-         */
33
-        $reportConditions = $this->constructConditions(['report_name' => $reportName], $this->model);
34
-        $report           = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($reportConditions['conditionString'], $reportConditions['conditionValues'])->first();
17
+	/**
18
+	 * Render the given report db view based on the given
19
+	 * condition.
20
+	 *
21
+	 * @param  string  $reportName
22
+	 * @param  array   $conditions array of conditions
23
+	 * @param  integer $perPage
24
+	 * @param  array   $relations
25
+	 * @param  boolean   $skipPermission
26
+	 * @return object
27
+	 */
28
+	public function getReport($reportName, $conditions = false, $perPage = 0, $relations = [], $skipPermission = false)
29
+	{
30
+		/**
31
+		 * Fetch the report from db.
32
+		 */
33
+		$reportConditions = $this->constructConditions(['report_name' => $reportName], $this->model);
34
+		$report           = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($reportConditions['conditionString'], $reportConditions['conditionValues'])->first();
35 35
         
36
-        /**
37
-         * Check report existance and permission.
38
-         */
39
-        if ( ! $report) 
40
-        {
41
-            \ErrorHandler::notFound('report');
42
-        }
43
-        else if (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports'))
44
-        {
45
-            \ErrorHandler::noPermissions();
46
-        }
36
+		/**
37
+		 * Check report existance and permission.
38
+		 */
39
+		if ( ! $report) 
40
+		{
41
+			\ErrorHandler::notFound('report');
42
+		}
43
+		else if (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports'))
44
+		{
45
+			\ErrorHandler::noPermissions();
46
+		}
47 47
 
48
-        /**
49
-         * Fetch data from the report based on the given conditions.
50
-         */
51
-        $report = \DB::table($report->view_name);
52
-        unset($conditions['page']);
53
-        if (count($conditions))
54
-        {
55
-            $conditions = $this->constructConditions($conditions, $this->model);
56
-            $report->whereRaw($conditions['conditionString'], $conditions['conditionValues']);   
57
-        }
58
-        /**
59
-         * Paginate or all data.
60
-         */
61
-        if ($perPage) 
62
-        {
63
-            return $report->paginate($perPage);
64
-        }
65
-        else
66
-        {
67
-            return $report->get();  
68
-        }
69
-    }
48
+		/**
49
+		 * Fetch data from the report based on the given conditions.
50
+		 */
51
+		$report = \DB::table($report->view_name);
52
+		unset($conditions['page']);
53
+		if (count($conditions))
54
+		{
55
+			$conditions = $this->constructConditions($conditions, $this->model);
56
+			$report->whereRaw($conditions['conditionString'], $conditions['conditionValues']);   
57
+		}
58
+		/**
59
+		 * Paginate or all data.
60
+		 */
61
+		if ($perPage) 
62
+		{
63
+			return $report->paginate($perPage);
64
+		}
65
+		else
66
+		{
67
+			return $report->get();  
68
+		}
69
+	}
70 70
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
         {
41 41
             \ErrorHandler::notFound('report');
42 42
         }
43
-        else if (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports'))
43
+        else if ( ! $skipPermission && ! \Core::users()->can($report->view_name, 'reports'))
44 44
         {
45 45
             \ErrorHandler::noPermissions();
46 46
         }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -39,8 +39,7 @@  discard block
 block discarded – undo
39 39
         if ( ! $report) 
40 40
         {
41 41
             \ErrorHandler::notFound('report');
42
-        }
43
-        else if (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports'))
42
+        } else if (! $skipPermission && ! \Core::users()->can($report->view_name, 'reports'))
44 43
         {
45 44
             \ErrorHandler::noPermissions();
46 45
         }
@@ -61,8 +60,7 @@  discard block
 block discarded – undo
61 60
         if ($perPage) 
62 61
         {
63 62
             return $report->paginate($perPage);
64
-        }
65
-        else
63
+        } else
66 64
         {
67 65
             return $report->get();  
68 66
         }
Please login to merge, or discard this patch.
src/Modules/V1/Notifications/Notification.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -5,23 +5,23 @@
 block discarded – undo
5 5
 
6 6
 class Notification extends DatabaseNotification{
7 7
 
8
-    public function getCreatedAtAttribute($value)
9
-    {
10
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
11
-    }
8
+	public function getCreatedAtAttribute($value)
9
+	{
10
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
11
+	}
12 12
 
13
-    public function getUpdatedAtAttribute($value)
14
-    {
15
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
16
-    }
13
+	public function getUpdatedAtAttribute($value)
14
+	{
15
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
16
+	}
17 17
 
18
-    public function getDeletedAtAttribute($value)
19
-    {
20
-        return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
21
-    }
18
+	public function getDeletedAtAttribute($value)
19
+	{
20
+		return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
21
+	}
22 22
 
23
-    public function getReadAtAttribute($value)
24
-    {
25
-        return ! $value ? false : \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
26
-    }
23
+	public function getReadAtAttribute($value)
24
+	{
25
+		return ! $value ? false : \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString();
26
+	}
27 27
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 use Illuminate\Notifications\DatabaseNotification;
4 4
 use Illuminate\Database\Eloquent\SoftDeletes;
5 5
 
6
-class Notification extends DatabaseNotification{
6
+class Notification extends DatabaseNotification {
7 7
 
8 8
     public function getCreatedAtAttribute($value)
9 9
     {
Please login to merge, or discard this patch.