Cgi.class.php 2.2 KB
<?php
/**
 * 登录控制器
 */
class Controller_Cgi extends Controller_Abstract
{
	private $_app_info = null ;
	
	public function init()
	{
		$key = trim($this->_request->key);
		
		if (!$key) 
		{
			return "Missing Key" ;
		}
		$appInfo = Facade_Subscribe::get($key);
		if(!$appInfo)
		{
			return "KEY Error" ;
		}
		$this->_appId = $appInfo['key'];
		$this->_app_info = $appInfo ;
	}
	
    /**
     * 登录
     */
    public function loginAction()
    {
    	$uid = Facade_Auth::getAuthedUid();
    	$callback = urldecode($this->_request->callback) ;
    	$refer    = urldecode($this->_request->refer) ;
    	$findpwd  = urldecode($this->_request->findpwd) ;
    	$reg      = urldecode($this->_request->reg) ;
    	
    	if (!$callback) 
    	{
    		return "Missing Callback" ;
    	}
    	$headpic = '' ;
    	if ($uid)
    	{
    		//@TODO 获取用户头像
    		$headpic = '' ;
    		if(!$headpic)
    		{
    			//默认头像(必须有)
    			$headpic = 'http://passport.yoho.cn/img/ad.jpg' ;
    		}
    	}
    	$this->_view['headpic']	  = $headpic ;
    	$this->_view['app_key']	  = $this->_appId ;
    	$this->_view['callback']  = $callback;
    	$this->_view['refer']	  = $refer ?  $refer : $this->_request->referer();
    	$this->_view['reg']       = $reg;
    	$this->_view['findpwd']   = $findpwd;
    }
    
    public function dologinAction()
    {
    	if ($this->_request->isPost() )
    	{
    		$account = trim($this->_request->post('account'));
    		$password = trim($this->_request->post('password'));
    		$check  = Facade_Auth::checkLogin($account, $password);
    		if (isset($check['uid']) && $check['uid']) 
    		{
    			$data = Api_Uuc::buildData(array('uid' => $check['uid']), $this->_app_info['key'], $this->_app_info['secret']);
    			return '1|'. http_build_query($data);
    		}
    		return '0|'.$check['message'];
    	}
    }
    
    /**
     * 快捷登录
     */
    public function autologinAction()
    {
    	$uid = Facade_Auth::getAuthedUid() ;
    	if($uid)
    	{
    		$data = Api_Uuc::buildData(array('uid' => $uid), $this->_app_info['key'], $this->_app_info['secret']);
    		return '1|'. http_build_query($data);
    	}
    	return '0|该请求已过期,请尝试刷新页面!';
    }
}