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?