<?php
class Login_Controller extends Public_Controller {
	function __construct(){
		parent::__construct();
		$this->login	=	new Auth_Login_Model();
	}
	function index($login_message=''){
		if($this->input->post()){
			$login				=	$this->input->post('login');
			$login_type			=	$this->input->post('login_type');
			$login['user_pwd']	=	md5($login['user_pwd']);
			$loginResult		=	$this->login->checkLogin($login,$login_type);
			$user				=	$loginResult->current();
			if($loginResult->count()==1){
				if($user->user_status==1){
					$auth	=	new Adminauth();
					//设置SESSION
					$auth->setUserSession($user->user_id);
					url::redirect(BASEURI."admin");
				}
				else{
					url::redirect(BASEURI."front/report/account_disabled/".base64_encode("login/index")."/true");
				}
			}
			else{
				url::redirect(BASEURI."front/report/password_error/".base64_encode("login/index")."/true");
			}
		}
		else{
			$this->view	=	new View('admin/login/index');
			$this->view->login_message=base64_decode($login_message);
			$this->view->render(true);
		}
	}
	
	
	function loginout($position="member"){
		$this->session  = Session::instance();
		unset($_SESSION['adminmanager']);
		switch ($position){
			case "member":	url::redirect(BASEURI."html");
			break;
			case "admin" :	url::redirect(BASEURI."login/index/");
			break;
			default:	url::redirect(BASEURI."html");
		}
	}
}