<?php


namespace wangjian\controller;

/**
 * 后台首页控制器

 */
class Member extends \source\Controller {
	
    /**
     * 后台用户登录
    
     */
    public function login($username = null, $password = null, $verify = null){
    	$config =   api('Config/lists');
		C($config);
    	//C('TMPL_PARSE_STRING.__TPL__',C('WEB_SITE_STATIC_DOAMIN')."/app/wangjian");
    	C('TMPL_PARSE_STRING.__TPL__',"/app/wangjian/view");
        if(IS_POST){
            /* 检测验证码 TODO: */
//          if(!check_verify($verify)){
//              $this->error('验证码输入错误！');
//          }
			$m=D('MemberAdmin');
			$where=array(
				'username'=>$username,
				'password'=>md5(sha1($password)),
				'status'=>array('neq','-1')
			);
			$user=$m->where($where)->find();
			$uid=$m->login($user);
            if(0 < $uid){
                $this->redirect('Index/index');
            } else { //登录失败
                $this->error('用户或密码错误');
            }
        } else {
            if(is_login()){
                $this->redirect('Index/index');
            }else{
                $this->display();
            }
        }
    }

    /* 退出登录 */
    public function logout(){
        if(is_login()){
            D('MemberAdmin')->logout();
            session('[destroy]');
            $this->redirect('login');
        } else {
            $this->redirect('login');
        }
    }

    public function verify(){
        $verify = new \source\Verify(array(
			'fontSize'=>12,
			'useCurve'=>false,
			'useNoise'=>false,
			'imageH'=>30,
			'imageW'=>100,
			'length'=>4
		));
        $verify->entry(1);
    }

}
