Browse Source

Code format

Installer fix
IDE Yii autocompletion
master
Egorka 6 years ago
parent
commit
8dd38b6e00
  1. 47
      Yii.php
  2. 50
      backend/controllers/AuthController.php
  3. 482
      backend/controllers/MenuController.php
  4. 134
      backend/controllers/ModuleController.php
  5. 41
      backend/controllers/PermissionController.php
  6. 68
      backend/controllers/RoleController.php
  7. 116
      backend/controllers/SiteController.php
  8. 114
      backend/controllers/SliderController.php
  9. 140
      backend/controllers/UserController.php
  10. 261
      backend/controllers/settings/ListController.php
  11. 81
      backend/views/role/view.php
  12. 43
      console/controllers/ModuleController.php
  13. 39
      console/controllers/PermissionController.php
  14. 8
      console/controllers/UserController.php
  15. 91
      core/entities/Settings.php
  16. 25
      core/services/SettingsService.php
  17. 29
      core/services/user/UserManageService.php
  18. 210
      frontend/config/main.php
  19. 11
      frontend/controllers/ContactController.php
  20. 69
      frontend/controllers/SiteController.php
  21. 29
      frontend/controllers/account/ProfileController.php
  22. 56
      frontend/controllers/auth/AuthController.php
  23. 6
      frontend/controllers/auth/NetworkController.php
  24. 10
      frontend/controllers/auth/ResetController.php
  25. 21
      frontend/controllers/auth/SignupController.php
  26. 167
      setup.php

47
Yii.php

@ -0,0 +1,47 @@
<?php
/**
* Yii bootstrap file.
* Used for enhanced IDE code autocompletion.
*/
class Yii extends \yii\BaseYii
{
/**
* @var BaseApplication|WebApplication|ConsoleApplication the application instance
*/
public static $app;
}
/**
* Class BaseApplication
* Used for properties that are identical for both WebApplication and ConsoleApplication
*
* @ property \app\components\RbacManager $authManager The auth manager for this application. Null is returned if auth manager is not configured. This property is read-only. Extended component.
* @ property \app\components\Mailer $mailer The mailer component. This property is read-only. Extended component.
*/
abstract class BaseApplication extends yii\base\Application
{
}
/**
* Class WebApplication
* Include only Web application related components here
*
* @property \core\components\modules\ModuleManager $moduleManager Module manager
*
* @property \core\entities\user\User $user The user component. This property is read-only. Extended component.
* @ property \app\components\MyResponse $response The response component. This property is read-only. Extended component.
* @ property \app\components\ErrorHandler $errorHandler The error handler application component. This property is read-only. Extended component.
*/
class WebApplication extends yii\web\Application
{
}
/**
* Class ConsoleApplication
* Include only Console application related components here
*
* @ property \app\components\ConsoleUser $user The user component. This property is read-only. Extended component.
*/
class ConsoleApplication extends yii\console\Application
{
}

50
backend/controllers/AuthController.php

