session - CakePHP 2.0 Automatic Login after Account Activation -
i'm working on user management-component of our new project. plan is:
- user registers on page minimal amount of account data (username, pass, email)
- user gets email activation link activate account
- user clicks on link , activates account
- the system logs in user after automatically after activation , redirects him kind of dashboard account information (last login, hi "username", etc.)
but there problems auto login. part of code use:
<?php ... // set userstatus "active" , delete meta information "activation_key" // automatically login $this->user->id = $id; $this->user->savefield('modified', date('y-m-d h:i:s') ); $this->user->savefield('status', 1 ); // $this->user->deleteactivationkey .... $this->auth->login($this->user->read()); $this->session->setflash(__('successfully activated account. logged in.')); $this->user->savefield('last_login', date('y-m-d h:i:s') ); $this->redirect(array('controller' => 'pages')); ...
this works far, until want information logged in user user() function of auth component.
we're using in appcontroller->beforerender, have user information application wide:
$this->set('auth', $this->auth->user());
but after auto login action, i'm getting undefined index notices. (e.g. accessing $auth['id'] in view). print_r() shows me username , hashed password of current user. if login manually, works fine. must automatic login after account activation.
seems problem session? doing wrong?
found solution after testing many variations.
works with:
$user = $this->user->findbyid($id); $user = $user['user']; $this->auth->login($user);
don't know why, thought tried way , did not work.
Comments
Post a Comment