yii框架中郵箱激活(數字簽名)

控制器:php

   //發送郵箱,激活帳號
   public function actionEmail()
   {
        $email=Yii::$app->request->get('email');
        //數字簽名
        $em_1=md5($email);

        //郵箱發送
        $mail= Yii::$app->mailer->compose();   
        $mail->setTo($email);
        $mail->setSubject("激活郵箱");
        //發佈能夠帶html標籤的文本
        $mail->setHtmlBody("<a href='http://www.small2.com/backend/web/index.php?r=login/live&em_1=".$em_1."&email=".$email."'>點擊此連接</a>");  
        if($mail->send())  
            echo "success";  
        else  
            echo "false";   
        die(); //郵箱發送ok
   }
   //激活帳號
   public function actionLive()
   {
      $email=Yii::$app->request->get('email');
      $em_1=Yii::$app->request->get('em_1');
      //echo $em_1;die;
      $em_2=md5($email);
      //echo $em_2;die;
      if($em_1==$em_2)
      {
          $res=Yii::$app->db;
          $data=$res->createCommand()->update("login",["status"=>1],["email"=>$email])->execute();
          if($data)
          {
            echo "<script>alert('激活成功,可登陸');location.href='index.php?r=login/login'</script>";
          }
          else
          {
             echo "<script>alert('激活失敗');location.href='index.php?r=login/login'</script>";
          }
      }
      else
      {
          echo "<script>alert('參數錯誤,從新激活');location.href='index.php?r=login/login'</script>";
      } 
}html

原理:(註冊後原有默認原有狀態status=0,激活後改成1,方可登錄。)web

相關文章
相關標籤/搜索