<?php
namespace backend\controllers;

use backend\models\forms\LoginForm;
use backend\models\forms\OpenDemoForm;
use backend\models\forms\OpenForm;
use backend\models\forms\PwdForm;
use backend\models\forms\RePwdForm;
use backend\models\MemberApi;
use backend\models\SmsApi;
use Yii;
use yii\helpers\Html;
use yii\web\Controller;
use yii\web\UploadedFile;
use backend\models\MemberIdentity;

class AccountController extends Controller
{
    public $enableCsrfValidation = false;

    /**
     * 管理员登录页面
     * @return string
     */
    public function actionAdminlogin()
    {
        return $this->renderPartial('adminlogin');
    }

    /**
     * 管理员登录验证
     * @return \yii\web\Response
     */
    public function actionAdminloginPost()
    {
        $model = new LoginForm();
        if (Yii::$app->getRequest()->getIsPost()) {
            $model->setAttributes(Yii::$app->getRequest()->post());
            $model->type = MemberIdentity::MEMBER_TYPE_ADMIN;
            if ($model->login()) {
                return $this->asJson([
                    'isSuccess' => true,
                ]);
            }
        }
        return $this->asJson([
            'isSuccess' => false,
            'msg' => Html::errorSummary($model, ['header' => '']),
        ]);
    }

    /**
     * 登出
     */
    public function actionLogout()
    {
        $redirectAction = '/adminL0gin3721';

        Yii::$app->user->logout(false);
        $this->redirect([$redirectAction]);
    }
}
