AuthComponent.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. <?php
  2. /**
  3. * Authentication component
  4. *
  5. * Manages user logins and permissions.
  6. *
  7. * PHP 5
  8. *
  9. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  10. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. *
  12. * Licensed under The MIT License
  13. * Redistributions of files must retain the above copyright notice.
  14. *
  15. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  16. * @link http://cakephp.org CakePHP(tm) Project
  17. * @package Cake.Controller.Component
  18. * @since CakePHP(tm) v 0.10.0.1076
  19. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  20. */
  21. App::uses('Component', 'Controller');
  22. App::uses('Router', 'Routing');
  23. App::uses('Security', 'Utility');
  24. App::uses('Debugger', 'Utility');
  25. App::uses('Hash', 'Utility');
  26. App::uses('CakeSession', 'Model/Datasource');
  27. App::uses('BaseAuthorize', 'Controller/Component/Auth');
  28. App::uses('BaseAuthenticate', 'Controller/Component/Auth');
  29. /**
  30. * Authentication control component class
  31. *
  32. * Binds access control with user authentication and session management.
  33. *
  34. * @package Cake.Controller.Component
  35. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html
  36. */
  37. class AuthComponent extends Component {
  38. const ALL = 'all';
  39. /**
  40. * Other components utilized by AuthComponent
  41. *
  42. * @var array
  43. */
  44. public $components = array('Session', 'RequestHandler');
  45. /**
  46. * An array of authentication objects to use for authenticating users. You can configure
  47. * multiple adapters and they will be checked sequentially when users are identified.
  48. *
  49. * {{{
  50. * $this->Auth->authenticate = array(
  51. * 'Form' => array(
  52. * 'userModel' => 'Users.User'
  53. * )
  54. * );
  55. * }}}
  56. *
  57. * Using the class name without 'Authenticate' as the key, you can pass in an array of settings for each
  58. * authentication object. Additionally you can define settings that should be set to all authentications objects
  59. * using the 'all' key:
  60. *
  61. * {{{
  62. * $this->Auth->authenticate = array(
  63. * 'all' => array(
  64. * 'userModel' => 'Users.User',
  65. * 'scope' => array('User.active' => 1)
  66. * ),
  67. * 'Form',
  68. * 'Basic'
  69. * );
  70. * }}}
  71. *
  72. * You can also use AuthComponent::ALL instead of the string 'all'.
  73. *
  74. * @var array
  75. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html
  76. */
  77. public $authenticate = array('Form');
  78. /**
  79. * Objects that will be used for authentication checks.
  80. *
  81. * @var array
  82. */
  83. protected $_authenticateObjects = array();
  84. /**
  85. * An array of authorization objects to use for authorizing users. You can configure
  86. * multiple adapters and they will be checked sequentially when authorization checks are done.
  87. *
  88. * {{{
  89. * $this->Auth->authorize = array(
  90. * 'Crud' => array(
  91. * 'actionPath' => 'controllers/'
  92. * )
  93. * );
  94. * }}}
  95. *
  96. * Using the class name without 'Authorize' as the key, you can pass in an array of settings for each
  97. * authorization object. Additionally you can define settings that should be set to all authorization objects
  98. * using the 'all' key:
  99. *
  100. * {{{
  101. * $this->Auth->authorize = array(
  102. * 'all' => array(
  103. * 'actionPath' => 'controllers/'
  104. * ),
  105. * 'Crud',
  106. * 'CustomAuth'
  107. * );
  108. * }}}
  109. *
  110. * You can also use AuthComponent::ALL instead of the string 'all'
  111. *
  112. * @var mixed
  113. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#authorization
  114. */
  115. public $authorize = false;
  116. /**
  117. * Objects that will be used for authorization checks.
  118. *
  119. * @var array
  120. */
  121. protected $_authorizeObjects = array();
  122. /**
  123. * The name of an optional view element to render when an Ajax request is made
  124. * with an invalid or expired session
  125. *
  126. * @var string
  127. */
  128. public $ajaxLogin = null;
  129. /**
  130. * Settings to use when Auth needs to do a flash message with SessionComponent::setFlash().
  131. * Available keys are:
  132. *
  133. * - `element` - The element to use, defaults to 'default'.
  134. * - `key` - The key to use, defaults to 'auth'
  135. * - `params` - The array of additional params to use, defaults to array()
  136. *
  137. * @var array
  138. */
  139. public $flash = array(
  140. 'element' => 'default',
  141. 'key' => 'auth',
  142. 'params' => array()
  143. );
  144. /**
  145. * The session key name where the record of the current user is stored. If
  146. * unspecified, it will be "Auth.User".
  147. *
  148. * @var string
  149. */
  150. public static $sessionKey = 'Auth.User';
  151. /**
  152. * The current user, used for stateless authentication when
  153. * sessions are not available.
  154. *
  155. * @var array
  156. */
  157. protected static $_user = array();
  158. /**
  159. * A URL (defined as a string or array) to the controller action that handles
  160. * logins. Defaults to `/users/login`
  161. *
  162. * @var mixed
  163. */
  164. public $loginAction = array(
  165. 'controller' => 'users',
  166. 'action' => 'login',
  167. 'plugin' => null
  168. );
  169. /**
  170. * Normally, if a user is redirected to the $loginAction page, the location they
  171. * were redirected from will be stored in the session so that they can be
  172. * redirected back after a successful login. If this session value is not
  173. * set, the user will be redirected to the page specified in $loginRedirect.
  174. *
  175. * @var mixed
  176. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#AuthComponent::$loginRedirect
  177. */
  178. public $loginRedirect = null;
  179. /**
  180. * The default action to redirect to after the user is logged out. While AuthComponent does
  181. * not handle post-logout redirection, a redirect URL will be returned from AuthComponent::logout().
  182. * Defaults to AuthComponent::$loginAction.
  183. *
  184. * @var mixed
  185. * @see AuthComponent::$loginAction
  186. * @see AuthComponent::logout()
  187. */
  188. public $logoutRedirect = null;
  189. /**
  190. * Error to display when user attempts to access an object or action to which they do not have
  191. * access.
  192. *
  193. * @var string
  194. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#AuthComponent::$authError
  195. */
  196. public $authError = null;
  197. /**
  198. * Controller actions for which user validation is not required.
  199. *
  200. * @var array
  201. * @see AuthComponent::allow()
  202. */
  203. public $allowedActions = array();
  204. /**
  205. * Request object
  206. *
  207. * @var CakeRequest
  208. */
  209. public $request;
  210. /**
  211. * Response object
  212. *
  213. * @var CakeResponse
  214. */
  215. public $response;
  216. /**
  217. * Method list for bound controller
  218. *
  219. * @var array
  220. */
  221. protected $_methods = array();
  222. /**
  223. * Initializes AuthComponent for use in the controller
  224. *
  225. * @param Controller $controller A reference to the instantiating controller object
  226. * @return void
  227. */
  228. public function initialize(Controller $controller) {
  229. $this->request = $controller->request;
  230. $this->response = $controller->response;
  231. $this->_methods = $controller->methods;
  232. if (Configure::read('debug') > 0) {
  233. Debugger::checkSecurityKeys();
  234. }
  235. }
  236. /**
  237. * Main execution method. Handles redirecting of invalid users, and processing
  238. * of login form data.
  239. *
  240. * @param Controller $controller A reference to the instantiating controller object
  241. * @return boolean
  242. */
  243. public function startup(Controller $controller) {
  244. $methods = array_flip(array_map('strtolower', $controller->methods));
  245. $action = strtolower($controller->request->params['action']);
  246. $isMissingAction = (
  247. $controller->scaffold === false &&
  248. !isset($methods[$action])
  249. );
  250. if ($isMissingAction) {
  251. return true;
  252. }
  253. if (!$this->_setDefaults()) {
  254. return false;
  255. }
  256. $request = $controller->request;
  257. $url = '';
  258. if (isset($request->url)) {
  259. $url = $request->url;
  260. }
  261. $url = Router::normalize($url);
  262. $loginAction = Router::normalize($this->loginAction);
  263. if ($loginAction != $url && in_array($action, array_map('strtolower', $this->allowedActions))) {
  264. return true;
  265. }
  266. if ($loginAction == $url) {
  267. if (empty($request->data)) {
  268. if (!$this->Session->check('Auth.redirect') && !$this->loginRedirect && env('HTTP_REFERER')) {
  269. $this->Session->write('Auth.redirect', $controller->referer(null, true));
  270. }
  271. }
  272. return true;
  273. } else {
  274. if (!$this->_getUser()) {
  275. if (!$request->is('ajax')) {
  276. $this->flash($this->authError);
  277. $this->Session->write('Auth.redirect', $request->here());
  278. $controller->redirect($loginAction);
  279. return false;
  280. } elseif (!empty($this->ajaxLogin)) {
  281. $controller->viewPath = 'Elements';
  282. echo $controller->render($this->ajaxLogin, $this->RequestHandler->ajaxLayout);
  283. $this->_stop();
  284. return false;
  285. } else {
  286. $controller->redirect(null, 403);
  287. }
  288. }
  289. }
  290. if (empty($this->authorize) || $this->isAuthorized($this->user())) {
  291. return true;
  292. }
  293. $this->flash($this->authError);
  294. $default = '/';
  295. if (!empty($this->loginRedirect)) {
  296. $default = $this->loginRedirect;
  297. }
  298. $controller->redirect($controller->referer($default), null, true);
  299. return false;
  300. }
  301. /**
  302. * Attempts to introspect the correct values for object properties.
  303. *
  304. * @return boolean
  305. */
  306. protected function _setDefaults() {
  307. $defaults = array(
  308. 'logoutRedirect' => $this->loginAction,
  309. 'authError' => __d('cake', 'You are not authorized to access that location.')
  310. );
  311. foreach ($defaults as $key => $value) {
  312. if (empty($this->{$key})) {
  313. $this->{$key} = $value;
  314. }
  315. }
  316. return true;
  317. }
  318. /**
  319. * Uses the configured Authorization adapters to check whether or not a user is authorized.
  320. * Each adapter will be checked in sequence, if any of them return true, then the user will
  321. * be authorized for the request.
  322. *
  323. * @param array $user The user to check the authorization of. If empty the user in the session will be used.
  324. * @param CakeRequest $request The request to authenticate for. If empty, the current request will be used.
  325. * @return boolean True if $user is authorized, otherwise false
  326. */
  327. public function isAuthorized($user = null, $request = null) {
  328. if (empty($user) && !$this->user()) {
  329. return false;
  330. } elseif (empty($user)) {
  331. $user = $this->user();
  332. }
  333. if (empty($request)) {
  334. $request = $this->request;
  335. }
  336. if (empty($this->_authorizeObjects)) {
  337. $this->constructAuthorize();
  338. }
  339. foreach ($this->_authorizeObjects as $authorizer) {
  340. if ($authorizer->authorize($user, $request) === true) {
  341. return true;
  342. }
  343. }
  344. return false;
  345. }
  346. /**
  347. * Loads the authorization objects configured.
  348. *
  349. * @return mixed Either null when authorize is empty, or the loaded authorization objects.
  350. * @throws CakeException
  351. */
  352. public function constructAuthorize() {
  353. if (empty($this->authorize)) {
  354. return;
  355. }
  356. $this->_authorizeObjects = array();
  357. $config = Hash::normalize((array)$this->authorize);
  358. $global = array();
  359. if (isset($config[AuthComponent::ALL])) {
  360. $global = $config[AuthComponent::ALL];
  361. unset($config[AuthComponent::ALL]);
  362. }
  363. foreach ($config as $class => $settings) {
  364. list($plugin, $class) = pluginSplit($class, true);
  365. $className = $class . 'Authorize';
  366. App::uses($className, $plugin . 'Controller/Component/Auth');
  367. if (!class_exists($className)) {
  368. throw new CakeException(__d('cake_dev', 'Authorization adapter "%s" was not found.', $class));
  369. }
  370. if (!method_exists($className, 'authorize')) {
  371. throw new CakeException(__d('cake_dev', 'Authorization objects must implement an authorize method.'));
  372. }
  373. $settings = array_merge($global, (array)$settings);
  374. $this->_authorizeObjects[] = new $className($this->_Collection, $settings);
  375. }
  376. return $this->_authorizeObjects;
  377. }
  378. /**
  379. * Takes a list of actions in the current controller for which authentication is not required, or
  380. * no parameters to allow all actions.
  381. *
  382. * You can use allow with either an array, or var args.
  383. *
  384. * `$this->Auth->allow(array('edit', 'add'));` or
  385. * `$this->Auth->allow('edit', 'add');` or
  386. * `$this->Auth->allow();` to allow all actions
  387. *
  388. * @param string|array $action,... Controller action name or array of actions
  389. * @return void
  390. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#making-actions-public
  391. */
  392. public function allow($action = null) {
  393. $args = func_get_args();
  394. if (empty($args) || $action === null) {
  395. $this->allowedActions = $this->_methods;
  396. } else {
  397. if (isset($args[0]) && is_array($args[0])) {
  398. $args = $args[0];
  399. }
  400. $this->allowedActions = array_merge($this->allowedActions, $args);
  401. }
  402. }
  403. /**
  404. * Removes items from the list of allowed/no authentication required actions.
  405. *
  406. * You can use deny with either an array, or var args.
  407. *
  408. * `$this->Auth->deny(array('edit', 'add'));` or
  409. * `$this->Auth->deny('edit', 'add');` or
  410. * `$this->Auth->deny();` to remove all items from the allowed list
  411. *
  412. * @param string|array $action,... Controller action name or array of actions
  413. * @return void
  414. * @see AuthComponent::allow()
  415. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#making-actions-require-authorization
  416. */
  417. public function deny($action = null) {
  418. $args = func_get_args();
  419. if (empty($args) || $action === null) {
  420. $this->allowedActions = array();
  421. } else {
  422. if (isset($args[0]) && is_array($args[0])) {
  423. $args = $args[0];
  424. }
  425. foreach ($args as $arg) {
  426. $i = array_search($arg, $this->allowedActions);
  427. if (is_int($i)) {
  428. unset($this->allowedActions[$i]);
  429. }
  430. }
  431. $this->allowedActions = array_values($this->allowedActions);
  432. }
  433. }
  434. /**
  435. * Maps action names to CRUD operations. Used for controller-based authentication. Make sure
  436. * to configure the authorize property before calling this method. As it delegates $map to all the
  437. * attached authorize objects.
  438. *
  439. * @param array $map Actions to map
  440. * @return void
  441. * @see BaseAuthorize::mapActions()
  442. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#mapping-actions-when-using-crudauthorize
  443. */
  444. public function mapActions($map = array()) {
  445. if (empty($this->_authorizeObjects)) {
  446. $this->constructAuthorize();
  447. }
  448. foreach ($this->_authorizeObjects as $auth) {
  449. $auth->mapActions($map);
  450. }
  451. }
  452. /**
  453. * Log a user in. If a $user is provided that data will be stored as the logged in user. If `$user` is empty or not
  454. * specified, the request will be used to identify a user. If the identification was successful,
  455. * the user record is written to the session key specified in AuthComponent::$sessionKey. Logging in
  456. * will also change the session id in order to help mitigate session replays.
  457. *
  458. * @param array $user Either an array of user data, or null to identify a user using the current request.
  459. * @return boolean True on login success, false on failure
  460. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#identifying-users-and-logging-them-in
  461. */
  462. public function login($user = null) {
  463. $this->_setDefaults();
  464. if (empty($user)) {
  465. $user = $this->identify($this->request, $this->response);
  466. }
  467. if ($user) {
  468. $this->Session->renew();
  469. $this->Session->write(self::$sessionKey, $user);
  470. }
  471. return $this->loggedIn();
  472. }
  473. /**
  474. * Logs a user out, and returns the login action to redirect to.
  475. * Triggers the logout() method of all the authenticate objects, so they can perform
  476. * custom logout logic. AuthComponent will remove the session data, so
  477. * there is no need to do that in an authentication object. Logging out
  478. * will also renew the session id. This helps mitigate issues with session replays.
  479. *
  480. * @return string AuthComponent::$logoutRedirect
  481. * @see AuthComponent::$logoutRedirect
  482. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#logging-users-out
  483. */
  484. public function logout() {
  485. $this->_setDefaults();
  486. if (empty($this->_authenticateObjects)) {
  487. $this->constructAuthenticate();
  488. }
  489. $user = $this->user();
  490. foreach ($this->_authenticateObjects as $auth) {
  491. $auth->logout($user);
  492. }
  493. $this->Session->delete(self::$sessionKey);
  494. $this->Session->delete('Auth.redirect');
  495. $this->Session->renew();
  496. return Router::normalize($this->logoutRedirect);
  497. }
  498. /**
  499. * Get the current user.
  500. *
  501. * Will prefer the static user cache over sessions. The static user
  502. * cache is primarily used for stateless authentication. For stateful authentication,
  503. * cookies + sessions will be used.
  504. *
  505. * @param string $key field to retrieve. Leave null to get entire User record
  506. * @return mixed User record. or null if no user is logged in.
  507. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#accessing-the-logged-in-user
  508. */
  509. public static function user($key = null) {
  510. if (empty(self::$_user) && !CakeSession::check(self::$sessionKey)) {
  511. return null;
  512. }
  513. if (!empty(self::$_user)) {
  514. $user = self::$_user;
  515. } else {
  516. $user = CakeSession::read(self::$sessionKey);
  517. }
  518. if ($key === null) {
  519. return $user;
  520. }
  521. return Hash::get($user, $key);
  522. }
  523. /**
  524. * Similar to AuthComponent::user() except if the session user cannot be found, connected authentication
  525. * objects will have their getUser() methods called. This lets stateless authentication methods function correctly.
  526. *
  527. * @return boolean true if a user can be found, false if one cannot.
  528. */
  529. protected function _getUser() {
  530. $user = $this->user();
  531. if ($user) {
  532. return true;
  533. }
  534. if (empty($this->_authenticateObjects)) {
  535. $this->constructAuthenticate();
  536. }
  537. foreach ($this->_authenticateObjects as $auth) {
  538. $result = $auth->getUser($this->request);
  539. if (!empty($result) && is_array($result)) {
  540. self::$_user = $result;
  541. return true;
  542. }
  543. }
  544. return false;
  545. }
  546. /**
  547. * If no parameter is passed, gets the authentication redirect URL. Pass a url in to
  548. * set the destination a user should be redirected to upon logging in. Will fallback to
  549. * AuthComponent::$loginRedirect if there is no stored redirect value.
  550. *
  551. * @param string|array $url Optional URL to write as the login redirect URL.
  552. * @return string Redirect URL
  553. */
  554. public function redirect($url = null) {
  555. if (!is_null($url)) {
  556. $redir = $url;
  557. $this->Session->write('Auth.redirect', $redir);
  558. } elseif ($this->Session->check('Auth.redirect')) {
  559. $redir = $this->Session->read('Auth.redirect');
  560. $this->Session->delete('Auth.redirect');
  561. if (Router::normalize($redir) == Router::normalize($this->loginAction)) {
  562. $redir = $this->loginRedirect;
  563. }
  564. } else {
  565. $redir = $this->loginRedirect;
  566. }
  567. return Router::normalize($redir);
  568. }
  569. /**
  570. * Use the configured authentication adapters, and attempt to identify the user
  571. * by credentials contained in $request.
  572. *
  573. * @param CakeRequest $request The request that contains authentication data.
  574. * @param CakeResponse $response The response
  575. * @return array User record data, or false, if the user could not be identified.
  576. */
  577. public function identify(CakeRequest $request, CakeResponse $response) {
  578. if (empty($this->_authenticateObjects)) {
  579. $this->constructAuthenticate();
  580. }
  581. foreach ($this->_authenticateObjects as $auth) {
  582. $result = $auth->authenticate($request, $response);
  583. if (!empty($result) && is_array($result)) {
  584. return $result;
  585. }
  586. }
  587. return false;
  588. }
  589. /**
  590. * loads the configured authentication objects.
  591. *
  592. * @return mixed either null on empty authenticate value, or an array of loaded objects.
  593. * @throws CakeException
  594. */
  595. public function constructAuthenticate() {
  596. if (empty($this->authenticate)) {
  597. return;
  598. }
  599. $this->_authenticateObjects = array();
  600. $config = Hash::normalize((array)$this->authenticate);
  601. $global = array();
  602. if (isset($config[AuthComponent::ALL])) {
  603. $global = $config[AuthComponent::ALL];
  604. unset($config[AuthComponent::ALL]);
  605. }
  606. foreach ($config as $class => $settings) {
  607. list($plugin, $class) = pluginSplit($class, true);
  608. $className = $class . 'Authenticate';
  609. App::uses($className, $plugin . 'Controller/Component/Auth');
  610. if (!class_exists($className)) {
  611. throw new CakeException(__d('cake_dev', 'Authentication adapter "%s" was not found.', $class));
  612. }
  613. if (!method_exists($className, 'authenticate')) {
  614. throw new CakeException(__d('cake_dev', 'Authentication objects must implement an authenticate method.'));
  615. }
  616. $settings = array_merge($global, (array)$settings);
  617. $this->_authenticateObjects[] = new $className($this->_Collection, $settings);
  618. }
  619. return $this->_authenticateObjects;
  620. }
  621. /**
  622. * Hash a password with the application's salt value (as defined with Configure::write('Security.salt');
  623. *
  624. * This method is intended as a convenience wrapper for Security::hash(). If you want to use
  625. * a hashing/encryption system not supported by that method, do not use this method.
  626. *
  627. * @param string $password Password to hash
  628. * @return string Hashed password
  629. * @link http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#hashing-passwords
  630. */
  631. public static function password($password) {
  632. return Security::hash($password, null, true);
  633. }
  634. /**
  635. * Component shutdown. If user is logged in, wipe out redirect.
  636. *
  637. * @param Controller $controller Instantiating controller
  638. * @return void
  639. */
  640. public function shutdown(Controller $controller) {
  641. if ($this->loggedIn()) {
  642. $this->Session->delete('Auth.redirect');
  643. }
  644. }
  645. /**
  646. * Check whether or not the current user has data in the session, and is considered logged in.
  647. *
  648. * @return boolean true if the user is logged in, false otherwise
  649. */
  650. public function loggedIn() {
  651. return $this->user() != array();
  652. }
  653. /**
  654. * Set a flash message. Uses the Session component, and values from AuthComponent::$flash.
  655. *
  656. * @param string $message The message to set.
  657. * @return void
  658. */
  659. public function flash($message) {
  660. $this->Session->setFlash($message, $this->flash['element'], $this->flash['params'], $this->flash['key']);
  661. }
  662. }