예제 #1
0
 protected function updateToken($value = null)
 {
     $token = AuthToken::findOne(['user_id' => $this->id]);
     if (!$token) {
         $token = new AuthToken();
         $token->user_id = $this->id;
     }
     if ($value) {
         $token->token = $value;
     }
     return $token->save();
 }
예제 #2
0
<?php

$aliases = (require __DIR__ . '/../../common/config/aliases.php');
$db = (require __DIR__ . '/../../common/config/db.php');
$params = (require __DIR__ . '/params.php');
$routes = (require __DIR__ . '/routes.php');
$config = ['on beforeAction' => function ($event) {
    // Удаление истекших токенов нужно перенести в cron
    \common\models\AuthToken::DeleteExpired();
}, 'as authenticator' => ['class' => 'app\\components\\filters\\auth\\HttpBearerAuth'], 'aliases' => $aliases, 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'components' => ['assetManager' => ['basePath' => '@app/web/assets'], 'authManager' => ['class' => 'yii\\rbac\\DbManager', 'defaultRoles' => ['guest', 'customer'], 'cache' => 'cache'], 'cache' => ['class' => 'yii\\caching\\FileCache'], 'db' => $db, 'errorHandler' => ['errorAction' => 'default/error'], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'mailer' => ['class' => 'yii\\swiftmailer\\Mailer', 'useFileTransport' => true], 'request' => ['cookieValidationKey' => 'V2jq0Rj1lG6hj!dthrb', 'enableCsrfValidation' => false, 'parsers' => ['application/json' => 'yii\\web\\JsonParser']], 'urlManager' => ['enablePrettyUrl' => true, 'enableStrictParsing' => true, 'showScriptName' => false, 'rules' => $routes], 'user' => ['identityClass' => 'app\\models\\Auth', 'enableSession' => false, 'loginUrl' => '/', 'authTimeout' => 3600]], 'controllerNamespace' => 'app\\controllers', 'id' => 'api', 'name' => 'API server', 'params' => $params];
if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = ['class' => 'yii\\debug\\Module'];
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = ['class' => 'yii\\gii\\Module'];
}
return $config;