dqy006150 2016-02-07 16:46
浏览 59

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

i try to send email after registration with authkey attribute. But i have problem with this authkey from user. I dont know why it not save this before send this email. There is my code from 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;
    }

There is my function sendEmail with url which i try to pass to the view. This var_dum return me NUll. MAybe i show my action Confirm in my RegistrationController:

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

So i send email and in this email i pass url to my actionConfirm. If user click this link his status become 1 instead of 0. But I dont know why my auth_key is return me NULL. Anyone can see my fail?

  • 写回答

1条回答 默认 最新

  • duanquannan0593 2016-02-07 17:41
    关注

    in your getSetPasswordLink your code exit before return .. the auth_key link ...

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

    in this way your sendEmail() can't get the right value to send ..

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)