<?php
// +-----------------------------------------------------------------------------------
// | Software: [ThinkPHP framework]
// | Version: V4.0
// | Site: http://www.czreg.com
// +-----------------------------------------------------------------------------------
// | Author: 飘叶 <cds425@163.com>
// | Copyright (c) 2012-2014, http://www.czreg.com All Rights Reserved.
// | time:2014.10.25
// | explain:管理员登陆类
// +-----------------------------------------------------------------------------------

namespace Admin\Controller;
use Think\Controller;
class PublicController extends Controller {
    public function login(){
        if(IS_POST){ 
            $user=M('Admin')->where(array('loginname'=>I('post.admin'),'loginpass'=>md5(I('post.pass'))))->find();
            if(is_array($user)){ 
                $auth =array(
                    'id'    => $user['id'],
                    'status'=> $user['status'],
                );
                session('user_auth', $auth);
                M('Adminlog')->add(array('adminid'=>$user['id'],'timeline'=>time(),'value'=>"成功登陆",'createip'=>get_client_ip()));
                $this->success('登录成功！', U('Index/index')); 
            } else {
            	$data['isType'] = "warning";
                $data['isData'] = '用户不存在或被禁用';
                $this->success('用户不存在或被禁用！'); 
                exit; 
            }             
        } else {  
            $configset          = M('Config')->limit(1)->find();//网站配置输出
            $this->configset    = $configset;//网站配置输出
            if($configset['upimg']==1){
                $this->IMGURL   =$configset['imgurl'];//图片远程地址
            }else{
                $this->IMGURL   ='/Uploads/';//图片本地地址
            }
            $this->bg=rand(1,4);
            $this->display(); 
        }
    }

    //退出登录 ,清除 session

    public function logout(){ 
        session('user_auth', null);
        session('destroy');
        $this->success('退出成功！', U('login')); 
    }

}