Tools.class.php 2.26 KB
<?php
/**
 * 用户信息
 */
class Controller_Tools extends Controller_Abstract
{
    /**
     * 首页
     */
    public function init()
    {
        $valid_passwords = array ("yoho" => "yoho9646abcdef");
        $valid_users = array_keys($valid_passwords);
        $user = $_SERVER['PHP_AUTH_USER'];
        $pass = $_SERVER['PHP_AUTH_PW'];
        
        $validated = (in_array($user, $valid_users)) && ($pass == $valid_passwords[$user]);
        
        if (!$validated) 
        {
              header('WWW-Authenticate: Basic realm="My Realm"');
              header('HTTP/1.0 401 Unauthorized');
              die ("Not authorized");
        }
    }
    
    
    public function cleanUserCacheAction()
    {
    	$uid = $this->_request->uid ;
    	if (!$uid) 
    	{
    		exit('Missing Uid');
    	}
    	Facade_Userinfo::cleanUserCache($uid);
    	return 'success';
    }
    
    
    /**
     * 用户信息操作 --- 通过手机号或邮箱获取用户信息
     */
    public function userAction()
    {
        $auth_type = intval($this->_request->type);
        $account = trim( $this->_request->account ) ;
        $uid = 0 ;
        if ($account && $auth_type  > 0) 
        {
            $row = Facade_Auth::getAuthByAccount($account,$auth_type);
            $uid = isset($row['uid']) ?$row['uid'] : 0 ;
        }
        if ($auth_type == -1 || $auth_type == -2) 
        {
        	$uid = $account ;
        }
        $error = '' ;
        if ($auth_type == -2 && $uid) 
        {
        	Facade_Userinfo::cleanUserCache($uid);
        	$error = '成功清除缓存';
        }
        
        $auth_list = $userinfo = array();
        if ($uid) 
        {
        	$auth_list = Facade_Auth::getAllAuth($uid);
        	$userinfo  = Facade_Userinfo::getUserinfoByUid($uid);
        }
        
        if ($this->_request->isPost() && !$userinfo) 
        {
        	$error .= '未查到该账号信息';
        }
        $this->_view['types'] = Facade_Auth::getAllowAuthType() + array('-1' => 'SSO_UID', '-2' => '根据用户ID清除用户缓存');
        $this->_view['auth_list'] = $auth_list ;
        $this->_view['userinfo'] = $userinfo ;
        $this->_view['type'] = $auth_type ;
        $this->_view['account'] = $account ;
        $this->_view['error'] = $error ;
    }
}