芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/airport-back/config/web.php
'basic', 'language'=>'es', 'timezone'=>'America/Mexico_City', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log', // 'app\components\EventBootstrap' ], 'aliases' => [ '@bower' => '@vendor/bower-asset', '@npm' => '@vendor/npm-asset', ], 'components' => [ 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => 'YKhIj0kUownPaqOL_-bd6zt8wpdz8Bmz', 'parsers' => [ 'application/json' => 'yii\web\JsonParser', 'multipart/form-data' => 'yii\web\MultipartFormDataParser', ], 'class' => 'yii\web\Request', 'enableCsrfValidation' => false, 'enableCookieValidation' => false, 'enableCsrfCookie' => false, ], 'response' => [ 'format' => yii\web\Response::FORMAT_JSON, 'charset' => 'UTF-8', 'on beforeSend' => function ($event) { $response = $event->sender; $response->headers->set('Access-Control-Allow-Origin', '*'); $response->headers->set('Access-Control-Allow-Methods', 'POST, GET, PUT,PATCH,DELETE,OPTIONS'); $response->headers->set('Access-Control-Allow-Headers', 'Authorization, Content-Type'); $response->headers->set('Access-Control-Expose-Headers', 'X-Pagination-Current-Page, X-Pagination-Page-Count, X-Pagination-Per-Page, X-Pagination-Total-Count'); $response->headers->set('Cache-Control', 'no-cache'); }, ], 'cache' => [ 'class' => 'yii\caching\FileCache', ], 'user' => [ 'identityClass' => 'app\models\User', 'enableSession' => false, 'loginUrl' => null, 'enableAutoLogin' => false, 'identityCookie' => null, ], 'errorHandler' => [ 'errorAction' => 'site/error', ], 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', // send all mails to a file by default. You have to set // 'useFileTransport' to false and configure transport // for the mailer to send real emails. 'useFileTransport' => true, ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], 'db' => $db, 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ $params['api_prefix'].'/auth/
' => 'auth/
', $params['api_prefix'].'/users/catalogs' => 'user/catalogs', $params['api_prefix'].'/dashboard/index' => 'dashboard/index', $params['api_prefix'].'/profiles/permissions' => 'profile/permissions', $params['api_prefix'].'/aircrafts/catalogs' => 'aircraft/catalogs', $params['api_prefix'].'/seatclasses/catalogs' => 'seatclass/catalogs', $params['api_prefix'].'/flights/catalogs' => 'flight/catalogs', $params['api_prefix'].'/site/catalogs' => 'site/catalogs', $params['api_prefix'].'/site/searchdestinations' => 'site/searchdestinations', $params['api_prefix'].'/site/searchflights' => 'site/searchflights', $params['api_prefix'].'/site/getflight' => 'site/getflight', $params['api_prefix'].'/site/register' => 'site/register', ['class' => 'yii\rest\UrlRule', 'controller' => 'airline', 'prefix'=>$params['api_prefix'] ], ['class' => 'yii\rest\UrlRule', 'controller' => 'aircraft', 'prefix'=>$params['api_prefix'] ], ['class' => 'yii\rest\UrlRule', 'controller' => 'flight', 'prefix'=>$params['api_prefix'] ], ['class' => 'yii\rest\UrlRule', 'controller' => 'booking', 'prefix'=>$params['api_prefix'] ], ['class' => 'yii\rest\UrlRule', 'controller' => 'destination', 'prefix'=>$params['api_prefix'] ], ['class' => 'yii\rest\UrlRule', 'controller' => 'seatclass', 'prefix'=>$params['api_prefix'] ], ['class' => 'yii\rest\UrlRule', 'controller' => 'seat', 'prefix'=>$params['api_prefix'] ], ['class' => 'yii\rest\UrlRule', 'controller' => 'customer', 'prefix'=>$params['api_prefix'] ], ['class' => 'yii\rest\UrlRule', 'controller' => 'user', 'prefix'=>$params['api_prefix'] ], ['class' => 'yii\rest\UrlRule', 'controller' => 'profile', 'prefix'=>$params['api_prefix'] ], ['class' => 'yii\rest\UrlRule', 'controller' => 'payment', 'prefix'=>$params['api_prefix'] ], ], ], ], 'params' => $params, 'on beforeAction'=>function($event){//la validación del JWT se realiza en este evento if($_SERVER['SERVER_NAME']=='localhost'){ //sleep(1); } $action=$event->action; $controller_id=$action->controller->id; $action_id=$action->id; $user = Yii::$app->user; //obtener el token de autorización del encabezado de la petición $token = Yii::$app->request->headers->get('Authorization'); //Se omite el controlador auth * por ahora no se valida a nivel action, sino globalmente todas las acciones de auth son permitidas if(strpos(Yii::$app->request->url,'/api/v1/auth/')===false && strpos(Yii::$app->request->url,'/gii')===false && strpos(Yii::$app->request->url,'/site')===false){ if (!empty($token)) { $token=str_replace(['Bearer',' '],'',$token); try { //Se usa la función decode de Firebase para JWT $decoded = \Firebase\JWT\JWT::decode($token, new \Firebase\JWT\Key(Yii::$app->params['jwtSecret'], 'HS256')); //Se valida que el token, si no existe, se niega la petición $user=\app\models\User::findIdentityByAccessToken($token); //Yii::$app->response->data = ['error' => $controller_id.'/'.$action_id]; /// Yii::$app->response->data = ['error' => $user->allowed($controller_id,$action_id)]; // Yii::$app->end(); if($user){ if(!$user->profile_changes){ if($user->allowed($controller_id,$action_id)){ Yii::$app->params["user"]=$user; }else{ Yii::$app->response->setStatusCode(403); Yii::$app->response->data = ['error' => Yii::t('app','Acceso no autorizado')]; Yii::$app->end(); } }else{ Yii::$app->response->setStatusCode(401); Yii::$app->response->data = ['error' => Yii::t('app','Sesión expirada')]; Yii::$app->end(); } }else{ Yii::$app->response->setStatusCode(401); Yii::$app->response->data = ['error' => Yii::t('app','Usuario no válido')]; Yii::$app->end(); } } catch (\Firebase\JWT\ExpiredException $e) { Yii::$app->response->statusCode=440; Yii::$app->response->data = ['error' => Yii::t('app','Token expirado')]; Yii::$app->end(); } catch (\Exception $e) { Yii::$app->response->statusCode=401; Yii::$app->response->data = ['error' => Yii::t('app','Token inválido')]; Yii::$app->end(); } }else{ Yii::$app->response->statusCode=401; Yii::$app->response->data = ['error' => Yii::t('app','Solicitud no válida')]; Yii::$app->end(); } } }, //Este código es para permitir las peticiones pre-flight de CORS que envía el navegador y evitar el error de CORS 'on beforeRequest' => function () { if(Yii::$app->request->isOptions){ Yii::$app->response->statusCode=200; Yii::$app->response->send(); Yii::$app->end(); } }, ]; if (YII_ENV_DEV) { // configuration adjustments for 'dev' environment $config['bootstrap'][] = 'debug'; $config['modules']['debug'] = [ 'class' => 'yii\debug\Module', // uncomment the following to add your IP if you are not connecting from localhost. //'allowedIPs' => ['127.0.0.1', '::1'], ]; $config['bootstrap'][] = 'gii'; $config['modules']['gii'] = [ 'class' => 'yii\gii\Module', // uncomment the following to add your IP if you are not connecting from localhost. 'allowedIPs' => ['127.0.0.1', '::1','*'], ]; } return $config;