55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace acs\Controller;
|
|
|
|
use Acast\Http\Config;
|
|
use Acast\Http\Controller;
|
|
use Acast\Http\Router;
|
|
use TwT\SSO;
|
|
use Workerman\Protocols\Http;
|
|
|
|
class Auth extends Controller
|
|
{
|
|
/**
|
|
* @var \acs\View\Auth
|
|
*/
|
|
protected $view;
|
|
|
|
/**
|
|
* @var \acs\Model\Client
|
|
*/
|
|
protected $model;
|
|
|
|
/**
|
|
* @var \TwT\SSO\Api
|
|
*/
|
|
protected $sso_api;
|
|
function __construct(Router $router)
|
|
{
|
|
parent::__construct($router);
|
|
$this->sso_api = new SSO\Api(Config::get('TWT_SSO_ID'), Config::get('TWT_SSO_KEY'));
|
|
}
|
|
|
|
function init()
|
|
{
|
|
$token = strval($this->params['token']);
|
|
$login_url = $this->sso_api->getLoginUrl('https://api.cismon.net/auth-confirm/'.$token);
|
|
Http::header('Location: '.$login_url);
|
|
}
|
|
|
|
function confirm()
|
|
{
|
|
$auth_token = strval($this->params['token']);
|
|
$token = strval($_GET['token']);
|
|
$stunum = strval($this->sso_api->fetchUserInfo($token)->result->user_number);
|
|
if ($stunum != '') {
|
|
if ($this->model->updateStunum($auth_token, $stunum)) {
|
|
$this->view->retJson("Auth complete, waiting.");
|
|
return;
|
|
}
|
|
$this->view->retJson("Pending auth or bad token.", 3);
|
|
return;
|
|
}
|
|
$this->view->retJson("Auth failed.", 4);
|
|
}
|
|
} |