In my app_controller I have the following

function beforeFilter() {
  ...
  if ($this->Auth->user()) {
    $this->__authExtra();
    App::import('Model', 'User');
    User::store($this->Session->read('Auth'));
  } else {
    $this->Session->del('Auth.Person');
  }
  ...
}

// The App::import ad User::store lines are linked to
http://www.pseudocoder.com/archives/2008/10/06/accessing-user-sessions-from-models-or-anywhere-in-cakephp-revealed/

function __authExtra() {
  $auth = $this->Session->read('Auth');
  $data = ClassRegistry::init('User')->find('first', array(
    'conditions' => array('User.id'=>$auth['User']['id']),
    'contain' => array('Person'=>array('PrimaryEmail.address',
'Organisation'=>array('PrimaryEmail.address')))
  ));
  $this->Session->write('Auth', Set::merge($auth, $data));
}

I have recently installed memcache and I'm beginning to work with
caching my datasets to save on queries, so my real __authExtra() looks
like

function __authExtra() {
  $auth = $this->Session->read('Auth');
  $cKey = 'data:sessionAuth:' . $auth['User']['id'];
  if(!$data = Cache::read($cKey, 'default')) {
    $data = ClassRegistry::init('User')->find('first', array(
      'conditions' => array('User.id'=>$auth['User']['id']),
      'contain' => array('Person'=>array('PrimaryEmail.address',
'Organisation'=>array('PrimaryEmail.address')))
    ));
    Cache::write($cKey, $data, 'default');
  }
  $this->Session->write('Auth', Set::merge($auth, $data));
}

Hope this felps

Paul

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to