Index.php 1.93 KB
<?php
use Action\RootAction;
use Hood\Cache;
use QAdmin\Profile\Client as ProfileClient;
use Hood\Core\Security\AuthCode;
use QAdmin\Config as QAdminConfig;
use QAdmin\Session\Client as SessionClient;

class IndexController extends RootAction
{
    public function indexAction()
    {
        $this->getView()->setLayout('signin');
        $this->_viewLink()->offsetSetFile(100, $this->_css('style.default', true));
        $this->_viewScript()->conditional('lt IE 9')
            ->offsetSetFile(100, $this->_js('html5shiv', true))
            ->offsetSetFile(101, $this->_js('respond', true));
        $this->_viewLink()->offsetSetFile(200, $this->_css('debugbar', true));
    }

    public function signinAction()
    {
        $this->disableView();
        $account = $this->_post('account');
        $password = $this->_post('password');
        $validator = $this->validator(
            ['account' => $account, 'password' => $password],
            ['account' => 'required', 'password' => 'required']
        );
        if ($validator->fails() == true) {
            $this->helpJsRedirect($validator->errors()->first());
        }
        $accountInfo = ProfileClient::self()->Dao()->getProfileByAccount($account);
        if (empty($accountInfo)) {
            $this->helpJsRedirect('没有这个账号.');
        }
        $authPass = AuthCode::authPassword($password, $accountInfo['password']);
        if ($authPass == false) {
            $this->helpJsRedirect('密码错误.');
        }
        if ($accountInfo['expiration'] > QAdminConfig::$expiration) {
            $this->helpJsRedirect('你账号 ' . QAdminConfig::$expiration . ' 天没有登陆,已经冻结.');
        }
        $accountInfo['token'] = $token = md5(uniqid('profile_info', true));
        SessionClient::self()->Dao()->setSession($accountInfo['pid'], $token);
        $this->_session('adminx_profile')->__set('profile_info', $accountInfo);
        $this->redirect('/display');
    }
}