<?php



/**

 * 会员注册登录

 */

namespace Phonegame\Controller;

use Common\Controller\PhonegameController;

class UsersController extends PhonegameController {
    //登录
	public function index() {
		$id=$userid=sp_get_current_userid();//I("get.id");
		$users_model=M("Users");
		$user=$users_model->where(array("id"=>$id))->find();
		if(empty($user)){
			$this->check_login();
            $this->check_user();
		}
		$this->assign($user);
        $other=M('users_other')->where(array("uid"=>$userid))->find();
        
        $other['pr'] = '';
        $other['ci'] = '';
        $other['di'] = '';
        $other['co'] = '';
        
		/**
		 *最热门游戏
		 *修改时间：2016/01/14 9:27:12
		 *@author yu<thebestyu@126.com>
		 */
		$hotgame = M("m_game")->where("isdisplay=1")->order('downloadnum desc')->limit('2')->getField('id,pic1,gametype,gamename,android_url_image,android_url,downloadnum');
		$this->assign("hotgame",$hotgame);
        $this->assign($other);
		$this->display($this->template.'/template1'.'/User'.'/index');
    }
    function is_login(){
    	if(sp_is_user_login()){
    		$this->ajaxReturn(array("status"=>1,"user"=>sp_get_current_user()));

    	}else{
    		$this->ajaxReturn(array("status"=>0,"info"=>"此用户未登录！"));
    	}
    }

    //退出
    public function logout(){
        session("user",null);//只有前台用户退出
    	$ucenter_syn=C("UCENTER_ENABLED");
    	$login_success=false;
    	if($ucenter_syn){
    		include UC_CLIENT_ROOT."client.php";
    		echo uc_user_synlogout();
    	}else{
            setcookie("thinkcmf_auth","",time()-3600*24*10, C ( 'COOKIE_PATH' ), C ( 'COOKIE_DOMAIN' ),false);
        }
    	$this->success("退出成功！",__ROOT__."/");
    }

	public function logout2(){
        session("user",null);//只有前台用户退出
    	$ucenter_syn=C("UCENTER_ENABLED");
    	$login_success=false;
    	if($ucenter_syn){
    		include UC_CLIENT_ROOT."client.php";
    		echo uc_user_synlogout();
    	}else{
            setcookie("thinkcmf_auth","",time()-3600*24*10, C ( 'COOKIE_PATH' ), C ( 'COOKIE_DOMAIN' ),false);
        }
		if(isset($_SESSION["user"])){
		$referer=$_SERVER["HTTP_REFERER"];
			$_SESSION['login_http_referer']=$referer;
			$this->success("退出成功！",__ROOT__."/");
		}else{
			redirect(__ROOT__."/");
		}
    }



}

