to help me understand where I'm going wrong. I should say first that I
have read the manual and bought a couple of the books but i'm totally
new to cakephp and still learning php.
I want to be able to log a user in when they are registering. Normally
this would be easy enough, but because I happen to have my register
and login forms on the same page I have to create the form as
<?php echo $this->Form->create('RegUser',
array('url'=>array('controller'=>'users', 'action'=>'add')));?>
Note: the RegUser instead of just User as the model. I then have a
blank RegUser model file which extends the User model.
This seems to be creating problems for me with first the hashing of
the password, now I have to do it manually because the auth component
likes the table/model to be User. Secondly logging in a user during
registration seems problematic, I assume it's something to do with me
using RegUser model too.
If anyone fancies looking at the following action and describing whats
buggered up about it I'm be extremely grateful.
Thanks in advance
function add() {
if (!empty($this->data)) {
$this->loadModel('RegUser');
if (!empty($this->data['RegUser']['password'])) {
$logdetails = $this->RegUser->read();
$this->data['RegUser']['password'] = $this->Auth->password($this-
>data['RegUser']['password']);
}
$this->data['RegUser']['password2hashed'] = $this->Auth-
>password($this->data['RegUser']['password2']);
$this->RegUser->create();
if ($this->RegUser->save($this->data)) {
$this->Auth->login($logdetails);
//write some user info to session
$firstlast = $this->data['RegUser']['first_name'] . '_' . $this-
>data['RegUser']['last_name'];
$this->Session->write('user.email', $this->data['RegUser']
['email']);
$this->Session->write('user.name', $firstlast);
$this->redirect(array('controller'=>'pages', 'action' => 'hello'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please,
try again.', true));
$this->data['RegUser']['password'] = '';
$this->data['RegUser']['password2'] = '';
$this->render('/pages/signup');
}
}
}
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
No comments:
Post a Comment