gpt4 book ai didi

php - CakePHP Auth 组件不反射(reflect)用户数据的更改

转载 作者:行者123 更新时间:2023-12-03 20:17:29 27 4
gpt4 key购买 nike

当我试图实现以下目标时:

  1. 用户更改电子邮件
  2. 用户收到验证邮件
  3. 用户激活更改后的电子邮件。

我这样做的方法如下:

<?php
echo $form->create('User', array('action' => 'changeEmail'));
echo $form->input('email');
echo $form->end('Change');
?>

然后是我的 Controller

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
}
}

然后我看到他们可以在其中激活电子邮件的 View ,然后执行以下操作:

function activate(){
$user = $this->Auth->user();

//Now this variable doesn't reflect the changes we've just saved (for example the activationCode)
}

这是有意的行为还是我在这里做错了什么。

最佳答案

AuthComponent 在 session 中缓存用户数据。直到用户再次登录后,此数据才会刷新。您可以显式覆盖 session 中的数据:

$this->Session->write('Auth.User', $user);

或者重新验证用户身份,这应该会提示刷新(如果这真的有效的话,我并不能 100% 确定):

$this->Auth->login($this->Auth->user('id'));

关于php - CakePHP Auth 组件不反射(reflect)用户数据的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6464624/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com