web.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. $params = require __DIR__ . '/params.php';
  3. $db = require __DIR__ . '/db.php';
  4. $config = [
  5. 'id' => 'basic',
  6. 'name'=>'Antares-2000',
  7. 'basePath' => dirname(__DIR__),
  8. 'bootstrap' => ['log'],
  9. 'language' => 'ru-RU',
  10. //'defaultRoute' => 'main/index',
  11. 'aliases' => [
  12. '@bower' => '@vendor/bower-asset',
  13. '@npm' => '@vendor/npm-asset',
  14. ],
  15. 'container' => [
  16. 'definitions' => [
  17. \yii\widgets\LinkPager::class => \yii\bootstrap4\LinkPager::class,
  18. ],
  19. ],
  20. 'components' => [
  21. 'request' => [
  22. // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
  23. 'cookieValidationKey' => '9F0UJBZKPPoUsJAKuAh9hpvyWdaF1IIb',
  24. 'parsers' => [
  25. 'application/json' => 'yii\web\JsonParser',
  26. ]
  27. ],
  28. 'cache' => [
  29. 'class' => 'yii\caching\FileCache',
  30. ],
  31. 'user' => [
  32. 'class' => 'app\components\User',
  33. 'loginUrl' => ['login'],
  34. //'returnUrl' => ['home'],
  35. 'identityClass' => 'app\models\user\User',
  36. ],
  37. 'errorHandler' => [
  38. 'errorAction' => 'site/error',
  39. ],
  40. 'mailer' => [
  41. 'class' => 'yii\swiftmailer\Mailer',
  42. // send all mails to a file by default. You have to set
  43. // 'useFileTransport' to false and configure a transport
  44. // for the mailer to send real emails.
  45. //'useFileTransport' => false,
  46. 'transport' => [
  47. 'class' => 'Swift_SmtpTransport',
  48. 'host' => $_ENV['SMTP_HOST'],
  49. 'username' => $_ENV['SMTP_LOGIN'],
  50. 'password' => $_ENV['SMTP_PASS'],
  51. 'port' => $_ENV['SMTP_PORT'],
  52. 'encryption' => $_ENV['SMTP_ENC'],
  53. ],
  54. ],
  55. 'log' => [
  56. 'traceLevel' => YII_DEBUG ? 3 : 0,
  57. 'targets' => [
  58. [
  59. 'class' => 'yii\log\FileTarget',
  60. 'levels' => ['error', 'warning'],
  61. ],
  62. ],
  63. ],
  64. 'db' => $db,
  65. 'urlManager' => [
  66. 'enablePrettyUrl' => true,
  67. 'enableStrictParsing' => true,
  68. 'showScriptName' => false,
  69. 'rules' => [
  70. [
  71. 'class' => 'yii\rest\UrlRule',
  72. 'controller' => ['api/user'],
  73. 'extraPatterns' => [
  74. 'POST add' => 'bulk-add',
  75. ],
  76. ],
  77. '/' => 'site/index',
  78. 'pricing/<action:[\w\-]+>' => 'pricing/<action>',
  79. 'profile/<action:[\w\-]+>' => 'profile/<action>',
  80. 'pay/<action:[\w\-]+>' => 'pay/<action>',
  81. 'history/<action:[\w\-]+>' => 'history/<action>',
  82. //'user/admin/<action:\w+>' => 'user/admin/<action>',
  83. 'user/<controller:[\w\-]+>/<action:[\w\-]+>' => 'user/<controller>/<action>',
  84. //'login' => 'user/security/login',
  85. '<alias:logout|login>' => 'user/security/<alias>',
  86. //'api/<action:\w+>' => 'api/<action>',
  87. //'api/<action:[\w\-]+>/<id:\d+>' => 'api/<action>'
  88. ],
  89. ],
  90. 'i18n' => [
  91. 'translations' => [
  92. 'app' => [
  93. 'class' => 'yii\i18n\PhpMessageSource',
  94. 'basePath' => '@app/messages',
  95. 'sourceLanguage' => 'en',
  96. 'fileMap' => [
  97. 'app' => 'app.php',
  98. ],
  99. ],
  100. 'user' => [
  101. 'class' => 'yii\i18n\PhpMessageSource',
  102. 'basePath' => '@app/messages',
  103. 'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']
  104. ],
  105. ],
  106. ],
  107. 'view' => [
  108. 'theme' => [
  109. 'pathMap' => [
  110. '@dektrium/user/views' => '@app/views/user'
  111. ],
  112. ],
  113. ],
  114. 'assetManager' => [
  115. 'bundles' => [
  116. 'yii\bootstrap\BootstrapPluginAsset' => [
  117. 'js'=>[]
  118. ],
  119. 'yii\bootstrap\BootstrapAsset' => [
  120. 'css' => [],
  121. ],
  122. ],
  123. ],
  124. ],
  125. 'modules' => [
  126. 'user' => [
  127. 'class' => 'dektrium\user\Module',
  128. 'enableRegistration' => false,
  129. 'enablePasswordRecovery' => true,
  130. 'enableConfirmation' => false,
  131. //'adminPermission' => 'admin',
  132. //'admins' => ['ptenchik0'],
  133. 'rememberFor' => 86400,
  134. //'debug' => true,
  135. 'controllerMap' => [
  136. 'settings' => 'app\controllers\ProfileController'
  137. ],
  138. 'modelMap' => [
  139. //'RecoveryForm' => 'app\models\security\RecoveryForm',
  140. //'RegistrationForm' => 'app\models\security\RegistrationForm',
  141. 'User' => 'app\models\user\User',
  142. 'UserSearch' => 'app\models\user\search\Users',
  143. 'LoginForm' => 'app\models\user\LoginForm',
  144. //'Profile' => 'app\models\user\Profile',
  145. //'SettingsForm' => 'app\models\user\SettingsForm',
  146. ],
  147. ],
  148. 'api' => [
  149. 'class' => 'app\modules\api\Module',
  150. ],
  151. ],
  152. 'params' => $params,
  153. 'on beforeAction' => function ($event) {
  154. if (Yii::$app->user->isGuest) :
  155. Yii::$app->layout = 'guest';
  156. else:
  157. $email = substr(Yii::$app->user->identity->email, strripos(Yii::$app->user->identity->email, '@') + 1 );
  158. if('example.com' === $email){
  159. $pass_link = \yii\bootstrap4\Html::a('Змінити', \yii\helpers\Url::to(['profile/account']), ['class'=>'text-uppercase']);
  160. Yii::$app->session->setFlash('warning', 'Для можливості відновлення паролю, будь-ласка, змініть свій <strong>Email</strong>. ' . $pass_link);
  161. }
  162. if(Yii::$app->user->identity->created_at == Yii::$app->user->identity->updated_at){
  163. $pass_link = \yii\bootstrap4\Html::a('Змінити', \yii\helpers\Url::to(['profile/account']), ['class'=>'text-white text-uppercase']);
  164. Yii::$app->session->setFlash('danger', '<strong>Ваш пароль є тимчасовым</strong>. З розумінь безпеки, будь-ласка, змініть свій пароль. ' . $pass_link);
  165. }
  166. endif;
  167. },
  168. 'as globalAccess' => [
  169. 'class' => app\components\GlobalAccessBehavior::class,
  170. 'rules' => [
  171. [
  172. 'actions' => ['error'],
  173. 'allow' => true,
  174. 'roles' => ["?","@"],
  175. ],
  176. [
  177. 'actions' => ['login', 'request'],
  178. 'allow' => true,
  179. 'roles' => ['?'],
  180. ],
  181. [
  182. 'actions' => ['logout'],
  183. 'allow' => true,
  184. 'roles' => ['@'],
  185. ],
  186. /*
  187. [
  188. 'controllers' => ['api/user'],
  189. 'allow' => true,
  190. 'roles' => ['?'],
  191. ],*/
  192. [
  193. 'controllers' => ['user/admin'],
  194. 'allow' => true,
  195. 'roles' => ['admin'],
  196. ],
  197. [
  198. 'controllers' => ['user/admin', 'user/settings', 'user/profile'],
  199. 'allow' => false,
  200. ],
  201. [
  202. 'allow' => true,
  203. 'roles' => ['client', 'admin'],
  204. ],
  205. // [
  206. // 'controllers' => ['sign-in'],
  207. // 'allow' => true,
  208. // 'roles' => ['?'],
  209. // 'actions' => ['login'],
  210. // ],
  211. // [
  212. // 'controllers' => ['sign-in'],
  213. // 'allow' => true,
  214. // 'roles' => ['@'],
  215. // 'actions' => ['logout'],
  216. // ],
  217. // [
  218. // 'controllers' => ['site'],
  219. // 'allow' => true,
  220. // 'roles' => ['?', '@'],
  221. // 'actions' => ['error'],
  222. // ],
  223. // [
  224. // 'controllers' => ['debug/default'],
  225. // 'allow' => true,
  226. // 'roles' => ['?'],
  227. // ],
  228. // [
  229. // 'controllers' => ['user'],
  230. // 'allow' => true,
  231. // 'roles' => ['administrator'],
  232. // ],
  233. // [
  234. // 'controllers' => ['user'],
  235. // 'allow' => false,
  236. // ],
  237. // [
  238. // 'allow' => true,
  239. // 'roles' => ['manager', 'administrator'],
  240. // ],
  241. ],
  242. ],
  243. ];
  244. if (YII_ENV_DEV) {
  245. // configuration adjustments for 'dev' environment
  246. $config['bootstrap'][] = 'debug';
  247. $config['modules']['debug'] = [
  248. 'class' => 'yii\debug\Module',
  249. // uncomment the following to add your IP if you are not connecting from localhost.
  250. //'allowedIPs' => ['127.0.0.1', '::1'],
  251. ];
  252. $config['bootstrap'][] = 'gii';
  253. $config['modules']['gii'] = [
  254. 'class' => 'yii\gii\Module',
  255. // uncomment the following to add your IP if you are not connecting from localhost.
  256. //'allowedIPs' => ['127.0.0.1', '::1'],
  257. ];
  258. }
  259. return $config;