コード例 #1
0
 /**
  * User Authentication Token Interface
  * 
  * @param type $id
  * @return type
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionTokens($id)
 {
     if (!\Yii::$app->controller->module->params['enableTokenAuthentication']) {
         throw new \yii\web\NotFoundHttpException('Page not found.');
     }
     $model = new AuthenticationToken(['scenario' => AuthenticationToken::SCENARIO_TOKEN_GENERATION, 'user_id' => $id]);
     if ($model->load(\Yii::$app->request->post())) {
         if ($model->save()) {
             \Yii::$app->session->setFlash('success', "<strong>Token Generated Successfully (Copy it Now):</strong><br>" . $model->token);
         }
         $model = new AuthenticationToken(['scenario' => AuthenticationToken::SCENARIO_TOKEN_GENERATION, 'user_id' => $id]);
         //reset model
     }
     $searchModel = new AuthenticationToken(['user_id' => $id]);
     $dataProvider = $searchModel->search($id);
     return $this->render('token', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }