| 123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace app\controllers;
- use app\models\Login;
- use Yii;
- class LoginController extends \yii\web\Controller {
- public function beforeAction($action) {
- Yii::$app->getRequest()->enableCsrfValidation = false;
- return parent::beforeAction($action);
- }
- public function actionIndex() {
- if(\Yii::$app->getRequest()->isPost) {
- $model = new Login();
- if ($model->load(Yii::$app->request->getBodyParams(), '') && $model->login()) {
- \Yii::$app->getResponse()->format = \yii\web\Response::FORMAT_JSON;
- return ['success' => true];
- }
- return ['success' => false, 'errors' => $model->getErrors()];
- }
- if(!\Yii::$app->user->isGuest) {
- return $this->redirect('inicio');
- }
- return $this->render('index');
- }
- }
|