<?php
namespace Home\Controller;
use Think\Controller;
use Think\Log;
class PublicController extends CoreController {
  public function _empty(){
    $this->display('Public:404');
  }
  /**
   * [block 后台公共模板]
   * @method   block
   * @Author   Amen[233713821@qq.com]
   * @DateTime 2016-05-22T16:59:59+0800
   * @return   [type]                   [description]
   */
  public function block(){
  	$this->display();
  }

  /**
   * [login 前台用户登陆页面]
   * @method   login
   * @Author   Amen[233713821@qq.com]
   * @DateTime 2016-05-22T17:00:16+0800
   * @return   [type]                   [description]
   */
  public function login(){
  	if(session('?user'))
  		$this->redirect('Index/index');
  	if(IS_POST){
//  		$verify = I('yzm','');
//  		if(!check_verify($verify))
//  			$this->error("验证码错误！",'login');
  	$nickname=I('nickname');
  	$password=I('password');

     $f=M('admin')->where('nickname='."'$nickname'")->find();//查找用户
     if(!$f){
      $this->error('用户不存在！','','1');
    }
    if($f['type']==0&&$f['shenhe']==NULL){
      $this->error('未通过审核且未激活，不能登录');
    }
    if($f['job']==0){
      $this->error('还未入组，不能登录');
    }
    if($f['state']!=1){
      $this->error('用户被封禁，不能登录');
    }
    if($f&&md5($password)==$f['password']){
      session('user',$f);// 设置session
      $this->success('登陆成功');// 提示成功，跳转至主页
    }else{
     $this->error('登陆失败，请检查密码','login');
   }
 }else{
   $this->display();
 }
}

public function getpwd(){
  if(IS_POST){
    $nickname=I('nickname');
    $anquan=I('anquan');
    $f=M('admin')->where(array('nickname'=>$nickname))->find();
    if($f&&md5($anquan)==$f['anquan']){
      if(!M('admin')->where(array('nickname'=>$nickname))->setField('password',md5(I('password'))))
        $this->error(C('MSG'));
      $this->success('重置密码成功！请登陆','login');
    }else{
      $this->error('验证失败，请检查昵称和安全码','getpwd');
    }
  }else{
   $this->display();
 }
 
}

}