<?php
namespace Admin\Controller;
use Think\Controller;
class PublicController extends Controller{
	/*
	显示后台登陆界面
	*/
	public function login(){

		$this->display();
		}
		
	/*
	
	生成验证码	
	*/	
	public function verify(){
				
			$config =    array(
			'fontSize'    =>    15,    // 验证码字体大小
			'length'      =>    3,     // 验证码位数
			'useNoise'    =>    false, // 关闭验证码杂点
			'imageH'    =>  42,               // 验证码图片高度
			'imageW'    =>  108,               // 验证码图片宽度
		);
		
		$Verify =new \Think\Verify($config);
		$Verify->entry();
		}
	/*
	登陆提交并检测验证码
	*/
	public function checklogin(){
		$code=I('code');
		//var_dump($code);
		$Verify=new \Think\Verify();
		$result=$Verify->check($code);	
		//var_dump($res);
		if(!$result){
			$data['status']  = 0;
			$data['message'] = '验证码错误';
			$this->ajaxReturn($data);
			}
		
		$username=I('username','','trim');
		$password=I('password','','md5');
		$map['username']=$username;
		$admin=M('admin')->where($map)->find();
		//print_r(M('admin')->_sql());打印SQL语句
		if($password==$admin['password']){
				$data['status']  =1;
				$data['message'] = '登陆成功';
				session('admin_id',$admin['id']);
				session('admin_username',$admin['username']);
			}else{
				$data['status']  =0;
				$data['message'] = '登陆失败';
				
				}
				$this->ajaxReturn($data);
		}
	
	public function logout(){
		session('admin_id',null);
		session('admin_username',null);
		$this->redirect('login');
		}
	
	
	
	
	
	
	
	
	
	
	}