@ -1,4 +1,5 @@
<?php
namespace backend\controllers;
use common\auth\Identity;
@ -11,12 +12,12 @@ use yii\filters\AccessControl;
class AuthController extends Controller
{
private $authService;
private $_auth_service;
public function __construct($id, $module, AuthService $service, $config = [])
{
parent::__construct($id, $module, $config);
$this->authService = $service;
$this->_auth_service = $service;
}
/**
@ -25,27 +26,27 @@ class AuthController extends Controller
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['login'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['login'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'logout' => ['post'],
],
@ -67,8 +68,9 @@ class AuthController extends Controller
$form = new LoginForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$user = $this->authService->auth($form);
$user = $this->_auth_service->auth($form);
Yii::$app->user->login(new Identity($user), $form->rememberMe ? 3600 * 24 * 30 : 0);
return $this->goBack();
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);

482
backend/controllers/MenuController.php

@ -23,257 +23,233 @@ use Yii;
class MenuController extends Controller
{
public $menu_service;
public $menu_item_service;
public function __construct( string $id, $module, MenuManageService $menu_service, MenuItemManageService $menu_item_service, array $config = [] ) {
parent::__construct( $id, $module, $config );
$this->menu_service = $menu_service;
$this->menu_item_service = $menu_item_service;
}
public function behaviors(): array
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
'roles' => ['MenuManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
'delete-menu-item' => ['POST'],
],
],
];
}
public function actionIndex($id = null)
{
$menus = []; // menu list
$menu_records = Menu::find()->all();
foreach ($menu_records as $menu_record) {
$menus[$menu_record->id] = isset($menu_record->translation) && $menu_record->translation->name ? $menu_record->translation->name : $menu_record->findTranslation(Yii::$app->params['defaultLanguage'])->name;
}
$form = new MenuSelectForm();
if ($form->load(Yii::$app->request->get()) && $form->validate()) {
return $this->redirect(['menu/index', 'id' => $form->id]);
}
elseif ($id) {
$this->createMenuItem(); // create menu item if MenuItemForm sent
$menu = $this->findModel($id);
$creatorWidgets = $this->getCreatorWidgets($menu->id);
return $this->render('menu', [
'model' => $form,
'menus' => $menus,
'menu' => $menu,
'creator' => $creatorWidgets,
]);
}
else {
return $this->render('select_menu', [
'model' => $form,
'menus' => $menus,
]);
}
}
public function actionCreate()
{
$form = new MenuForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$menu = $this->menu_service->create($form);
return $this->redirect(['index', 'id' => $menu->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('create', [
'model' => $form,
]);
}
public function actionUpdate($id)
{
$menu = $this->findModel($id);
$form = new MenuForm($menu);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->menu_service->edit($menu->id, $form);
return $this->redirect(['index', 'id' => $menu->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('update', [
'model' => $form,
'menu' => $menu,
]);
}
public function actionDelete($id)
{
try {
$this->menu_service->remove($id);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
return $this->redirect(['index']);
}
public function actionSaveItem($id)
{
$item = $this->findItemModel($id);
$form = new MenuItemForm($item);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->menu_item_service->edit($item->id, $form);
return $this->redirect(['index', 'id' => $item->menu_id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->redirect(['index', 'id' => $item->menu_id]);
}
public function actionDeleteMenuItem()
{
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if (Yii::$app->request->isAjax) {
try {
$id = Yii::$app->request->post('id');
$item = $this->findItemModel($id);
//$this->deleteItem($item);
$item->delete();
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Item Deleted'));
return [ 'result' => 'success' ];
}
catch (\RuntimeException $e) {
return [ 'result' => 'error', 'message' => $e->getMessage() ];
}
}
return ['result' => 'error', 'message' => 'Request error'];
}
/*
public function actionSaveMenuItemData()
{
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if (Yii::$app->request->isAjax) {
try {
$id = Yii::$app->request->post('id');
$name = Yii::$app->request->post('name');
$title = Yii::$app->request->post('title');
$style = Yii::$app->request->post('style');
$css = Yii::$app->request->post('css');
$url = Yii::$app->request->post('url');
$target = Yii::$app->request->post('target');
$item = $this->findItemModel($id);
$item->name = $name;
$item->title_attr = $title;
$item->style = $style;
$item->css = $css;
$item->url = $url;
$item->target = $target;
$item->save();
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Item Saved'));
return [ 'result' => 'success' ];
}
catch (\RuntimeException $e) {
return [ 'result' => 'error', 'message' => $e->getMessage() ];
}
}
return ['result' => 'error', 'message' => 'Request error'];
}
*/
public function actionSaveMenuItems()
{
$json = Yii::$app->request->post('json');
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if (Yii::$app->request->isAjax) {
try {
$order = [];
$items = Json::decode($json, true);
foreach ($items as $item) {
$order[$item[1]] = isset($order[$item[1]]) ? $order[$item[1]]+1 : 0;
$this->menu_item_service->setPosition($item, $order[$item[1]]);
}
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Saved'));
return [ 'result' => 'success' ];
}
catch (\RuntimeException $e) {
return [ 'result' => 'error', 'message' => $e->getMessage() ];
}
}
return ['result' => 'error', 'message' => 'Request error'];
}
private function getCreatorWidgets($menu_id): array
{
$widgets = [];
$modules = ModuleRecord::find()->active()->all();
foreach ($modules as $module) {
if (method_exists($module->class, 'getMenuItemCreator')) {
$module_widgets = call_user_func_array($module->class . '::getMenuItemCreator', [$menu_id]);
$widgets = is_array($module_widgets) ? array_merge($widgets, $module_widgets) : $widgets;
}
}
return $widgets;
}
private function createMenuItem()
{
$form = new MenuItemForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->menu_item_service->create($form);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
}
}
}
protected function findModel($id): Menu
{
if (($model = Menu::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested menu does not exist.');
}
protected function findItemModel($id): MenuItem
{
if (($model = MenuItem::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested menu item does not exist.');
}
public $menu_service;
public $menu_item_service;
public function __construct(
string $id,
$module,
MenuManageService $menu_service,
MenuItemManageService $menu_item_service,
array $config = []
) {
parent::__construct($id, $module, $config);
$this->menu_service = $menu_service;
$this->menu_item_service = $menu_item_service;
}
public function behaviors(): array
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
'roles' => ['MenuManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
'delete-menu-item' => ['POST'],
],
],
];
}
public function actionIndex($id = null)
{
$menus = []; // menu list
$menu_records = Menu::find()->all();
foreach ($menu_records as $menu_record) {
$menus[$menu_record->id] = isset($menu_record->translation) && $menu_record->translation->name ? $menu_record->translation->name : $menu_record->findTranslation(Yii::$app->params['defaultLanguage'])->name;
}
$form = new MenuSelectForm();
if ($form->load(Yii::$app->request->get()) && $form->validate()) {
return $this->redirect(['menu/index', 'id' => $form->id]);
} elseif ($id) {
$this->createMenuItem(); // create menu item if MenuItemForm sent
$menu = $this->findModel($id);
$creatorWidgets = $this->getCreatorWidgets($menu->id);
return $this->render('menu', [
'model' => $form,
'menus' => $menus,
'menu' => $menu,
'creator' => $creatorWidgets,
]);
} else {
return $this->render('select_menu', [
'model' => $form,
'menus' => $menus,
]);
}
}
public function actionCreate()
{
$form = new MenuForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$menu = $this->menu_service->create($form);
return $this->redirect(['index', 'id' => $menu->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('create', [
'model' => $form,
]);
}
public function actionUpdate($id)
{
$menu = $this->findModel($id);
$form = new MenuForm($menu);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->menu_service->edit($menu->id, $form);
return $this->redirect(['index', 'id' => $menu->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('update', [
'model' => $form,
'menu' => $menu,
]);
}
public function actionDelete($id)
{
try {
$this->menu_service->remove($id);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
return $this->redirect(['index']);
}
public function actionSaveItem($id)
{
$item = $this->findItemModel($id);
$form = new MenuItemForm($item);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->menu_item_service->edit($item->id, $form);
return $this->redirect(['index', 'id' => $item->menu_id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->redirect(['index', 'id' => $item->menu_id]);
}
public function actionDeleteMenuItem()
{
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if (Yii::$app->request->isAjax) {
try {
$id = Yii::$app->request->post('id');
$item = $this->findItemModel($id);
$item->delete();
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Item Deleted'));
return ['result' => 'success'];
} catch (\RuntimeException $e) {
return ['result' => 'error', 'message' => $e->getMessage()];
}
}
return ['result' => 'error', 'message' => 'Request error'];
}
public function actionSaveMenuItems()
{
$json = Yii::$app->request->post('json');
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if (Yii::$app->request->isAjax) {
try {
$order = [];
$items = Json::decode($json, true);
foreach ($items as $item) {
$order[$item[1]] = isset($order[$item[1]]) ? $order[$item[1]] + 1 : 0;
$this->menu_item_service->setPosition($item, $order[$item[1]]);
}
Yii::$app->session->setFlash('success', Yii::t('menu', 'Menu Saved'));
return ['result' => 'success'];
} catch (\RuntimeException $e) {
return ['result' => 'error', 'message' => $e->getMessage()];
}
}
return ['result' => 'error', 'message' => 'Request error'];
}
private function getCreatorWidgets($menu_id): array
{
$widgets = [];
$modules = ModuleRecord::find()->active()->all();
foreach ($modules as $module) {
if (method_exists($module->class, 'getMenuItemCreator')) {
$module_widgets = call_user_func_array($module->class . '::getMenuItemCreator', [$menu_id]);
$widgets = is_array($module_widgets) ? array_merge($widgets, $module_widgets) : $widgets;
}
}
return $widgets;
}
private function createMenuItem()
{
$form = new MenuItemForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->menu_item_service->create($form);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
}
}
}
protected function findModel($id): Menu
{
if (($model = Menu::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested menu does not exist.');
}
protected function findItemModel($id): MenuItem
{
if (($model = MenuItem::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested menu item does not exist.');
}
}

134
backend/controllers/ModuleController.php

@ -6,7 +6,6 @@
namespace backend\controllers;
use core\entities\ModuleRecord;
use core\services\ModuleService;
use yii\web\Controller;
@ -16,77 +15,80 @@ use yii\web\NotFoundHttpException;
class ModuleController extends Controller
{
private $service;
private $_service;
public function __construct(string $id, $module, ModuleService $service, array $config = [])
{
parent::__construct($id, $module, $config);
$this->_service = $service;
}
public function behaviors(): array
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['list', 'disable', 'enable', 'delete'],
'allow' => true,
'roles' => ['ModuleManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
'disable' => ['POST'],
'enable' => ['POST'],
],
],
];
}
public function actionList()
{
$modules = \Yii::$app->moduleManager->getModules();
public function __construct( string $id, $module, ModuleService $service, array $config = [] ) {
parent::__construct( $id, $module, $config );
$this->service = $service;
}
return $this->render('list', [
'modules' => $modules,
]);
}
public function behaviors(): array
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['list', 'disable', 'enable', 'delete'],
'allow' => true,
'roles' => ['ModuleManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
'disable' => ['POST'],
'enable' => ['POST'],
],
],
];
}
public function actionDelete($id)
{
$module = $this->findModel($id);
$this->_service->delete($module);
public function actionList()
{
//$modules = ModuleRecord::find()->all();
$modules = \Yii::$app->moduleManager->getModules();
return $this->redirect(['module/list']);
}
return $this->render('list', [
'modules' => $modules,
]);
}
public function actionDisable($id)
{
$module = $this->findModel($id);
$this->_service->disable($module);
public function actionDelete($id)
{
$module = $this->findModel($id);
$this->service->delete($module);
return $this->redirect(['module/list']);
}
return $this->redirect(['module/list']);
}
public function actionDisable($id)
{
$module = $this->findModel($id);
$this->service->disable($module);
return $this->redirect(['module/list']);
}
public function actionEnable($id)
{
$module = $this->findModel($id);
$this->_service->enable($module);
public function actionEnable($id)
{
$module = $this->findModel($id);
$this->service->enable($module);
return $this->redirect(['module/list']);
}
return $this->redirect(['module/list']);
}
protected function findModel($id): ModuleRecord
{
if (($model = ModuleRecord::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested module does not exist.');
}
protected function findModel($id): ModuleRecord
{
if (($model = ModuleRecord::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested module does not exist.');
}
}

41
backend/controllers/PermissionController.php

@ -19,12 +19,12 @@ use yii\filters\AccessControl;
class PermissionController extends Controller
{
private $permission;
private $_permission;
public function __construct($id, $module, PermissionManager $permission, $config = [])
{
parent::__construct($id, $module, $config);
$this->permission = $permission;
$this->_permission = $permission;
}
/**
@ -34,15 +34,15 @@ class PermissionController extends Controller
{
return [
[
'class' => TimestampBehavior::className(),
'class' => TimestampBehavior::class,
],
'access' => [
'class' => AccessControl::className(),
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['create','view','index', 'update', 'delete'],
'allow' => true,
'roles' => ['UserManagement'],
'actions' => ['create', 'view', 'index', 'update', 'delete'],
'allow' => true,
'roles' => ['UserManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
@ -50,8 +50,8 @@ class PermissionController extends Controller
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
@ -61,19 +61,19 @@ class PermissionController extends Controller
public function actionIndex()
{
$data = array_map(function (Permission $permission){
$data = array_map(function (Permission $permission) {
return [
'name' => $permission->name,
'name' => $permission->name,
'description' => $permission->description,
];
}, $this->permission->getPermissions());
}, $this->_permission->getPermissions());
$dataProvider = new ArrayDataProvider([
'allModels' => $data,
'allModels' => $data,
'pagination' => [
'pageSize' => 20,
],
'sort' => [
'sort' => [
'attributes' => ['name', 'description'],
],
]);
@ -86,13 +86,15 @@ class PermissionController extends Controller
$form = new RbacCreatePermissionForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->permission->create($form->name, $form->description, $form->rule_name, $form->data);
$this->_permission->create($form->name, $form->description, $form->rule_name, $form->data);
return $this->redirect(['view', 'id' => $form->name]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('create', [
'model' => $form,
]);
@ -105,13 +107,15 @@ class PermissionController extends Controller
$form = new RbacEditPermissionForm($permission);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->permission->update($permission->name, $form->name, $form->description, $form->rule_name, $form->data);
$this->_permission->update($permission->name, $form->name, $form->description, $form->rule_name, $form->data);
return $this->redirect(['view', 'id' => $form->name]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('update', [
'model' => $form,
]);
@ -119,7 +123,8 @@ class PermissionController extends Controller
public function actionDelete($id)
{
$this->permission->delete($id);
$this->_permission->delete($id);
return $this->redirect(['index']);
}
@ -132,6 +137,6 @@ class PermissionController extends Controller
protected function findModel($id)
{
return $this->permission->getPermission($id);
return $this->_permission->getPermission($id);
}
}

68
backend/controllers/RoleController.php

@ -20,14 +20,14 @@ use Yii;
class RoleController extends Controller
{
private $role;
private $permission;
private $_role;
private $_permission;
public function __construct($id, $module, RoleManager $role, PermissionManager $permission, $config = [])
{
parent::__construct($id, $module, $config);
$this->role = $role;
$this->permission = $permission;
$this->_role = $role;
$this->_permission = $permission;
}
/**
@ -37,15 +37,15 @@ class RoleController extends Controller
{
return [
[
'class' => TimestampBehavior::className(),
'class' => TimestampBehavior::class,
],
'access' => [
'class' => AccessControl::className(),
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['create','view','index', 'update', 'delete'],
'allow' => true,
'roles' => ['UserManagement'],
'actions' => ['create', 'view', 'index', 'update', 'delete'],
'allow' => true,
'roles' => ['UserManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
@ -53,8 +53,8 @@ class RoleController extends Controller
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
@ -64,14 +64,14 @@ class RoleController extends Controller
public function actionIndex()
{
$data = $this->role->getRolesListArray();
$data = $this->_role->getRolesListArray();
$dataProvider = new ArrayDataProvider([
'allModels' => $data,
'allModels' => $data,
'pagination' => [
'pageSize' => 20,
],
'sort' => [
'sort' => [
'attributes' => ['name', 'description'],
],
]);
@ -84,13 +84,15 @@ class RoleController extends Controller
$form = new RbacCreateRoleForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->role->create($form->name, $form->description, $form->rule_name, $form->data);
$this->_role->create($form->name, $form->description, $form->rule_name, $form->data);
return $this->redirect(['view', 'id' => $form->name]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('create', [
'model' => $form,
]);
@ -103,13 +105,15 @@ class RoleController extends Controller
$form = new RbacEditRoleForm($role);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->role->update($role->name, $form->name, $form->description, $form->rule_name, $form->data);
$this->_role->update($role->name, $form->name, $form->description, $form->rule_name, $form->data);
return $this->redirect(['view', 'id' => $form->name]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('update', [
'model' => $form,
]);
@ -118,46 +122,44 @@ class RoleController extends Controller
public function actionDelete($id)
{
try {
$this->role->delete($id);
}
catch (\DomainException $e)
{
$this->_role->delete($id);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
return $this->redirect(['index']);
}
public function actionView($id)
{
$currentRole = $this->role->getRole($id);
$rolesSelectArray = array_diff_assoc($this->role->getRolesSelectArray(), [$currentRole->name => $currentRole->description]);
$currentRole = $this->_role->getRole($id);
$rolesSelectArray = array_diff_assoc($this->_role->getRolesSelectArray(), [$currentRole->name => $currentRole->description]);
$itemsForm = new RbacUpdateChildren();
if ($itemsForm->load(Yii::$app->request->post()) && $itemsForm->validate()) {
$this->role->saveChildren($id, $itemsForm->roles, $itemsForm->permissions);
$this->_role->saveChildren($id, $itemsForm->roles, $itemsForm->permissions);
Yii::$app->session->setFlash('success', Yii::t('user', 'Children roles and permissions for "{role}" is updated.', ['role' => $currentRole->description]));
}
$rolesSelected = $this->role->getRolesSelectArrayByRole($id);
$rolesSelected = $this->_role->getRolesSelectArrayByRole($id);
$permissionsSelectArray = $this->permission->getPermissionsSelectArray();
$permissionsSelected = $this->permission->getPermissionsSelectArrayByRole($id);
$permissionsSelectArray = $this->_permission->getPermissionsSelectArray();
$permissionsSelected = $this->_permission->getPermissionsSelectArrayByRole($id);
$itemsForm->roles = $rolesSelected;
$itemsForm->roles = $rolesSelected;
$itemsForm->permissions = $permissionsSelected;
return $this->render('view', [
'model' => $this->findModel($id),
'roles' => $rolesSelectArray,
'permissions' => $permissionsSelectArray,
'permissionsSelected' => $permissionsSelected,
'itemsForm' => $itemsForm,
'model' => $this->findModel($id),
'roles' => $rolesSelectArray,
'permissions' => $permissionsSelectArray,
'itemsForm' => $itemsForm,
]);
}
protected function findModel($id)
{
return $this->role->getRole($id);
return $this->_role->getRole($id);
}
}

116
backend/controllers/SiteController.php

@ -1,31 +1,30 @@
<?php
namespace backend\controllers;
use core\entities\Search;
use core\forms\SearchForm;
use core\helpers\LanguageHelper;
use core\services\user\UserManageService;
use Yii;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use yii\web\NotFoundHttpException;
/**
* Site controller
*/
class SiteController extends Controller
{
private $service;
private $_service;
public function __construct( string $id, $module, UserManageService $service, array $config = [] ) {
parent::__construct( $id, $module, $config );
$this->service = $service;
}
public function __construct(string $id, $module, UserManageService $service, array $config = [])
{
parent::__construct($id, $module, $config);
$this->_service = $service;
}
/**
/**
* @inheritdoc
*/
public function behaviors()
@ -36,23 +35,23 @@ class SiteController extends Controller
'rules' => [
[
'actions' => ['error'],
'allow' => true,
'allow' => true,
],
[
'actions' => ['index', 'search', 'language'],
'allow' => true,
'roles' => ['Dashboard'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['Dashboard'],
'roles' => ['admin'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'logout' => ['post'],
'logout' => ['post'],
'language' => ['post'],
],
],
@ -83,50 +82,53 @@ class SiteController extends Controller
public function actionSearch()
{
$form = new SearchForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$query = Search::find()
->andWhere(['LIKE', 'title', $form->query])
->orWhere(['LIKE', 'content', $form->query]);
$provider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
],
'sort' => [],
]);
return $this->render('search', [
'provider' => $provider,
'form' => $form
]);
//$page = $this->service->create($form);
//return $this->redirect(['view', 'id' => $page->id]);
} catch (\DomainException $e) {
//Yii::$app->errorHandler->logException($e);
//Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return '';
$form = new SearchForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$query = Search::find()
->andWhere(['LIKE', 'title', $form->query])
->orWhere(['LIKE', 'content', $form->query]);
$provider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
],
'sort' => [],
]);
return $this->render('search', [
'provider' => $provider,
'form' => $form
]);
//$page = $this->service->create($form);
//return $this->redirect(['view', 'id' => $page->id]);
} catch (\DomainException $e) {
//Yii::$app->errorHandler->logException($e);
//Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return '';
}
public function actionLanguage($language)
{
if ($language && in_array($language, array_keys(Yii::$app->params['backendTranslatedLanguages']))) {
$this->service->setBackendLanguage($language);
}
return $this->redirect(Yii::$app->request->referrer);
$this->_service->setBackendLanguage($language);
}
return $this->redirect(Yii::$app->request->referrer);
}
public function beforeAction($action)
{
if ($action->id === 'error') {
$this->layout = 'error';
}
return parent::beforeAction($action);
}
public function beforeAction($action)
{
if ($action->id === 'error') {
$this->layout = 'error';
}
return parent::beforeAction($action);
}
}

114
backend/controllers/SliderController.php

@ -12,15 +12,14 @@ use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
class SliderController extends Controller
{
private $service;
private $_service;
public function __construct($id, $module, SliderService $service, $config = [])
{
parent::__construct($id, $module, $config);
$this->service = $service;
$this->_service = $service;
}
/**
@ -29,22 +28,22 @@ class SliderController extends Controller
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['create', 'view', 'index', 'update', 'delete'],
'allow' => true,
'roles' => ['SliderManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['create', 'view', 'index', 'update', 'delete'],
'allow' => true,
'roles' => ['SliderManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
@ -56,30 +55,30 @@ class SliderController extends Controller
{
//$searchModel = new UserSearch();
//$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$query = Slider::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 20,
],
'sort' => [
'defaultOrder' => [
'id' => SORT_ASC,
]
],
]);
$query = Slider::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 20,
],
'sort' => [
'defaultOrder' => [
'id' => SORT_ASC,
]
],
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
/**
* @param $id
*
* @return string
* @throws NotFoundHttpException
*/
/**
* @param $id
*
* @return string
* @throws NotFoundHttpException
*/
public function actionView($id)
{
return $this->render('view', [
@ -94,57 +93,62 @@ class SliderController extends Controller
*/
public function actionCreate()
{
$form = new SliderForm();
$form = new SliderForm();
$form->scenario = Slider::SCENARIO_CREATE;
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$slider = $this->service->create($form);
$slider = $this->_service->create($form);
return $this->redirect(['view', 'id' => $slider->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('create', [
'model' => $form,
]);
}
/**
* @param $id
*
* @return string|\yii\web\Response
* @throws NotFoundHttpException
*/
/**
* @param $id
*
* @return string|\yii\web\Response
* @throws NotFoundHttpException
*/
public function actionUpdate($id)
{
$slider = $this->findModel($id);
$form = new SliderForm($slider);
$form->scenario = Slider::SCENARIO_UPDATE;
$form = new SliderForm($slider);
$form->scenario = Slider::SCENARIO_UPDATE;
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->edit($slider->id, $form);
$this->_service->edit($slider->id, $form);
return $this->redirect(['view', 'id' => $slider->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('update', [
'model' => $form,
'model' => $form,
'slider' => $slider,
]);
}
/**
* @param $id
*
* @return \yii\web\Response
*/
/**
* @param $id
*
* @return \yii\web\Response
*/
public function actionDelete($id)
{
$this->service->remove($id);
$this->_service->remove($id);
return $this->redirect(['index']);
}

140
backend/controllers/UserController.php

@ -20,14 +20,14 @@ use yii\web\UploadedFile;
*/
class UserController extends Controller
{
private $service;
private $profile_service;
private $_service;
private $_profile_service;
public function __construct($id, $module, UserManageService $service, ProfileService $profile_service, $config = [])
{
parent::__construct($id, $module, $config);
$this->service = $service;
$this->profile_service = $profile_service;
$this->_service = $service;
$this->_profile_service = $profile_service;
}
/**
@ -36,27 +36,27 @@ class UserController extends Controller
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['create','view','index', 'update', 'delete'],
'allow' => true,
'roles' => ['UserManagement'],
],
[
'actions' => ['profile'],
'allow' => true,
'roles' => ['@'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['create', 'view', 'index', 'update', 'delete'],
'allow' => true,
'roles' => ['UserManagement'],
],
[
'actions' => ['profile'],
'allow' => true,
'roles' => ['@'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
@ -70,21 +70,21 @@ class UserController extends Controller
*/
public function actionIndex()
{
$searchModel = new UserSearch();
$searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* @param $id
*
* @return string
* @throws NotFoundHttpException
*/
/**
* @param $id
*
* @return string
* @throws NotFoundHttpException
*/
public function actionView($id)
{
return $this->render('view', [
@ -102,24 +102,26 @@ class UserController extends Controller
$form = new UserForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$user = $this->service->create($form);
$user = $this->_service->create($form);
return $this->redirect(['view', 'id' => $user->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('create', [
'model' => $form,
]);
}
/**
* @param $id
*
* @return string|\yii\web\Response
* @throws NotFoundHttpException
*/
/**
* @param $id
*
* @return string|\yii\web\Response
* @throws NotFoundHttpException
*/
public function actionUpdate($id)
{
$user = $this->findModel($id);
@ -127,58 +129,66 @@ class UserController extends Controller
$form = new UserForm($user);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->edit($user->id, $form);
$this->_service->edit($user->id, $form);
return $this->redirect(['view', 'id' => $user->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('update', [
'model' => $form,
'user' => $user,
'user' => $user,
]);
}
/**
* Deletes an existing User model.
* If deletion is successful, the browser will be redirected to the 'index' page.
*
* @param integer $id
*
* @return mixed
*/
public function actionDelete($id)
{
$this->service->remove($id);
$this->_service->remove($id);
return $this->redirect(['index']);
}
public function actionProfile()
{
$user = $this->findModel(Yii::$app->user->id);
$form = new ProfileEditForm($user);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$form->user_pic = UploadedFile::getInstance($form, 'user_pic');
$this->profile_service->edit(Yii::$app->user->id, $form);
Yii::$app->session->setFlash('success', Yii::t('user', 'Profile is saved.'));
return $this->redirect(['/user/profile']);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('profile', [
'model' => $form,
'user' => $user,
]);
}
public function actionProfile()
{
$user = $this->findModel(Yii::$app->user->id);
$form = new ProfileEditForm($user);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$form->user_pic = UploadedFile::getInstance($form, 'user_pic');
$this->_profile_service->edit(Yii::$app->user->id, $form);
Yii::$app->session->setFlash('success', Yii::t('user', 'Profile is saved.'));
return $this->redirect(['/user/profile']);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('profile', [
'model' => $form,
'user' => $user,
]);
}
/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
*
* @param integer $id
*
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/

261
backend/controllers/settings/ListController.php

@ -6,7 +6,6 @@
namespace backend\controllers\settings;
use backend\forms\SettingsSearch;
use core\entities\Settings;
use core\forms\SettingsForm;
@ -20,131 +19,137 @@ use yii\web\NotFoundHttpException;
class ListController extends Controller
{
private $service;
public function __construct( string $id, $module, SettingsService $service, array $config = [] ) {
parent::__construct( $id, $module, $config );
$this->service = $service;
}
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
],
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['create','view','index', 'update', 'delete', 'toggle'],
'allow' => true,
'roles' => ['SettingsManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
];
}
public function actions()
{
return [
'toggle' => [
'class' => ToggleAction::class,
'modelClass' => Settings::class,
//'setFlash' => true,
]
];
}
public function actionIndex()
{
$searchModel = new SettingsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render(
'index',
[
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]
);
}
public function actionView($id)
{
return $this->render(
'view',
[
'model' => $this->findModel($id),
]
);
}
public function actionCreate()
{
$form = new SettingsForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$settings = $this->service->create($form);
return $this->redirect(['view', 'id' => $settings->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
else {
$form->active = 1;
}
return $this->render(
'create',
[
'model' => $form,
]
);
}
public function actionUpdate($id)
{
$settings = $this->findModel($id);
$form = new SettingsForm($settings);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->edit($settings->id, $form);
return $this->redirect(['view', 'id' => $settings->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render(
'update',
[
'model' => $form,
'settings' => $settings,
]
);
}
public function actionDelete($id)
{
$this->service->remove($id);
return $this->redirect(['index']);
}
protected function findModel($id)
{
if (($model = Settings::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
private $_service;
public function __construct(string $id, $module, SettingsService $service, array $config = [])
{
parent::__construct($id, $module, $config);
$this->_service = $service;
}
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'delete' => ['POST'],
],
],
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['create', 'view', 'index', 'update', 'delete', 'toggle'],
'allow' => true,
'roles' => ['SettingsManagement'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
];
}
public function actions()
{
return [
'toggle' => [
'class' => ToggleAction::class,
'modelClass' => Settings::class,
//'setFlash' => true,
]
];
}
public function actionIndex()
{
$searchModel = new SettingsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render(
'index',
[
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]
);
}
public function actionView($id)
{
return $this->render(
'view',
[
'model' => $this->findModel($id),
]
);
}
public function actionCreate()
{
$form = new SettingsForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$settings = $this->_service->create($form);
return $this->redirect(['view', 'id' => $settings->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
} else {
$form->active = 1;
}
return $this->render(
'create',
[
'model' => $form,
]
);
}
public function actionUpdate($id)
{
$settings = $this->findModel($id);
$form = new SettingsForm($settings);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->_service->edit($settings->id, $form);
return $this->redirect(['view', 'id' => $settings->id]);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render(
'update',
[
'model' => $form,
'settings' => $settings,
]
);
}
public function actionDelete($id)
{
$this->_service->remove($id);
return $this->redirect(['index']);
}
protected function findModel($id)
{
if (($model = Settings::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}

81
backend/views/role/view.php

@ -1,4 +1,5 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
use kartik\select2\Select2;
@ -12,7 +13,7 @@ use kartik\form\ActiveForm;
/* @var $permissionsSelected array */
/* @var $itemsForm \backend\forms\rbac\RbacUpdateChildren */
$this->title = $model->name;
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Roles'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
@ -23,9 +24,9 @@ $this->params['breadcrumbs'][] = $this->title;
<?= Html::a(Yii::t('buttons', 'Edit'), ['update', 'id' => $model->name], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('buttons', 'Delete'), ['delete', 'id' => $model->name], [
'class' => 'btn btn-danger',
'data' => [
'data' => [
'confirm' => Yii::t('buttons', 'Are you sure you want to delete this item?'),
'method' => 'post',
'method' => 'post',
],
]) ?>
</p>
@ -33,19 +34,19 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="box box-default">
<div class="box-body">
<?= DetailView::widget([
'model' => $model,
'model' => $model,
'attributes' => [
[
'attribute' => 'name',
'label' => Yii::t('user', 'Role Name'),
'label' => Yii::t('user', 'Role Name'),
],
[
'attribute' => 'description',
'label' => Yii::t('user', 'Role Description'),
'label' => Yii::t('user', 'Role Description'),
],
[
'attribute' => 'ruleName',
'label' => Yii::t('user', 'Rule Name'),
'label' => Yii::t('user', 'Rule Name'),
],
],
]) ?>
@ -53,44 +54,54 @@ $this->params['breadcrumbs'][] = $this->title;
</div>
<?php if ($model->name !== 'admin'): ?>
<?php if ($model->name !== 'admin') : ?>
<h4><?= Yii::t('user', 'Contains roles') ?></h4>
<?php $form = ActiveForm::begin(); ?>
<h4><?= Yii::t('user', 'Contains roles') ?></h4>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($itemsForm, 'roles')->widget(
Select2::classname(), [
'name' => 'childrenRoles',
'data' => $roles,
'size' => Select2::SMALL,
'options' => ['placeholder' => Yii::t('user', 'Select role...'), 'multiple' => true],
'pluginOptions' => [
'allowClear' => true
],
])->label(false);
?>
<?= $form->field($itemsForm, 'roles')->widget(
Select2::class,
[
'name' => 'childrenRoles',
'data' => $roles,
'size' => Select2::SMALL,
'options' => [
'placeholder' => Yii::t('user', 'Select role...'),
'multiple' => true,
],
'pluginOptions' => [
'allowClear' => true
],
]
)->label(false);
?>
<h4><?= Yii::t('user', 'Permissions') ?></h4>
<h4><?= Yii::t('user', 'Permissions') ?></h4>
<?= $form->field($itemsForm, 'permissions')->widget(
Select2::classname(), [
'name' => 'childrenPermissions',
'data' => $permissions,
'size' => Select2::SMALL,
'options' => ['placeholder' => Yii::t('user', 'Select permission...'), 'multiple' => true],
<?= $form->field($itemsForm, 'permissions')->widget(
Select2::class,
[
'name' => 'childrenPermissions',
'data' => $permissions,
'size' => Select2::SMALL,
'options' => [
'placeholder' => Yii::t('user', 'Select permission...'),
'multiple' => true
],
'pluginOptions' => [
'allowClear' => true
],
])->label(false);
?>
]
)->label(false);
?>
<div class="form-group">
<?= Html::submitButton(Yii::t('buttons', 'Save'), ['class' => 'btn btn-primary']) ?>
</div>
<div class="form-group">
<?= Html::submitButton(Yii::t('buttons', 'Save'), ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
<?php ActiveForm::end(); ?>
<?php else: ?>
<?php else : ?>
<div class="callout callout-warning">
<?= Yii::t('user', 'Administrator has full access rules') ?>
</div>

43
console/controllers/ModuleController.php

@ -0,0 +1,43 @@
<?php
/**
* Created by Error202
* Date: 04.09.2018
*/
namespace console\controllers;
use core\entities\ModuleRecord;
use core\services\ModuleService;
use yii\console\Controller;
/**
* Modules management from console
* Class ModuleController
* @package console\controllers
*/
class ModuleController extends Controller
{
/**
* @var ModuleService Modules management service
*/
private $_service;
public function __construct(string $id, $module, ModuleService $service, array $config = [])
{
parent::__construct($id, $module, $config);
$this->_service = $service;
}
/**
* Activate module and apply it migration if needed
* @param $name
*/
public function actionActivate($name)
{
$module = ModuleRecord::find()->andWhere(['name' => $name])->one();
if ($module || $module->isDisabled()) {
$this->_service->enable($module);
}
}
}

39
console/controllers/PermissionController.php

@ -0,0 +1,39 @@
<?php
/**
* Created by Error202
* Date: 04.09.2018
*/
namespace console\controllers;
use core\services\PermissionManager;
use yii\console\Controller;
/**
* Permissions management from console
* Class PermissionController
* @package console\controllers
*/
class PermissionController extends Controller
{
/**
* @var PermissionManager Permissions management service
*/
private $_service;
public function __construct(string $id, $module, PermissionManager $service, array $config = [])
{
parent::__construct($id, $module, $config);
$this->_service = $service;
}
/**
* Create permission
* @param $name
* @param null $description
*/
public function actionAdd($name, $description = null) : void
{
$this->_service->create($name, $description);
}
}

8
console/controllers/UserController.php

@ -31,8 +31,6 @@ class UserController extends Controller
$password = $this->prompt('Password:', ['required' => true]);
$role = $this->select('Role:', ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'description'));
//$this->findModel($username, $email);
$form = new UserForm();
$form->username = $username;
$form->email = $email;
@ -50,12 +48,6 @@ class UserController extends Controller
foreach ($form->errors as $error) {
$this->stdout(is_string($error) ? $error : $error[0] . PHP_EOL);
}
//$this->stdout(print_r($form->errors, true) . PHP_EOL);
/*
$user = User::create($username, $email, $phone, $password);
$user->save();*/
}
public function actionAddAdmin($username, $email, $password)

91
core/entities/Settings.php

@ -6,6 +6,10 @@
namespace core\entities;
use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
/**
* @property integer $id
* @property string $type
@ -17,55 +21,52 @@ namespace core\entities;
* @property integer $updated_at
*/
use Yii;
use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
class Settings extends ActiveRecord
{
public static function tableName(): string
{
return '{{%settings}}';
}
public static function tableName(): string
{
return '{{%settings}}';
}
public function attributeLabels()
{
return [
'id' => Yii::t('main', 'ID'),
'type' => Yii::t('main', 'Type'),
'section' => Yii::t('main', 'Section'),
'key' => Yii::t('main', 'Key'),
'value' => Yii::t('main', 'Value'),
'active' => Yii::t('main', 'Active'),
'created_at' => Yii::t('main', 'Created At'),
'updated_at' => Yii::t('main', 'Updated At'),
];
}
public function attributeLabels()
{
return [
'id' => Yii::t('main', 'ID'),
'type' => Yii::t('main', 'Type'),
'section' => Yii::t('main', 'Section'),
'key' => Yii::t('main', 'Key'),
'value' => Yii::t('main', 'Value'),
'active' => Yii::t('main', 'Active'),
'created_at' => Yii::t('main', 'Created At'),
'updated_at' => Yii::t('main', 'Updated At'),
];
}
public static function create($type, $section, $key, $value, $active): self
{
$settings = new static();
$settings->type = $type;
$settings->section = $section;
$settings->key = $key;
$settings->value = $value;
$settings->active = $active;
public static function create($type, $section, $key, $value, $active): self
{
$settings = new static();
$settings->type = $type;
$settings->section = $section;
$settings->key = $key;
$settings->value = $value;
$settings->active = $active;
return $settings;
}
return $settings;
}
public function edit($type, $section, $key, $value, $active): void
{
$this->type = $type;
$this->section = $section;
$this->key = $key;
$this->value = $value;
$this->active = $active;
}
public function edit($type, $section, $key, $value, $active): void
{
$this->type = $type;
$this->section = $section;
$this->key = $key;
$this->value = $value;
$this->active = $active;
}
public function behaviors(): array
{
return [
TimestampBehavior::class,
];
}
public function behaviors(): array
{
return [
TimestampBehavior::class,
];
}
}

25
core/services/SettingsService.php

@ -8,11 +8,11 @@ use core\repositories\SettingsRepository;
class SettingsService
{
private $repository;
private $_repository;
public function __construct(SettingsRepository $repository)
{
$this->repository = $repository;
$this->_repository = $repository;
}
public function create(SettingsForm $form): Settings
@ -24,26 +24,27 @@ class SettingsService
$form->value,
$form->active
);
$this->repository->save($settings);
$this->_repository->save($settings);
return $settings;
}
public function edit($id, SettingsForm $form): void
{
$settings = $this->repository->get($id);
$settings = $this->_repository->get($id);
$settings->edit(
$form->type,
$form->section,
$form->key,
$form->value,
$form->active
$form->type,
$form->section,
$form->key,
$form->value,
$form->active
);
$this->repository->save($settings);
$this->_repository->save($settings);
}
public function remove($id): void
{
$settings = $this->repository->get($id);
$this->repository->remove($settings);
$settings = $this->_repository->get($id);
$this->_repository->remove($settings);
}
}

29
core/services/user/UserManageService.php

@ -19,13 +19,13 @@ class UserManageService
*/
//private $newsletter;
/**
* UserManageService constructor.
*
* @param UserRepository $repository
* @param RoleManager $roles
* @param TransactionManager $transaction
*/
/**
* UserManageService constructor.
*
* @param UserRepository $repository
* @param RoleManager $roles
* @param TransactionManager $transaction
*/
public function __construct(
UserRepository $repository,
RoleManager $roles,
@ -33,8 +33,8 @@ class UserManageService
//Newsletter $newsletter
)
{
$this->repository = $repository;
$this->roles = $roles;
$this->repository = $repository;
$this->roles = $roles;
$this->transaction = $transaction;
//$this->newsletter = $newsletter;
}
@ -51,6 +51,7 @@ class UserManageService
$this->roles->assign($user->id, $form->role);
//$this->newsletter->subscribe($user->email);
});
return $user;
}
@ -70,11 +71,11 @@ class UserManageService
public function setBackendLanguage($language): void
{
if (in_array($language, array_keys(\Yii::$app->params['backendTranslatedLanguages']))) {
$user = $this->repository->get(\Yii::$app->user->id);
$user->backend_language = $language;
$this->repository->save($user);
}
if (in_array($language, array_keys(\Yii::$app->params['backendTranslatedLanguages']))) {
$user = $this->repository->get(\Yii::$app->user->id);
$user->backend_language = $language;
$this->repository->save($user);
}
}
public function assignRole($id, $role): void

210
frontend/config/main.php

@ -7,121 +7,121 @@ $params = array_merge(
);
return [
'id' => 'app-frontend',
'language' => 'ru',
'basePath' => dirname(__DIR__),
'bootstrap' => [
'log',
'common\bootstrap\SetUp',
'frontend\bootstrap\SetUp',
'id' => 'app-frontend',
'language' => 'ru',
'basePath' => dirname(__DIR__),
'bootstrap' => [
'log',
'common\bootstrap\SetUp',
'frontend\bootstrap\SetUp',
],
'aliases' => [
'@staticRoot' => $params['staticPath'],
'@static' => $params['staticHostInfo'],
'aliases' => [
'@staticRoot' => $params['staticPath'],
'@static' => $params['staticHostInfo'],
],
'controllerNamespace' => 'frontend\controllers',
'components' => [
'request' => [
'baseUrl' => '',
'csrfParam' => '_csrf-frontend',
'cookieValidationKey' => $params['cookieValidationKey'],
],
'user' => [
'identityClass' => 'common\auth\Identity',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity', 'httpOnly' => true, 'domain' => $params['cookieDomain']],
'loginUrl' => ['auth/auth/login'],
],
'session' => [
'name' => '_session',
'class' => 'yii\web\DbSession',
'writeCallback' => function($session){
return [
'user_id' => Yii::$app->user->id
];
},
'cookieParams' => [
'domain' => $params['cookieDomain'],
'httpOnly' => true,
],
],
'log' => [
'components' => [
'request' => [
'baseUrl' => '',
'csrfParam' => '_csrf-frontend',
'cookieValidationKey' => $params['cookieValidationKey'],
],
'user' => [
'identityClass' => 'common\auth\Identity',
'enableAutoLogin' => true,
'identityCookie' => ['name' => '_identity', 'httpOnly' => true, 'domain' => $params['cookieDomain']],
'loginUrl' => ['auth/auth/login'],
],
'session' => [
'name' => '_session',
'class' => 'yii\web\DbSession',
'writeCallback' => function ($session) {
return [
'user_id' => Yii::$app->user->id
];
},
'cookieParams' => [
'domain' => $params['cookieDomain'],
'httpOnly' => true,
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorHandler' => [
'errorAction' => 'site/error',
],
'backendUrlManager' => require __DIR__ . '/../../backend/config/urlManager.php',
'frontendUrlManager' => require __DIR__ . '/urlManager.php',
'urlManager' => function () {
return Yii::$app->get('frontendUrlManager');
},
'i18n' => [
'translations' => [
'post' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages',
],
'slider' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages',
],
'auth' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages',
],
'user' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages',
],
'main' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages',
],
],
],
'view' => [
'theme' => [
'basePath' => '@webroot/themes/sport',
'baseUrl' => '@web/themes/sport',
'pathMap' => [
'@frontend/views' => '@webroot/themes/sport',
'@frontend/widgets' => '@webroot/themes/sport/widgets',
],
],
],
'assetManager' => [
'bundles' => [
'yii\web\JqueryAsset' => [
'sourcePath' => '@frontend/assets/libs/jquery321', // do not publish the bundle
'js' => [
YII_ENV_DEV ? 'jquery-3.2.1.js' : 'jquery-3.2.1.min.js'
],
],
'yii\bootstrap\BootstrapAsset' => [
'sourcePath' => '@frontend/assets/libs/bootstrap4/css', // do not publish the bundle
'css' => [
YII_ENV_DEV ? 'bootstrap.css' : 'bootstrap.min.css'
],
],
'yii\bootstrap\BootstrapPluginAsset' => [
'sourcePath' => '@frontend/assets/libs/bootstrap4/js', // do not publish the bundle
'js' => [
YII_ENV_DEV ? 'bootstrap.js' : 'bootstrap.min.js'
],
'depends' => [
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset',
],
],
],
],
'backendUrlManager' => require __DIR__ . '/../../backend/config/urlManager.php',
'frontendUrlManager' => require __DIR__ . '/urlManager.php',
'urlManager' => function () {
return Yii::$app->get('frontendUrlManager');
},
'i18n' => [
'translations' => [
'post' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages',
],
'slider' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages',
],
'auth' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages',
],
'user' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages',
],
'main' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@frontend/messages',
],
],
],
'view' => [
'theme' => [
'basePath' => '@webroot/themes/sport',
'baseUrl' => '@web/themes/sport',
'pathMap' => [
'@frontend/views' => '@webroot/themes/sport',
'@frontend/widgets' => '@webroot/themes/sport/widgets',
],
],
],
'assetManager' => [
'bundles' => [
'yii\web\JqueryAsset' => [
'sourcePath' => '@frontend/assets/libs/jquery321', // do not publish the bundle
'js' => [
YII_ENV_DEV ? 'jquery-3.2.1.js' : 'jquery-3.2.1.min.js'
],
],
'yii\bootstrap\BootstrapAsset' => [
'sourcePath' => '@frontend/assets/libs/bootstrap4/css', // do not publish the bundle
'css' => [
YII_ENV_DEV ? 'bootstrap.css' : 'bootstrap.min.css'
],
],
'yii\bootstrap\BootstrapPluginAsset' => [
'sourcePath' => '@frontend/assets/libs/bootstrap4/js', // do not publish the bundle
'js' => [
YII_ENV_DEV ? 'bootstrap.js' : 'bootstrap.min.js'
],
'depends' => [
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset',
],
],
],
],
],
'params' => $params,
'params' => $params,
];

11
frontend/controllers/ContactController.php

@ -1,4 +1,5 @@
<?php
namespace frontend\controllers;
use core\services\ContactService;
@ -8,14 +9,14 @@ use core\forms\ContactForm;
class ContactController extends FrontendController
{
public $layout = 'blank';
public $layout = 'blank';
private $service;
private $_service;
public function __construct($id, $module, ContactService $service, $config = [])
{
parent::__construct($id, $module, $config);
$this->service = $service;
$this->_service = $service;
}
public function actionIndex()
@ -23,13 +24,15 @@ class ContactController extends FrontendController
$form = new ContactForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->send($form);
$this->_service->send($form);
Yii::$app->session->setFlash('success', Yii::t('main', 'Thank you for contacting us. We will respond to you as soon as possible.'));
return $this->goHome();
} catch (\Exception $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', Yii::t('main', 'There was an error sending your message.'));
}
return $this->refresh();
}

69
frontend/controllers/SiteController.php

@ -1,4 +1,5 @@
<?php
namespace frontend\controllers;
use core\forms\SubscribeForm;
@ -14,14 +15,15 @@ use Yii;
*/
class SiteController extends FrontendController
{
public $newletter;
public $newletter;
public function __construct( string $id, $module, Newsletter $newsletter, array $config = [] ) {
parent::__construct( $id, $module, $config );
$this->newletter = $newsletter;
}
public function __construct(string $id, $module, Newsletter $newsletter, array $config = [])
{
parent::__construct($id, $module, $config);
$this->newletter = $newsletter;
}
/**
/**
* @inheritdoc
*/
public function behaviors()
@ -29,21 +31,21 @@ class SiteController extends FrontendController
return [
'access' => [
'class' => AccessControl::class,
'only' => ['subscribe'],
'only' => ['subscribe'],
'rules' => [
[
'actions' => ['subscribe'],
'allow' => true,
],
[
'actions' => ['subscribe'],
'allow' => true,
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'logout' => ['post'],
],
],
SiteAccess::class,
SiteAccess::class,
];
}
@ -53,13 +55,13 @@ class SiteController extends FrontendController
public function actions()
{
return [
'error' => [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
'transparent' => true,
'transparent' => true,
],
];
}
@ -71,24 +73,25 @@ class SiteController extends FrontendController
*/
public function actionIndex()
{
$this->layout = 'home';
$this->layout = 'home';
return $this->render('index');
}
public function actionSubscribe()
{
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$form = new SubscribeForm();
if(Yii::$app->request->isAjax && $form->load(Yii::$app->request->post())){
try {
$this->newletter->subscribe( $form->email );
return [ 'result' => 'success' ];
}
catch (\RuntimeException $e) {
return [ 'result' => 'error', 'message' => $e->getMessage() ];
}
}
return ['result' => 'error', 'message' => 'Request error'];
}
public function actionSubscribe()
{
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$form = new SubscribeForm();
if (Yii::$app->request->isAjax && $form->load(Yii::$app->request->post())) {
try {
$this->newletter->subscribe($form->email);
return ['result' => 'success'];
} catch (\RuntimeException $e) {
return ['result' => 'error', 'message' => $e->getMessage()];
}
}
return ['result' => 'error', 'message' => 'Request error'];
}
}

29
frontend/controllers/account/ProfileController.php

@ -6,7 +6,6 @@
namespace frontend\controllers\account;
use frontend\components\FrontendController;
use core\services\user\ProfileService;
use core\forms\user\ProfileEditForm;
@ -17,14 +16,14 @@ use Yii;
class ProfileController extends FrontendController
{
public $layout = 'profile';
public $layout = 'profile';
private $service;
private $_service;
public function __construct($id, $module, ProfileService $service, $config = [])
{
parent::__construct($id, $module, $config);
$this->service = $service;
$this->_service = $service;
}
public function behaviors(): array
@ -32,22 +31,22 @@ class ProfileController extends FrontendController
return [
'access' => [
'class' => AccessControl::class,
'only' => ['index'],
'only' => ['index'],
'rules' => [
[
'actions' => ['edit', 'social'],
'allow' => true,
'roles' => ['@'],
'allow' => true,
'roles' => ['@'],
],
],
],
];
}
/**
* @return string|\yii\web\Response
* @throws NotFoundHttpException
*/
/**
* @return string|\yii\web\Response
* @throws NotFoundHttpException
*/
public function actionEdit()
{
$user = $this->findModel(Yii::$app->user->id);
@ -55,17 +54,19 @@ class ProfileController extends FrontendController
$form = new ProfileEditForm($user);
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->edit($user->id, $form);
$this->_service->edit($user->id, $form);
Yii::$app->session->setFlash('success', Yii::t('user', 'Profile is saved.'));
return $this->redirect(['/account/profile/edit']);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('edit', [
'model' => $form,
'user' => $user,
'user' => $user,
]);
}
@ -77,7 +78,9 @@ class ProfileController extends FrontendController
/**
* Finds the User model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
*
* @param integer $id
*
* @return User the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/

56
frontend/controllers/auth/AuthController.php

@ -1,4 +1,5 @@
<?php
namespace frontend\controllers\auth;
use common\auth\Identity;
@ -12,38 +13,38 @@ class AuthController extends Controller
{
public $layout = 'auth';
private $service;
private $_service;
public function __construct($id, $module, AuthService $service, $config = [])
{
parent::__construct($id, $module, $config);
$this->service = $service;
$this->_service = $service;
}
public function behaviors(): array
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['login'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
];
}
public function behaviors(): array
{
return [
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'actions' => ['login'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
[ // all the action are accessible to admin
'allow' => true,
'roles' => ['admin'],
],
],
],
];
}
/**
* @return mixed
@ -57,8 +58,9 @@ class AuthController extends Controller
$form = new LoginForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$user = $this->service->auth($form);
$user = $this->_service->auth($form);
Yii::$app->user->login(new Identity($user), $form->rememberMe ? Yii::$app->params['user.rememberMeDuration'] : 0);
return $this->goBack();
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);

6
frontend/controllers/auth/NetworkController.php

@ -12,12 +12,12 @@ use yii\web\Controller;
class NetworkController extends Controller
{
private $service;
private $_service;
public function __construct($id, $module, NetworkService $service, $config = [])
{
parent::__construct($id, $module, $config);
$this->service = $service;
$this->_service = $service;
}
public function actions()
@ -37,7 +37,7 @@ class NetworkController extends Controller
$identity = ArrayHelper::getValue($attributes, 'id');
try {
$user = $this->service->auth($network, $identity);
$user = $this->_service->auth($network, $identity);
Yii::$app->user->login(new Identity($user), Yii::$app->params['user.rememberMeDuration']);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);

10
frontend/controllers/auth/ResetController.php

@ -12,12 +12,12 @@ class ResetController extends Controller
{
public $layout = 'auth';
private $service;
private $_service;
public function __construct($id, $module, PasswordResetService $service, $config = [])
{
parent::__construct($id, $module, $config);
$this->service = $service;
$this->_service = $service;
}
/**
@ -28,7 +28,7 @@ class ResetController extends Controller
$form = new PasswordResetRequestForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->request($form);
$this->_service->request($form);
Yii::$app->session->setFlash('success', Yii::t('auth', 'Check your email for further instructions.'));
return $this->goHome();
} catch (\DomainException $e) {
@ -50,7 +50,7 @@ class ResetController extends Controller
public function actionConfirm($token)
{
try {
$this->service->validateToken($token);
$this->_service->validateToken($token);
} catch (\DomainException $e) {
throw new BadRequestHttpException($e->getMessage());
}
@ -58,7 +58,7 @@ class ResetController extends Controller
$form = new ResetPasswordForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->reset($token, $form);
$this->_service->reset($token, $form);
Yii::$app->session->setFlash('success', Yii::t('auth', 'New password saved.'));
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);

21
frontend/controllers/auth/SignupController.php

@ -1,4 +1,5 @@
<?php
namespace frontend\controllers\auth;
use core\services\auth\SignupService;
@ -11,25 +12,25 @@ class SignupController extends Controller
{
public $layout = 'auth';
private $service;
private $_service;
public function __construct($id, $module, SignupService $service, $config = [])
{
parent::__construct($id, $module, $config);
$this->service = $service;
$this->_service = $service;
}
public function behaviors(): array
{
return [
'access' => [
'class' => AccessControl::className(),
'class' => AccessControl::class,
//'only' => ['index'],
'rules' => [
[
'actions' => ['request', 'confirm'],
'allow' => true,
'roles' => ['?'],
'allow' => true,
'roles' => ['?'],
],
],
],
@ -44,10 +45,11 @@ class SignupController extends Controller
$form = new SignupForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->signup($form);
$this->_service->signup($form);
Yii::$app->session->setFlash('success', Yii::t('auth', 'Check your email for further instructions.'));
//return $this->goHome();
return $this->redirect(['auth/auth/login']);
return $this->redirect(['auth/auth/login']);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
@ -61,18 +63,21 @@ class SignupController extends Controller
/**
* @param $token
*
* @return mixed
*/
public function actionConfirm($token)
{
try {
$this->service->confirm($token);
$this->_service->confirm($token);
Yii::$app->session->setFlash('success', Yii::t('auth', 'Your email is confirmed.'));
return $this->redirect(['auth/auth/login']);
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
return $this->goHome();
}
}

167
setup.php

@ -60,6 +60,10 @@ class Setup
'Admin account complete' => 'Аккаунт администратора создан',
'Prepare MySQL tables' => 'Подготовка MySQL таблиц',
'Complete' => 'Готово',
'Server HTTP configuration' => 'Конфигурация HTTP сервера',
'Does your server use Apache? [y]: ' => 'Ваш сервер использует Apache? [y]: ',
'Creating permissions' => 'Создание разрешений',
'Activating modules' => 'Активация модулей',
],
];
@ -95,6 +99,16 @@ class Setup
// setup domain data
$this->setConfigDomains();
// install modules
$this->activateSystemModules();
// install system permissions
$this->addPermissions();
// apache htaccess
$this->apache();
echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Installation complete'), 'yellow') . PHP_EOL;
echo PHP_EOL;
@ -104,7 +118,7 @@ class Setup
echo '---------------------' . PHP_EOL;
}
private function selectType()
private function selectType() : void
{
echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Select initialization type'), 'white') . PHP_EOL;
@ -114,7 +128,7 @@ class Setup
$this->_type = readline($this->l('Type [p]: ')) ?: 'p';
}
private function selectLanguage()
private function selectLanguage() : void
{
echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Select installer language'), 'white') . PHP_EOL;
@ -124,7 +138,7 @@ class Setup
$this->_language = readline($this->l('Language [en]: ')) ?: 'en';
}
private function setupMySQL(): bool
private function setupMySQL() : bool
{
echo '---------------------' . PHP_EOL;
echo Console::log($this->l('MySQL settings'), 'white') . PHP_EOL;
@ -141,7 +155,7 @@ class Setup
return $this->checkDatabaseConnection();
}
private function checkDatabaseConnection(): bool
private function checkDatabaseConnection() : bool
{
try {
$this->_db_connection = new \PDO('mysql:host=' . $this->_db_host . ';dbname=' . $this->_db_name, $this->_db_user, $this->_db_pass);
@ -152,7 +166,7 @@ class Setup
}
}
private function setConfigMySQL()
private function setConfigMySQL() : void
{
$mysql_line = 'mysql:host=' . $this->_db_host . ';dbname=' . $this->_db_name;
$file = __DIR__ . '/common/config/main-local.php';
@ -163,7 +177,7 @@ class Setup
file_put_contents($file, $content);
}
private function setConfigDomains()
private function setConfigDomains() : void
{
echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Set your HTTP protocol (http/https)'), 'white') . PHP_EOL;
@ -196,7 +210,7 @@ class Setup
file_put_contents($file, $content);
}
private function addAdmin(): void
private function addAdmin() : void
{
echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Create admin account'), 'white') . PHP_EOL;
@ -227,13 +241,13 @@ class Setup
echo Console::log($this->l('Admin account complete'), 'green') . PHP_EOL;
}
private function trueEmail($email): bool
private function trueEmail($email) : bool
{
$email = filter_var($email, FILTER_VALIDATE_EMAIL);
return $email ? true : false;
}
private function runMigrations(): void
private function runMigrations() : void
{
echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Prepare MySQL tables'), 'white') . PHP_EOL;
@ -242,6 +256,141 @@ class Setup
echo Console::log($this->l('Complete'), 'green') . PHP_EOL;
}
private function apache() : void
{
echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Server HTTP configuration'), 'white') . PHP_EOL;
echo '---------------------' . PHP_EOL;
$apache = readline($this->l('Does your server use Apache? [yes]: ')) ?: 'y';
if ($apache == 'y' || $apache == 'yes') {
$this->prepareHtaccess();
}
}
private function prepareHtaccess() : void
{
// main
$ssh_rules = <<<SSH
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://{$this->_domain}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(www\.)+(.*)$ [NC]
RewriteRule (.*) https://{$this->_domain}%{REQUEST_URI} [L,R=301]
SSH;
$ssh_rules = $this->_http_protocol == 'https' ? $ssh_rules : '';
$main_htacces = <<<MH
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
{$ssh_rules}
#static
RewriteCond %{HTTP_HOST} ^static.{$this->_domain}
RewriteRule ^(.*)$ zxcms/static/$1 [L]
#RewriteCond %{HTTP_HOST} ^static.{$this->_domain}
#RewriteRule ^(.*)$ $1 [L]
RewriteCond %{HTTP_HOST} ^admin.{$this->_domain}
RewriteRule ^(.*)$ zxcms/backend/web/$1 [L]
# if /admin - backend
RewriteCond %{HTTP_HOST} ^admin.{$this->_domain}
RewriteRule ^assets/(.*)$ zxcms/backend/web/assets/$1 [L]
RewriteCond %{HTTP_HOST} ^admin.{$this->_domain}
RewriteRule ^css/(.*)$ zxcms/backend/web/css/$1 [L]
RewriteCond %{HTTP_HOST} ^admin.{$this->_domain}
RewriteRule ^js/(.*)$ zxcms/backend/web/js/$1 [L]
RewriteCond %{REQUEST_URI} !^/zxcms/backend/web/(assets|js|css)/
RewriteCond %{HTTP_HOST} ^admin.{$this->_domain}
RewriteRule ^.*$ zxcms/backend/web/index.php [L]
#RewriteCond %{REQUEST_URI} !^/zxcms/static
RewriteCond %{REQUEST_URI} ^/(assets|css|js|images)
RewriteRule ^assets/(.*)$ zxcms/frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ zxcms/frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ zxcms/frontend/web/js/$1 [L]
RewriteRule ^images/(.*)$ zxcms/frontend/web/images/$1 [L]
RewriteRule ^(.*)$ zxcms/frontend/web/$1 [L]
#RewriteCond %{REQUEST_URI} !^/zxcms/static
RewriteCond %{REQUEST_URI} !^/zxcms/(frontend|backend)/web/(assets|css|js)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ zxcms/frontend/web/index.php
</IfModule>
MH;
file_put_contents(__DIR__ . '/../.htaccess', $main_htacces);
// backend, frontend
$bf_htaccess = <<<BF
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
BF;
file_put_contents(__DIR__ . '/backend/web/.htaccess', $bf_htaccess);
file_put_contents(__DIR__ . '/frontend/web/.htaccess', $bf_htaccess);
// static
$static_htaccess = <<<SH
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . {$this->_http_protocol}://{$this->_domain}/site/error [R=404,L]
ErrorDocument 404 {$this->_http_protocol}://{$this->_domain}/site/error
SH;
file_put_contents(__DIR__ . '/frontend/web/.htaccess', $static_htaccess);
}
private function addPermissions() : void
{
echo '---------------------' . PHP_EOL;
echo Console::log($this->l('Creating permissions'), 'white') . PHP_EOL;
echo '---------------------' . PHP_EOL;
$systemPermissions = [
'SettingsManagement' => 'Settings Management',
'MenuManagement' => 'Menu Management',
'ModuleManagement' => 'Modules Management',
'UserManagement' => 'Users Management',
'Dashboard' => 'Dashboard',
'SliderManagement' => 'Slider Management',
];
foreach ($systemPermissions as $name => $description) {
shell_exec('php ' . __DIR__ . '/yii permission/add "' . $name . '" "' . $description . '"');
}
echo Console::log($this->l('Complete'), 'green') . PHP_EOL;
}
private function activateSystemModules(): void
{
Console::log($this->l('Activating modules: '), 'white');
$systemModules = [
'languages', 'pages', 'forms', 'links'
];
foreach ($systemModules as $name) {
shell_exec('php ' . __DIR__ . '/yii module/add "' . $name . '"');
}
echo Console::log($this->l('Complete'), 'green') . PHP_EOL;
}
private function l($str): string
{
return isset($this->_l[$this->_language]) && isset($this->_l[$this->_language][$str]) ? $this->_l[$this->_language][$str] : $str;

Loading…
Cancel
Save