<?php
class loginControl extends skymvc{
	function __construct(){
		parent::__construct();
		$this->loadModel(array("user","login"));
		
	}
	
	function onDefault(){
		$this->smarty->display("login/login.html");
	}
	
	
	public function onLogin(){
		if(get('ajax')){
			$this->smarty->display("login/ajax_login.html");
		}else{
			$this->smarty->display("login/login.html");
		}
	}
	
	public function onLoginSave(){
		$nickname=post('nickname');
		$email=post('email','h');
		$password=post('password','h');
		$checkcode=post('checkcode','h');
		if(isset($_POST['checkcode']) && $checkcode!=$_SESSION['checkcode']){
			$this->gomsg($this->lang['checkcode_error']);
		}
		if($email){
			$user=$this->user->selectRow(array("where"=>"email='".$email."' "));
		}
		
		if($nickname){
			$user=$this->user->selectRow(array("where"=>"nickname='".$nickname."' "));
		}
		
		if(empty($user)){
			$this->gomsg('账号不存在');
		}
		if($user['password']!=umd5($password.$user['salt'])){
			$this->gomsg("密码出错了");
		}
		$_SESSION['ssuser']=$user;
		$backurl=get_post('backurl','h');
		if(!$backurl){
			$backurl="/index.php";
		}
		$this->gomsg("登陆成功",$backurl);
	}
	
	public function onLogout(){
		$_SESSION['ssuser']="";
		 
		$this->gourl("/index.php");
	}
	
	public function onforgetPassword(){
		$this->smarty->display("login/forgetpassword.html");
	}
}
?>