帐户激活的最佳方式
我正在尝试使用 CakePHP 2.0
创建一个帐户注册页面,用户需要通过单击插入用户名
后收到的电子邮件中的链接来激活其新帐户,<代码>电子邮件和密码
。
我的问题是如何在用户记录中设置激活码。
我想创建一个名为 activation_code
的表字段,然后存储 用户名
的散列
版本,以确保用户可以通过单击激活自己带有激活密钥的电子邮件链接。
所有过程均已完成,但我不知道如何在 $data['User']
对象内设置 activation_code
并且我不清楚这是否是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
是我数据库中的空字段。
那么如何从控制器动态创建一个字段呢?
I'm trying to create an account register page with CakePHP 2.0
where user needs to activate it's new account by clicking on a link in the email he's received after insert username
, email
and password
.
My question is how can I set an activation code inside the user record.
I thought to create a table field named activation_code
and then to store an hashed
version of the username
to be sure the user can activate itself by clicking the email link with the activation key.
All the procedure is done but I don't know how can I set the activation_code
inside the $data['User']
object and It's not clear for me if this is a good usage of the MVC framework or I should make it in a different way.
During the user registration action I've done this but I get an error when I try to create 'activation_code' dynamically:
// 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'));
}
}
}
}
Obviously the activation_key
is an empty field inside my database.
So how can I create a filed dynamically from the controller?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经用 Model::set() 方法解决了这个问题,所以:
I've solved the problem with the method
Model::set()
, so:应该是:(
您应该将所有对 $this->data 的引用更改为新的 cakephp2.0 $this->request->data)
should be:
(You should change all references to $this->data to the new cakephp2.0 $this->request->data)