用户通过电子邮件地址进行身份验证auth_key


User authenticating by email address with auth_key

我尝试在使用Authkey属性注册后发送电子邮件。但是我对用户的这个身份验证密钥有问题。我不知道为什么在发送此电子邮件之前不保存此内容。有我来自SignupForm的代码:

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

有我的函数 发送带有网址的电子邮件 我尝试传递给视图。这var_dum让我空。我在我的注册控制器中显示我的操作确认:

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();
    }

所以我发送电子邮件,在这封电子邮件中,我将网址传递给我的操作确认。如果用户单击此链接,其状态将变为 1 而不是 0。但我不知道为什么我的auth_key是返回我 NULL。有人能看到我的失败吗?

in your getSetPasswordLink您的代码在返回之前退出..auth_key链接...

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

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