<?php
class userAction extends action
{
    function __construct(){
        parent::__construct();
        $this->mod = new userMod();
    }

    function __destruct(){
    }

    function loginOut(){
		$this->mod->loginOut();
		$_SESSION['isLoginOut']=true;
		exit('<script>parent.window.location.href = "'.HOST.'";</script>');
    }

    function changePass(){
		$input = file_get_contents('php://input');
		$params = json_decode($input,true);
		if(!isset($_SESSION['user']) || !isset($_SESSION['user']['id'])){
			$this->exitJson(2001,'未登录');
		}
		if(empty($params['old']) || empty($params['pass'])){
			$this->exitJson(2001,'没有录入任何值');
		}
		if($row = $this->mod->getUser($_SESSION['user']['id'])){
			if(strcmp($this->mod->password($params['old']),$row['u_pass'])!=0){
				$this->exitJson(2001,$_SESSION['user']['id'].' 原密码不正确');
			}else{
				$this->mod->setPassword($_SESSION['user']['id'],$params['pass']);
				$this->mod->loginOut();
				$this->exitJson(0);
			}
		}else{
			$this->exitJson(2001,'找不到当前用户');
		}
    }

    
}