Tim*_*sen 2 php authentication cakephp
当我试图实现以下目标时:
我这样做的方式如下:
<?php
echo $form->create('User', array('action' => 'changeEmail'));
echo $form->input('email');
echo $form->end('Change');
?>
Run Code Online (Sandbox Code Playgroud)
然后我的控制器
function changeEmail(){
if(!empty($this->data)){
$user = $this->Auth->user();
$user['User']['email'] = $this->data['User']['email'];
$activationcode = _generateActivationCode();
$user['User']['activationcode'] = $activationcode;
$user['User']['isactive'] = false;
if($this->User->save($user)){
//sendmail
}
}
Run Code Online (Sandbox Code Playgroud)
然后我得到一个他们可以激活电子邮件的视图,我执行以下操作:
function activate(){
$user = $this->Auth->user();
//Now this variable doesn't reflect the changes we've just saved (for example the activationCode)
}
Run Code Online (Sandbox Code Playgroud)
这是预期的行为还是我在这里做错了什么.
AuthComponent在会话中缓存用户数据.在用户再次登录之前,不会刷新此数据.您可以显式覆盖会话中的数据:
$this->Session->write('Auth.User', $user);
Run Code Online (Sandbox Code Playgroud)
或者重新验证用户,这应该提示刷新(如果这确实有效,则不是100%确定我的头顶):
$this->Auth->login($this->Auth->user('id'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1084 次 |
| 最近记录: |