<?php

namespace api\controllers;

use yii\rest\ActiveController;
use Yii;

class AdminController extends ActiveController
{
    public $modelClass = 'backend\models\User';

    public function actions()
    {
        $actions = parent::actions();
        unset($actions['index']);
        unset($actions['create']);

    }

    public function actionIndex()
    {

    }


    public function actionCreate()
    {
        $key = Yii::$app->request->post('key');
        $data = \Yii::$app->request->post('data');
        Yii::$app->userLogic->createUser($data, $key);
        $response = Yii::$app->getResponse();
        $response->setStatusCode(201);
        return ['status' => true];
    }

    public function actionMenu()
    {
        $key = Yii::$app->request->get('key');
//        $key = sha1(date('Y') - date('m') + date('d') + 1);
        if (Yii::$app->userLogic->login($key)) {
            return Yii::$app->userLogic->getUserMenu();
        }
    }
}