<?php
/**
 * register emlog
 * @package EMLOG
 * @link https://www.emlog.net
 */

/**
 * @var string $action
 * @var object $CACHE
 */

require_once 'globals.php';

if (empty($action)) {

    $br = '<a href="./">控制台</a><a><cite>正版授权</cite></a>';

    include View::getAdmView('header');
    require_once(View::getAdmView('auth'));
    include View::getAdmView('footer');
    View::output();
}

if ($action === 'auth') {

    $emkey = Input::postStrVar('emkey');


    if (empty($emkey)) {
        output::error('请输入授权码');
    }


    $r = Register::doReg($emkey);


    if ($r === false) {
        output::error('授权码错误或请求授权失败，请重试');
    }


    if (isset($r['data']['type'])) {
        Option::updateOption("emkey_type", $r['data']['type']);
    }
    Option::updateOption("emkey", $emkey);
    $CACHE->updateCache('options');
    output::ok();
}
