@@ -37,23 +37,20 @@ class AuthComponent extends Object {
37
37
* Maintains current user login state.
38
38
*
39
39
* @var boolean
40
- * @access private
41
40
*/
42
41
protected $ _loggedIn = false ;
43
42
44
43
/**
45
44
* Other components utilized by AuthComponent
46
45
*
47
46
* @var array
48
- * @access public
49
47
*/
50
48
public $ components = array ('Session ' , 'RequestHandler ' );
51
49
52
50
/**
53
51
* A reference to the object used for authentication
54
52
*
55
53
* @var object
56
- * @access public
57
54
* @link http://book.cakephp.org/view/1278/authenticate
58
55
*/
59
56
public $ authenticate = null ;
@@ -67,7 +64,6 @@ class AuthComponent extends Object {
67
64
* 'object' will validate Controller::action against object::isAuthorized(user, controller, action)
68
65
*
69
66
* @var mixed
70
- * @access public
71
67
* @link http://book.cakephp.org/view/1275/authorize
72
68
*/
73
69
public $ authorize = false ;
@@ -77,7 +73,6 @@ class AuthComponent extends Object {
77
73
* with an invalid or expired session
78
74
*
79
75
* @var string
80
- * @access public
81
76
* @link http://book.cakephp.org/view/1277/ajaxLogin
82
77
*/
83
78
public $ ajaxLogin = null ;
@@ -86,15 +81,13 @@ class AuthComponent extends Object {
86
81
* The name of the element used for SessionComponent::setFlash
87
82
*
88
83
* @var string
89
- * @access public
90
84
*/
91
85
public $ flashElement = 'default ' ;
92
86
93
87
/**
94
88
* The name of the model that represents users which will be authenticated. Defaults to 'User'.
95
89
*
96
90
* @var string
97
- * @access public
98
91
* @link http://book.cakephp.org/view/1266/userModel
99
92
*/
100
93
public $ userModel = 'User ' ;
@@ -104,7 +97,6 @@ class AuthComponent extends Object {
104
97
* i.e. array('User.is_active' => 1).
105
98
*
106
99
* @var array
107
- * @access public
108
100
* @link http://book.cakephp.org/view/1268/userScope
109
101
*/
110
102
public $ userScope = array ();
@@ -114,7 +106,6 @@ class AuthComponent extends Object {
114
106
* $userModel, i.e. array('username' => 'login_name', 'password' => 'passwd').
115
107
*
116
108
* @var array
117
- * @access public
118
109
* @link http://book.cakephp.org/view/1267/fields
119
110
*/
120
111
public $ fields = array ('username ' => 'username ' , 'password ' => 'password ' );
@@ -124,7 +115,6 @@ class AuthComponent extends Object {
124
115
* unspecified, it will be "Auth.{$userModel name}".
125
116
*
126
117
* @var string
127
- * @access public
128
118
* @link http://book.cakephp.org/view/1276/sessionKey
129
119
*/
130
120
public $ sessionKey = null ;
@@ -136,7 +126,6 @@ class AuthComponent extends Object {
136
126
* "Controllers/".
137
127
*
138
128
* @var string
139
- * @access public
140
129
* @link http://book.cakephp.org/view/1279/actionPath
141
130
*/
142
131
public $ actionPath = null ;
@@ -146,7 +135,6 @@ class AuthComponent extends Object {
146
135
* logins.
147
136
*
148
137
* @var mixed
149
- * @access public
150
138
* @link http://book.cakephp.org/view/1269/loginAction
151
139
*/
152
140
public $ loginAction = null ;
@@ -158,7 +146,6 @@ class AuthComponent extends Object {
158
146
* set, the user will be redirected to the page specified in $loginRedirect.
159
147
*
160
148
* @var mixed
161
- * @access public
162
149
* @link http://book.cakephp.org/view/1270/loginRedirect
163
150
*/
164
151
public $ loginRedirect = null ;
@@ -169,7 +156,6 @@ class AuthComponent extends Object {
169
156
* Defaults to AuthComponent::$loginAction.
170
157
*
171
158
* @var mixed
172
- * @access public
173
159
* @see AuthComponent::$loginAction
174
160
* @see AuthComponent::logout()
175
161
* @link http://book.cakephp.org/view/1271/logoutRedirect
@@ -180,7 +166,6 @@ class AuthComponent extends Object {
180
166
* The name of model or model object, or any other object has an isAuthorized method.
181
167
*
182
168
* @var string
183
- * @access public
184
169
*/
185
170
public $ object = null ;
186
171
@@ -189,7 +174,6 @@ class AuthComponent extends Object {
189
174
* login failures, so as not to expose information on why the login failed.
190
175
*
191
176
* @var string
192
- * @access public
193
177
* @link http://book.cakephp.org/view/1272/loginError
194
178
*/
195
179
public $ loginError = null ;
@@ -199,7 +183,6 @@ class AuthComponent extends Object {
199
183
* acccess.
200
184
*
201
185
* @var string
202
- * @access public
203
186
* @link http://book.cakephp.org/view/1273/authError
204
187
*/
205
188
public $ authError = null ;
@@ -208,7 +191,6 @@ class AuthComponent extends Object {
208
191
* Determines whether AuthComponent will automatically redirect and exit if login is successful.
209
192
*
210
193
* @var boolean
211
- * @access public
212
194
* @link http://book.cakephp.org/view/1274/autoRedirect
213
195
*/
214
196
public $ autoRedirect = true ;
@@ -217,7 +199,6 @@ class AuthComponent extends Object {
217
199
* Controller actions for which user validation is not required.
218
200
*
219
201
* @var array
220
- * @access public
221
202
* @see AuthComponent::allow()
222
203
* @link http://book.cakephp.org/view/1251/Setting-Auth-Component-Variables
223
204
*/
@@ -227,7 +208,6 @@ class AuthComponent extends Object {
227
208
* Maps actions to CRUD operations. Used for controller-based validation ($validate = 'controller').
228
209
*
229
210
* @var array
230
- * @access public
231
211
* @see AuthComponent::mapActions()
232
212
*/
233
213
public $ actionMap = array (
@@ -238,27 +218,33 @@ class AuthComponent extends Object {
238
218
'remove ' => 'delete '
239
219
);
240
220
221
+ /**
222
+ * Request object
223
+ *
224
+ * @var CakeRequest
225
+ */
226
+ public $ request ;
227
+
241
228
/**
242
229
* Form data from Controller::$data
243
230
*
231
+ * @deprecated Use $this->request->data instead
244
232
* @var array
245
- * @access public
246
233
*/
247
234
public $ data = array ();
248
235
249
236
/**
250
237
* Parameter data from Controller::$params
251
238
*
239
+ * @deprecated Use $this->request instead
252
240
* @var array
253
- * @access public
254
241
*/
255
242
public $ params = array ();
256
243
257
244
/**
258
245
* Method list for bound controller
259
246
*
260
247
* @var array
261
- * @access protected
262
248
*/
263
249
protected $ _methods = array ();
264
250
@@ -268,8 +254,10 @@ class AuthComponent extends Object {
268
254
* @param object $controller A reference to the instantiating controller object
269
255
* @return void
270
256
*/
271
- public function initialize (&$ controller , $ settings = array ()) {
272
- $ this ->params = $ controller ->params ;
257
+ public function initialize (Controller $ controller , $ settings = array ()) {
258
+ $ this ->request = $ controller ->request ;
259
+ $ this ->params = $ this ->request ;
260
+
273
261
$ crud = array ('create ' , 'read ' , 'update ' , 'delete ' );
274
262
$ this ->actionMap = array_merge ($ this ->actionMap , array_combine ($ crud , $ crud ));
275
263
$ this ->_methods = $ controller ->methods ;
@@ -314,7 +302,7 @@ public function startup(&$controller) {
314
302
}
315
303
316
304
$ methods = array_flip ($ controller ->methods );
317
- $ action = strtolower ($ controller ->params ['action ' ]);
305
+ $ action = strtolower ($ controller ->request -> params ['action ' ]);
318
306
$ isMissingAction = (
319
307
$ controller ->scaffold === false &&
320
308
!isset ($ methods [$ action ])
@@ -327,12 +315,13 @@ public function startup(&$controller) {
327
315
if (!$ this ->__setDefaults ()) {
328
316
return false ;
329
317
}
330
-
331
- $ this ->data = $ controller ->data = $ this ->hashPasswords ($ controller ->data );
318
+ $ request =& $ controller ->request ;
319
+
320
+ $ this ->request ->data = $ controller ->request ->data = $ this ->hashPasswords ($ request ->data );
332
321
$ url = '' ;
333
322
334
- if (isset ($ controller -> params [ ' url ' ] ['url ' ])) {
335
- $ url = $ controller -> params [ ' url ' ] ['url ' ];
323
+ if (isset ($ request -> query ['url ' ])) {
324
+ $ url = $ request -> query ['url ' ];
336
325
}
337
326
$ url = Router::normalize ($ url );
338
327
$ loginAction = Router::normalize ($ this ->loginAction );
@@ -348,20 +337,20 @@ public function startup(&$controller) {
348
337
}
349
338
350
339
if ($ loginAction == $ url ) {
351
- $ model =& $ this ->getModel ();
352
- if (empty ($ controller ->data ) || !isset ($ controller ->data [$ model ->alias ])) {
340
+ $ model = $ this ->getModel ();
341
+ if (empty ($ request ->data ) || !isset ($ request ->data [$ model ->alias ])) {
353
342
if (!$ this ->Session ->check ('Auth.redirect ' ) && !$ this ->loginRedirect && env ('HTTP_REFERER ' )) {
354
343
$ this ->Session ->write ('Auth.redirect ' , $ controller ->referer (null , true ));
355
344
}
356
345
return false ;
357
346
}
358
347
359
- $ isValid = !empty ($ controller ->data [$ model ->alias ][$ this ->fields ['username ' ]]) &&
360
- !empty ($ controller ->data [$ model ->alias ][$ this ->fields ['password ' ]]);
348
+ $ isValid = !empty ($ request ->data [$ model ->alias ][$ this ->fields ['username ' ]]) &&
349
+ !empty ($ request ->data [$ model ->alias ][$ this ->fields ['password ' ]]);
361
350
362
351
if ($ isValid ) {
363
- $ username = $ controller ->data [$ model ->alias ][$ this ->fields ['username ' ]];
364
- $ password = $ controller ->data [$ model ->alias ][$ this ->fields ['password ' ]];
352
+ $ username = $ request ->data [$ model ->alias ][$ this ->fields ['username ' ]];
353
+ $ password = $ request ->data [$ model ->alias ][$ this ->fields ['password ' ]];
365
354
366
355
$ data = array (
367
356
$ model ->alias . '. ' . $ this ->fields ['username ' ] => $ username ,
@@ -377,14 +366,14 @@ public function startup(&$controller) {
377
366
}
378
367
379
368
$ this ->Session ->setFlash ($ this ->loginError , $ this ->flashElement , array (), 'auth ' );
380
- $ controller ->data [$ model ->alias ][$ this ->fields ['password ' ]] = null ;
369
+ $ request ->data [$ model ->alias ][$ this ->fields ['password ' ]] = null ;
381
370
return false ;
382
371
} else {
383
372
if (!$ this ->user ()) {
384
373
if (!$ this ->RequestHandler ->isAjax ()) {
385
374
$ this ->Session ->setFlash ($ this ->authError , $ this ->flashElement , array (), 'auth ' );
386
- if (!empty ($ controller -> params [ ' url ' ] ) && count ($ controller -> params [ ' url ' ] ) >= 2 ) {
387
- $ query = $ controller -> params [ ' url ' ] ;
375
+ if (!empty ($ request -> query ) && count ($ request -> query ) >= 2 ) {
376
+ $ query = $ request -> query ;
388
377
unset($ query ['url ' ], $ query ['ext ' ]);
389
378
$ url .= Router::queryString ($ query , array ());
390
379
}
@@ -409,12 +398,12 @@ public function startup(&$controller) {
409
398
extract ($ this ->__authType ());
410
399
switch ($ type ) {
411
400
case 'controller ' :
412
- $ this ->object =& $ controller ;
401
+ $ this ->object = $ controller ;
413
402
break ;
414
403
case 'crud ' :
415
404
case 'actions ' :
416
405
if (isset ($ controller ->Acl )) {
417
- $ this ->Acl =& $ controller ->Acl ;
406
+ $ this ->Acl = $ controller ->Acl ;
418
407
} else {
419
408
trigger_error (__ ('Could not find AclComponent. Please include Acl in Controller::$components. ' ), E_USER_WARNING );
420
409
}
@@ -525,22 +514,22 @@ public function isAuthorized($type = null, $object = null, $user = null) {
525
514
break ;
526
515
case 'crud ' :
527
516
$ this ->mapActions ();
528
- if (!isset ($ this ->actionMap [$ this ->params ['action ' ]])) {
517
+ if (!isset ($ this ->actionMap [$ this ->request ['action ' ]])) {
529
518
trigger_error (
530
- sprintf (__ ('Auth::startup() - Attempted access of un-mapped action "%1$s" in controller "%2$s" ' ), $ this ->params ['action ' ], $ this ->params ['controller ' ]),
519
+ sprintf (__ ('Auth::startup() - Attempted access of un-mapped action "%1$s" in controller "%2$s" ' ), $ this ->request ['action ' ], $ this ->request ['controller ' ]),
531
520
E_USER_WARNING
532
521
);
533
522
} else {
534
523
$ valid = $ this ->Acl ->check (
535
524
$ user ,
536
525
$ this ->action (':controller ' ),
537
- $ this ->actionMap [$ this ->params ['action ' ]]
526
+ $ this ->actionMap [$ this ->request ['action ' ]]
538
527
);
539
528
}
540
529
break ;
541
530
case 'model ' :
542
531
$ this ->mapActions ();
543
- $ action = $ this ->params ['action ' ];
532
+ $ action = $ this ->request ['action ' ];
544
533
if (isset ($ this ->actionMap [$ action ])) {
545
534
$ action = $ this ->actionMap [$ action ];
546
535
}
@@ -717,7 +706,7 @@ public function user($key = null) {
717
706
}
718
707
719
708
if ($ key == null ) {
720
- $ model =& $ this ->getModel ();
709
+ $ model = $ this ->getModel ();
721
710
return array ($ model ->alias => $ this ->Session ->read ($ this ->sessionKey ));
722
711
} else {
723
712
$ user = $ this ->Session ->read ($ this ->sessionKey );
@@ -783,10 +772,10 @@ public function validate($object, $user = null, $action = null) {
783
772
* @link http://book.cakephp.org/view/1256/action
784
773
*/
785
774
public function action ($ action = ':plugin/:controller/:action ' ) {
786
- $ plugin = empty ($ this ->params ['plugin ' ]) ? null : Inflector::camelize ($ this ->params ['plugin ' ]) . '/ ' ;
775
+ $ plugin = empty ($ this ->request ['plugin ' ]) ? null : Inflector::camelize ($ this ->request ['plugin ' ]) . '/ ' ;
787
776
return str_replace (
788
777
array (':controller ' , ':action ' , ':plugin/ ' ),
789
- array (Inflector::camelize ($ this ->params ['controller ' ]), $ this ->params ['action ' ], $ plugin ),
778
+ array (Inflector::camelize ($ this ->request ['controller ' ]), $ this ->request ['action ' ], $ plugin ),
790
779
$ this ->actionPath . $ action
791
780
);
792
781
}
@@ -804,11 +793,7 @@ public function &getModel($name = null) {
804
793
$ name = $ this ->userModel ;
805
794
}
806
795
807
- if (PHP5 ) {
808
- $ model = ClassRegistry::init ($ name );
809
- } else {
810
- $ model =& ClassRegistry::init ($ name );
811
- }
796
+ $ model = ClassRegistry::init ($ name );
812
797
813
798
if (empty ($ model )) {
814
799
trigger_error (__ ('Auth::getModel() - Model is not set or could not be found ' ), E_USER_WARNING );
@@ -834,7 +819,7 @@ public function identify($user = null, $conditions = null) {
834
819
} else {
835
820
$ conditions = $ this ->userScope ;
836
821
}
837
- $ model =& $ this ->getModel ();
822
+ $ model = $ this ->getModel ();
838
823
if (empty ($ user )) {
839
824
$ user = $ this ->user ();
840
825
if (empty ($ user )) {
@@ -908,7 +893,7 @@ public function hashPasswords($data) {
908
893
}
909
894
910
895
if (is_array ($ data )) {
911
- $ model =& $ this ->getModel ();
896
+ $ model = $ this ->getModel ();
912
897
913
898
if (isset ($ data [$ model ->alias ])) {
914
899
if (isset ($ data [$ model ->alias ][$ this ->fields ['username ' ]]) && isset ($ data [$ model ->alias ][$ this ->fields ['password ' ]])) {
0 commit comments