<?php
namespace admin\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function login(){
		//如果已经登录则跳过登录
		$user=D('User');
		if ($user->is_admin_login())
		{
			$this->redirect('/main/index');
			exit();
		}
		if(IS_POST){
				$username=I("post.username",'','trim');
				$password=I("post.password",'','trim');
				if (empty($username) || empty($password))
				{
					$this->assign('err','请填写用户名和密码');
					$this->display();
					exit();
				}
				$userinfo=$user->verify_username_password($username,$password);
				if ($userinfo && $userinfo['isadmin']=='1' && $userinfo['auth'])
				{	
					$user->user_login($userinfo);
					$this->redirect('/main/index');
				}else{
					$this->assign('err','用户名或密码错误');
					$this->display();
				}
		}else{
		 	$this->display();
		}       
    }
	 public function logout(){
	 	$user=D('User');
        $user->clear_session();
		$this->redirect('/login/login');
    }
}
?>