我正在尝试创建一个帐户注册页面CakePHP 2.0
,用户需要通过单击插入后收到的电子邮件中的链接来激活其新帐户username
,email
并且password
.
我的问题是如何在用户记录中设置激活码。
我想创建一个名为的表字段activation_code
,然后存储一个hashed
版本,username
以确保用户可以通过单击带有激活密钥的电子邮件链接来激活自己。
所有过程都完成了,但我不知道如何设置对象activation_code
内部,$data['User']
而且我不清楚这是 MVC 框架的一个很好的用法,还是我应该以不同的方式制作它。
在用户注册操作期间,我已完成此操作,但当我尝试动态创建“activation_code”时出现错误:
// from the UserController class
public function register () {
if (!empty($this->data)) {
if ($this->data['User']['password'] == $this->data['User']['confirm_password']) {
// here is where I get the error
$this->data['User']['activation_key'] = AuthComponent::password($this->data['User']['email']);
$this->User->create();
if ($this->User->save($this->data)) {
// private method
$this->registrationEmail ($this->data['User']['email'], $this->data['User']['username']);
$this->redirect(array('controller'=>'users', 'action'=>'registration', 'success'));
}
}
}
}
显然,这activation_key
是我的数据库中的一个空字段。
那么如何从控制器动态创建一个文件呢?