Hey..
Try this:
if ($this->User->save($this->request->data)) {
if ($this->Auth->login($this->request->data['User'])) {
$this->redirect($this->Auth->redirect());
Or you can find the user and log him in after the save:
$user = $this->User->findById($this->User->getInsertID());
if ($user) {
$this->Auth->login($user['User'])
}
-Tom
kl. 12:15:19 UTC+1 fredag 23. november 2012 skrev alex sandor følgende:
>
> Hello,
> in my opinion website usability wants me to log in my users right after
> registration. It makes no sense to force them to reenter their log in
> information after they already filled out the registration
> form successfully.
>
> public function signup() {
> if ($this->request->is('post')) {
> $this->User->create();
> if ($this->User->save($this->request->data)) {
> if ($this->Auth->login()) {
> $this->redirect($this->Auth->redirect());
> } else {
> $this->Session->setFlash(__('The user could not be saved.
> Please, try again.'));
> }
> }
> }
> In this code $this->Auth->login() just returns false. The User is saved
> correctly however.
>
> public function signup() {
> if ($this->request->is('post')) {
> $this->User->create();
> if ($this->User->save($this->request->data)) {
> if ($this->Auth->login($this->request->data)) {
> $this->redirect($this->Auth->redirect());
> } else {
> $this->Session->setFlash(__('The user could not be saved.
> Please, try again.'));
> }
> }
> }
> In this code the Auth and the Session only contains field that are also in
> $this->request->data, but not other fields of User like "id".
>
> Both examples above do not do what i want. I need ALL fields of User right
> after registration/signup, including "id" and others.
>
> My view(parsed) looks like this:
> <form action="/users/signup" class="form-horizontal" id="UserSignupForm"
> method="post" accept-charset="utf-8"><div style="display:none;"><input
> type="hidden" name="_method" value="POST"/></div>
> <label for="UserName">Name</label><input
> name="data[User][name]"maxlength="255" type="text" id="UserName"/>
> <label for="UserEmail">Email</label><input name="data[User][email]"
> maxlength="250" type="text" id="UserEmail"/>
> <label for="UserPassword">Passwort</label><input
> name="data[User][password]" type="password" id="UserPassword"/>
> <label for="UserPasswordConfirm">Passwort</label><input
> name="data[User][password_confirm]" type="password"
> id="UserPasswordConfirm"/>
> <button type="submit">Sign Up</button>
> </form>
>
> And last but not least in my AppController:
> public $components = array(
> 'Session',
> 'Auth' => array(
> 'loginRedirect' => array('controller' => 'users', 'action' =>
> 'settings'),
> 'logoutRedirect' => array('controller' => 'pages', 'action' =>
> 'display', 'home'),
> 'authenticate' => array(
> 'Form' => array(
> 'fields' => array('username' => 'email')
> )
> )
> )
> );
>
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
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].
Visit this group at http://groups.google.com/group/cake-php?hl=en.