* @copyright (c), Thread */ class LoginController extends BackendController { public $name = 'login'; public $title = "Login"; public $layout = "@app/layouts/nologin"; public $defaultAction = 'index'; protected $model = SignInForm::class; /** * @inheritdoc */ public function behaviors() { return [ 'AccessControl' => [ 'class' => AccessControl::class, 'rules' => [ [ 'allow' => true, 'actions' => ['index', 'captcha', 'validation'], 'roles' => ['?'], ], [ 'allow' => false, ], ], ], ]; } /** * @inheritdoc */ public function actions() { return [ 'captcha' => [ 'class' => CaptchaAction::class, ], ]; } /** * @return string|\yii\web\Response */ public function actionIndex() { /** @var SignInForm $model */ $model = new $this->model; $model->setScenario('signIn'); $model->ONLY_ADMIN = true; if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) { return $this->goHome(); } else { return $this->render('index', [ 'model' => $model, ]); } } /** * Перевірка валідації моделі(-ей) * Має бути встановдений у моделі scenario 'backend' * @return mixed */ public function actionValidation() { /** @var Model $model */ $model = new $this->model; $model->setScenario('signIn'); $model->load(Yii::$app->getRequest()->post()); Yii::$app->getResponse()->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } }