Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated to work with 2.1

  • Loading branch information...
commit 7c76da66c5ec5af04941d971fe697fbaab9618ea 1 parent 8911f69
Richard S authored
43 controllers/components/stay_out.php → Controller/Component/StayOutComponent.php
@@ -7,7 +7,7 @@
7 7 *
8 8 **/
9 9
10   -class StayOutComponent extends Object {
  10 +class StayOutComponent extends Component {
11 11
12 12 /**
13 13 * Include the neccessary components for StayOut to function with
@@ -19,12 +19,12 @@ class StayOutComponent extends Object {
19 19 * @param array $settings overrides default settings for fieldnames
20 20 * @return false
21 21 */
22   - function initialize(&$Controller, $settings = array()) {
  22 + function initialize($Controller, $settings = array()) {
23 23 $defaults = array(
24 24 'logout_field' => 'logged_out',
25 25 'cache' => false,
26 26 );
27   - $this->Controller = &$Controller;
  27 + $this->Controller = $Controller;
28 28 $this->settings = array_merge($defaults, $settings);
29 29 }
30 30
@@ -37,11 +37,34 @@ public function generateHash() {
37 37 }
38 38
39 39 /**
  40 + * initializeModel method loads the required model if not previously loaded
  41 + * @return false
  42 + */
  43 + private function __initializeModel() {
  44 + if (!isset($this->userModel)) {
  45 + $userModel = '';
  46 + foreach ($this->Auth->authenticate as $adapter) {
  47 + if (is_array($adapter) && !empty($adapter['userModel'])) {
  48 + $userModel = $adapter['userModel'];
  49 + break;
  50 + }
  51 + }
  52 +
  53 + if (empty($userModel)) {
  54 + die('Please specify what user model to authenticate against');
  55 + }
  56 +
  57 + App::import('Model', $userModel);
  58 + $this->userModel = new $userModel;
  59 + }
  60 + }
  61 +
  62 +/**
40 63 * startup Called after beforeFilter
41 64 * @return false
42 65 */
43 66 function startup() {
44   - $this->initializeModel();
  67 + $this->__initializeModel();
45 68 if ($this->tableSupports('logout_field') && $this->Auth->user()) {
46 69
47 70 if (!empty($this->Controller->data[$this->Auth->userModel]) && !$this->Auth->user($this->settings['logout_field'])) {
@@ -86,23 +109,11 @@ function startup() {
86 109 }
87 110
88 111 /**
89   - * initializeModel method loads the required model if not previously loaded
90   - * @return false
91   - */
92   - private function initializeModel() {
93   - if (!isset($this->userModel)) {
94   - App::import('Model', $this->Auth->userModel);
95   - $this->userModel = new $this->Auth->userModel();
96   - }
97   - }
98   -
99   -/**
100 112 * tableSupports checks to see whether or not the current setup supports tracking logouts
101 113 * @param type specifies which field & setting is functional
102 114 * @return bool
103 115 */
104 116 protected function tableSupports($type = '') {
105   - $this->initializeModel();
106 117 if (@$this->userModel->schema($this->settings[$type]) && !empty($this->settings[$type])) {
107 118 return true;
108 119 }

0 comments on commit 7c76da6

Please sign in to comment.
Something went wrong with that request. Please try again.