Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过电子邮件地址和身份验证密钥进行用户身份验证_Php_Email_Authentication_Yii2 - Fatal编程技术网

Php 通过电子邮件地址和身份验证密钥进行用户身份验证

Php 通过电子邮件地址和身份验证密钥进行用户身份验证,php,email,authentication,yii2,Php,Email,Authentication,Yii2,我尝试在使用authkey属性注册后发送电子邮件。但是我对用户的这个authkey有问题。我不知道为什么在发送此电子邮件之前不保存此邮件。这是我在注册表中的代码: public function getSetPasswordLink() { $user = User::findOne([ 'status' => User::STATUS_DELETED, 'email' => $this-

我尝试在使用authkey属性注册后发送电子邮件。但是我对用户的这个authkey有问题。我不知道为什么在发送此电子邮件之前不保存此邮件。这是我在注册表中的代码:

 public function getSetPasswordLink() {
       $user = User::findOne([
                    'status' => User::STATUS_DELETED,
                    'email' => $this->email,

        ]);
        var_dump($user['auth_key']);
        exit();
        return Url::to(['registration/confirm', 'email' => $this->email, 'authkey' => $user['auth_key']], true);
    }

    public function sendEmail() {

        $status = Yii::$app->mailer->compose('registrationmail',['url' => $this->getSetPasswordLink()])
                ->setTo($this->email)
                ->setCharset('utf8')
                ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->params['supportEmail']])
                ->setSubject(self::SUBJECT)
                ->send();

        return $status;
    }
这是我的函数sendmail,其中包含我试图传递给视图的url。此变量返回空值。也许我会在我的注册控制器中显示我的操作确认:

public function actionConfirm($email, $key) {

        $user = \common\models\User::find()->where([
                    'email' => $email,
                    'auth_key' => $key,
                    'status' => 0,
                ])->one();
        if (!empty($user)) {
            $user->status = 10;
            $user->save();
            Yii::$app->getSession()->setFlash('success', 'Success!');
        } else {
            Yii::$app->getSession()->setFlash('warning', 'Failed!');
        }
        return $this->goHome();
    }

所以我发送电子邮件,在这封电子邮件中我将url传递给我的actionConfirm。如果用户单击此链接,其状态将变为1而不是0。但是我不知道为什么我的auth_密钥是returnme NULL。任何人都可以在getSetPasswordLink中看到我的fail?

您的代码在返回之前退出。。验证密钥链接

   var_dump($user['auth_key']);
    exit();
    return Url::to(['registration/confirm', 'email' => $this->email, 'authkey' => $user['auth_key']], true);

这样,sendEmail()就无法获得要发送的正确值

我知道这一点,但如果我用exit it not work删除varump,我的链接看起来像:email)%40gmail.com,但没有auth_key,当我单击link时,我会用错误的请求(#400)呈现我的页面,缺少必需的参数:keyso此auth_key为Null。。我认为如果删除exit(),那么函数应该返回url。。使用auth_键。。。但是如果在这个返回之前auth_密钥为null..并且您可以在var_dump(..)中看到null,这意味着您没有保存valida auth_密钥用户。。。进入请确认与否..我解决了这个问题,只是在保存用户数据之前设置了电子邮件