There are a few things missing from your code that really don't help. Usually what you would do is:
- Get input from the user
- Assign the email to a variable
- Check the database for that email
- If it exists then tell the user that the email is already there - choose another one or login
- If not update the database
Now if you want them to verify that their email is correct or valid then lets assume that you send them a code 12345
. Then when they click a link it will go to an action confirmAction
. The posted data to that action would be the email and the verification code. In your action you then need to do:
// First parameter field name, 2nd filter, 3rd default value if the field does not exist
$email = $this->request->getQuery('email', 'email', '');
$code = $this->request->getQuery('code', 'string', '');
// Check the database
$user = Users::find(
[
'conditions' => 'email = :email: AND token = :token:',
'bind' => [
'email' => $email,
'token' => $token,
],
]
);
if (false === $user) {
// Inform the user that something went wrong - code does not exist or anything like that
} else {
// Correct verification - update the verification flag
$user->verified = true;
$result = $user->save();
if (false === $user) {
// Something went wrong with saving the record - throw an exception or send a message back
} else {
// Success -> you are now verified
}
}