Hello everybody,
I need only a light user account : username and password is enough. So
I don't want a login page and a sign in page. If the user login with a
new username, I have to register and automatically login the user with
the new account. Is it possible with Auth ?
At the moment, I register successfully the user if the username is
available, but the login no more works...
Here my view
<?php
echo $this->Session->flash('auth');
echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $form->input('remember_me', array('label' => 'Remember me',
'type' => 'checkbox'));
echo $this->Form->end('Login');
?>
Here my UsersController
function beforeFilter() {
parent::beforeFilter(); // contains $this->Auth->autoRedirect =
false;
if(isset($this->data['User']['password'])) {
// save the password because it will be erased by Auth (?)
$this->password_for_reg = $this->data['User']['password'];
}
}
public function login() {
if ($this->Auth->user()) {
if (!empty($this->data['User']['remember_me'])) {
// ...create the cookie...
}
$this->redirect($this->Auth->redirect());
}
if (empty($this->data)) {
// ... read the cookie...
} else {
// Here the login fallback!
$user_in_db = $this->User->findByUsername($this->data['User']
['username']);
if(! $user_in_db) {
// Ok, the username is available
$this->data['User']['password'] = $this->Auth->password($this-
>data['User']['password']);
$this->User->save($this->data);
unset($this->data['User']['password']);
// ...redirection...
} else {
// the username is already used and the password is wrong
}
}
}
Thank you for any help!
--
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
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php