12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace KIF\Core;
- use Cas\Module\BackPassport;
- /**
- * 继承自MVC里的Controller,封装了后台用户登录状态、用户信息等一些方法
- * @author lishumingoo@gmail.com
- */
- class BKController extends \KIF\Core\Controller {
-
- /**
- * 判断用户登录状态
- * @return Boolean
- */
- static public function isLogin() {
- return (boolean) self::getUid();
- }
-
- /**
- * 要求未登陆用户去登陆
- * @return boolean
- */
- static public function requireLogin() {
- if (!self::isLogin()) {
- $referer = Request::url();
- $url = Request::schemeDomain() . '/?c=Admin_BackUser&a=Login&referer=' . urlencode($referer);
- parent::redirect($url);
- }
-
- return true;
- }
-
- /**
- * 获取用户id
- * @return false | int
- */
- static public function getUid() {
- $user = self::getUser();
- if (!$user) {
- return false;
- }
-
- return $user['uid'];
- }
-
- /**
- * 获取用户名
- * 这里的用户名是不靠谱的!!!
- * @return string
- */
- static public function getUsername() {
- $user = self::getUser();
- if (!$user) {
- return false;
- }
-
- return $user['name'];
- }
-
- /**
- *
- * 从Cookie中获取用户的登陆信息
- * @return boolean | array
- */
- public function getUser() {
- static $user = null;
- if ($user) {
- return $user;
- }
-
- $user = array();
-
- $objBackPassport = new BackPassport();
- $tmpResult = $objBackPassport->getLoginInfo();
- if ($tmpResult->isSuccess()) {
- $user = $tmpResult->getData();
- }
-
-
- return $user;
- }
-
- public function run() {
- $action = $this->action;
- $this->$action();
- }
- }
|