public function checkLogin() {
if (Yii::app()->authority->isLogin() == Yii::app()->authority->getStatus(‘NOTLOGIN‘)) {
$url = $this->createUrl(‘user/login‘);
if (Yii::app()->request->isPostRequest && Yii::app()->request->isAjaxRequest) {
echo json_encode(array(‘code‘ => -101, ‘message‘ => ‘用户未登录。‘, ‘callback‘ => ‘window.location="‘ . $url . ‘";‘));
} else if (Yii::app()->request->isAjaxRequest) {
echo ‘<script language="javascript">window.location="‘ . $url . ‘";</script>‘;
} else {
$this->redirect($url);
}
exit;
}
return true;
}