Ejemplo n.º 1
0
 public function getAccessToken()
 {
     $sessionId = \Yii::$app->session->getId();
     $user = \Yii::$app->getUser();
     $accessToken = AccessToken::find()->where(['user_id' => $user->id])->andWhere(['session_id' => $sessionId])->one();
     if ($accessToken != null) {
         if (!$accessToken->validate(['token'])) {
             $accessToken->token = TokenService::generateAccessToken();
         }
     } else {
         $accessToken = new AccessToken();
         $accessToken->user_id = $user->id;
         $accessToken->session_id = $sessionId;
         $accessToken->token = TokenService::generateAccessToken();
     }
     $date = date('Y-m-d H:i:s');
     $accessToken->created = $date;
     if ($accessToken->save()) {
         $this->accessToken = $accessToken;
         return $accessToken->token;
     } else {
         return null;
     }
 }
 public function up()
 {
     $this->insert('access_token', ['token' => \app\services\TokenService::generateAccessToken(), 'user_id' => '1', 'created' => date('Y-m-d H:i:s')]);
 }