Если кликаю по кнопке со ссылкой - /admin в админку переходит, но выдает ошибку "Не удалось проверить переданные данные"
main.php бэкэнда
Код: Выделить всё
<?php
$params = array_merge(
require __DIR__ . '/../../common/config/params.php',
require __DIR__ . '/../../common/config/params-local.php',
require __DIR__ . '/params.php',
require __DIR__ . '/params-local.php'
);
return [
'id' => 'app-backend',
'name' => '..."',
'language' => 'ru-RU',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'defaultRoute'=>'site/index',
'layout' => 'cp',
'modules' => [],
// 'homeUrl' => '/admin',
'components' => [
'request' => [
'baseUrl' => '/admin',
'cookieValidationKey' => $params['cookieValidationKey'],
'csrfParam' => '_csrf-backend',
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
// 'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
'identityCookie' => ['name' => '_identity', 'httpOnly' => true,
// 'domain' => $params['cookieDomain']
],
],
'session' => [
// this is the name of the session cookie used for login on the backend
// 'name' => 'advanced-backend',
'name' => 'advanced',
'cookieParams' =>[
'httpOnly' => true,
// 'domain' => $params['cookieDomain'],
]
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller>' => '<controller>/index'],
],
],
'params' => $params,
];
site/index бэкэнда
Код: Выделить всё
<?php
namespace backend\controllers;
use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use common\models\User;
/**
* Site controller
*/
class SiteController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['*'],
'rules' => [
[
'allow' => true,
'roles' => ['admin', 'manager'],
],
],
'denyCallback' => function () {
return Yii::$app->response->redirect(['./../../']);
},
],
];
}
/**
* {@inheritdoc}
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
/**
* Displays homepage.
*
* @return string
*/
public function actionIndex()
{
// if (!Yii::$app->getUser()->can('manager')) {
// return $this->redirect(Yii::$app->urlManager->createUrl('./../../'));
// }
return $this->render('index');
}
/**
* Login action.
*
* @return string
*/
public function actionLogin()
{
if (!Yii::$app->user->isGuest) {
return $this->goHome();
}
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
$model->password = '';
return $this->render('login', [
'model' => $model,
]);
}
}
//$g=User::findOne('22');
//$result = User::getPassword2($g->password, $g->password_hash); //9
/**
* Logout action.
*
* @return string
*/
public function actionLogout()
{
Yii::$app->user->logout();
return $this->redirect(Yii::$app->urlManager->createUrl('./../../'));
//return $this->goHome();
}
}
Код: Выделить всё
<div class="col-lg-12">
<?php if (Yii::$app->user->isGuest): ?>
<?php $form = ActiveForm::begin(['id' => 'login-form', 'fieldConfig' => ['enableLabel'=>false]]); ?>
<?= $form->field($model, 'password', ['enableLabel' => false])
->widget(\yii\widgets\MaskedInput::className(), [
'mask' => '9999-9999-99',
])
->textInput(array('placeholder' => 'xxxx-xxxx-xx', 'class'=>'form-control text-center')); ?>
<div class="form-group">
<?= Html::submitButton('Вход', ['class' => 'btn btn-success', 'name' => 'login-button']) ?>
</div>
<?php ActiveForm::end(); ?>
<?php elseif (Yii::$app->getUser()->can('manager')): ?>
<?= '<div class="form-group">'
//. Html::beginForm(['/site/logout'], 'post')
. Html::beginForm(['/admin'], 'post') . //вот кнопка перехода
. Html::submitButton(
'Вход (' . Yii::$app->user->identity->surname . ')',
['class' => 'btn btn-success', 'name' => 'login-button']
)
. Html::endForm()
. '</div>' ?>
<?php elseif (Yii::$app->getUser()->can('indexEdu')): ?>
<?= '<div class="form-group">'
//. Html::beginForm(['/site/logout'], 'post')
. Html::beginForm(['/edu/index'], 'post')
. Html::submitButton(
'Вход (' . Yii::$app->user->identity->surname . ')',
['class' => 'btn btn-success', 'name' => 'login-button']
)
. Html::endForm()
. '</div>' ?>
<?php endif ?>
</div>
Код: Выделить всё
<?php
$params = array_merge(
require __DIR__ . '/../../common/config/params.php',
require __DIR__ . '/../../common/config/params-local.php',
require __DIR__ . '/params.php',
require __DIR__ . '/params-local.php'
);
return [
'id' => 'app-frontend',
'language' => 'ru-RU',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'name' => '..."',
'controllerNamespace' => 'frontend\controllers',
'components' => [
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
'request' => [
'csrfParam' => '_csrf-frontend',
'cookieValidationKey' => $params['cookieValidationKey'],
'baseUrl' => ''
],
'user' => [
'identityClass' => 'common\models\User',
'enableAutoLogin' => true,
// 'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
'identityCookie' => ['name' => '_identity', 'httpOnly' => true,
// 'domain' => $params['cookieDomain']
],
],
'session' => [
// this is the name of the session cookie used for login on the frontend
// 'name' => 'advanced-frontend',
'name' => 'advanced',
'cookieParams' =>[
'httpOnly' => true,
// 'domain' => $params['cookieDomain'],
]
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller>' => '<controller>/index'
],
],
],
'params' => $params,
];