web.php 9.3 KB

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