Re: Joining Data for Auth Component to read

2010-04-22 Thread cricket
See if this works.

AppController:

function beforeFilter()
{
parent::beforeFilter();

$this->Auth->fields = array(
...
);
$this->Auth->loginAction = array(
...
);

/* set the redirect for post-login
 */
$this->Auth->loginRedirect = array(
...
);

/* but tell Auth not to redirect automatically
 */
$this->Auth->autoRedirect = false;
}


public function login()
{
if ($user = $this->Auth->user())
{
if (empty($this->data))
{
$this->redirect($this->Auth->loginRedirect);
}

$this->User->Group->recursive = -1;

$this->Session->write(
'Group',
$this->User->Group->read(
null,
$this->Auth->user('group_id')
)
);

$this->redirect($this->Auth->loginRedirect);
}
}

On Apr 22, 12:47 am, capo64  wrote:
> Well basically I have over a thousand products and I'll be assigning a
> price modifier per group (ie Bronze Silver and Gold members have
> different prices for their items), so I would think the best way would
> be to check the User's Group's price_modifier when the user logs in,
> and store it in the session. Then on each of the product pages
> multiply the product price by the modifier.
>
> I just can't seem to figure out how to implement the code. I tried in
> the user controller:
>
>                 function login() {
>                         if ($this->Auth->user('id'))
>                                 $session->write('Auth.User.Group', 
> $this->User->Group->findById($this->Auth->user('group_id')));
>
>                 }
>
> But I don't think I fully understand how the login function works.
> Please let me know if this is wrong in many ways. I'm brand new to
> CakePHP :\
>
> I have an association that User belongsTo Group. There's no way to get
> Auth to use this association?
> On Apr 21, 1:19 am, thatsgreat2345  wrote:
>
>
>
> > Auth component only stores values that are in the users table, so you
> > can grab the user id using $this->Auth->user('id') and then do a find.
> > Or alternatively you can use $this->Auth->login and once if it
> > successfully logs in then do a find on the group data and store it in
> > the session for later use especially if you are going to be accessing
> > it a lot. But if you only need it in one place I'd just recommend
> > doing the find when it is needed.
>
> > On Apr 20, 5:52 pm, capo64  wrote:
>
> > > Hi I have a setup with Users and Groups.
>
> > > I've been reading user data using this in my views:
> > > $session->read('Auth.User.full_name'); ..etc
>
> > > Now I need to access information about the group of the user. How can
> > > I go about doing this?
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelpothers 
> > > 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 cake-php@googlegroups.com
> > > To unsubscribe from this group, send email to
> > > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> > > athttp://groups.google.com/group/cake-php?hl=en
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp 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 cake-php@googlegroups.com
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> > athttp://groups.google.com/group/cake-php?hl=en
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> athttp://groups.google.com/group/cake-php?hl=en

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Joining Data for Auth Component to read

2010-04-21 Thread WebbedIT
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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Joining Data for Auth Component to read

2010-04-21 Thread capo64
Well basically I have over a thousand products and I'll be assigning a
price modifier per group (ie Bronze Silver and Gold members have
different prices for their items), so I would think the best way would
be to check the User's Group's price_modifier when the user logs in,
and store it in the session. Then on each of the product pages
multiply the product price by the modifier.

I just can't seem to figure out how to implement the code. I tried in
the user controller:

function login() {
if ($this->Auth->user('id'))
$session->write('Auth.User.Group', 
$this->User->Group-
>findById($this->Auth->user('group_id')));
}

But I don't think I fully understand how the login function works.
Please let me know if this is wrong in many ways. I'm brand new to
CakePHP :\

I have an association that User belongsTo Group. There's no way to get
Auth to use this association?
On Apr 21, 1:19 am, thatsgreat2345  wrote:
> Auth component only stores values that are in the users table, so you
> can grab the user id using $this->Auth->user('id') and then do a find.
> Or alternatively you can use $this->Auth->login and once if it
> successfully logs in then do a find on the group data and store it in
> the session for later use especially if you are going to be accessing
> it a lot. But if you only need it in one place I'd just recommend
> doing the find when it is needed.
>
> On Apr 20, 5:52 pm, capo64  wrote:
>
> > Hi I have a setup with Users and Groups.
>
> > I've been reading user data using this in my views:
> > $session->read('Auth.User.full_name'); ..etc
>
> > Now I need to access information about the group of the user. How can
> > I go about doing this?
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp 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 cake-php@googlegroups.com
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> > athttp://groups.google.com/group/cake-php?hl=en
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> athttp://groups.google.com/group/cake-php?hl=en

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Joining Data for Auth Component to read

2010-04-20 Thread thatsgreat2345
Auth component only stores values that are in the users table, so you
can grab the user id using $this->Auth->user('id') and then do a find.
Or alternatively you can use $this->Auth->login and once if it
successfully logs in then do a find on the group data and store it in
the session for later use especially if you are going to be accessing
it a lot. But if you only need it in one place I'd just recommend
doing the find when it is needed.

On Apr 20, 5:52 pm, capo64  wrote:
> Hi I have a setup with Users and Groups.
>
> I've been reading user data using this in my views:
> $session->read('Auth.User.full_name'); ..etc
>
> Now I need to access information about the group of the user. How can
> I go about doing this?
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> athttp://groups.google.com/group/cake-php?hl=en

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Joining Data for Auth Component to read

2010-04-20 Thread capo64
Hi I have a setup with Users and Groups.

I've been reading user data using this in my views:
$session->read('Auth.User.full_name'); ..etc

Now I need to access information about the group of the user. How can
I go about doing this?

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en