We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How can i do to verified email

 public function confirmEmail()
    {
        $data = getEmail;
        $email = $data['email'];

        // Find the user in the database
        $user = Users::findFirstByEmail($email);
        if ($user) {
            return $this->response->setJsonContent(["tokenKey" => $this->security->getTokenKey(), "value" => $this->security->getToken()]);
        }
    }

but i got this error

Warning: get_object_vars() expects parameter 1 to be object, boolean given in E:\paps-lms\app\controllers\LoginController.php on line 146

What is in line 146 of your LoginController.php?

Also, put a var_dump right after the $user = Users::find.... to see that you are getting the correct object back.



537
edited Jun '19

What is in line 146 of your LoginController.php?

Also, put a var_dump right after the $user = Users::find.... to see that you are getting the correct object back.

On line 146 , this is what i want to achieve but not locally but dynamically , like this > $data['email'] = '[email protected]'; but from the db



39.3k
Accepted
answer

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


537

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

thanks for the above answer Now i have verified the email and i want to use it to reset the user password by sending a confirmation email to the user please how can i go about that with the use of codes will be very happy if you answer it .

There are very few changes you need to do for the reset password code.

You get the call from the user in your action, you generate a random password, you set the password expiration time in your database and send the email. If the request has been made in error then you ignore the new password (expiration time)

When the user clicks the link you send them to a screen where they type their new password and that is done.

Have a look at the Vokuro sample application. It has many of the concepts you need here.

thanks for the above answer Now i have verified the email and i want to use it to reset the user password by sending a confirmation email to the user please how can i go about that with the use of codes will be very happy if you answer it .