<?php

/**
 *  管理员登录类
 *
 * @author Yang
 */
class LoginAction extends Action {

    //登录首页
    public function index() {
        $this->display();
    }

    //登录检查
    public function checkLogin() {
        //dump($_POST);
        //dump($_SESSION);
        if ($_SESSION['verify'] != md5(strtoupper($_POST['auth_code']))) {
            $this->ajaxReturn('', '', 2);   //验证码错误
        } else {
            $map['username'] = $_POST['name'];
            $map['pwd'] = md5(substr(md5($_POST['pwd']), 0, 16));
            $map['status'] = 1;

            $admin = M('admin');
            if (!$admin->where($map)->find()) {
                $this->ajaxReturn('', '', 0);   //帐号或密码错误
            } else {
                unset($_SESSION['flag']);
                $_SESSION['adminID'] = $admin->id;
                $_SESSION['adminName'] = $admin->username;
                if ($admin->flag == 1) {
                    $_SESSION['flag'] = 1;
                }
                $this->ajaxReturn('', '', 1);   //登录成功
            }
        }
    }

    //注销
    public function logout() {
        unset($_SESSION['adminID'], $_SESSION['adminName'], $_SESSION['flag']);
        $this->redirect('Login/');
    }

    //验证码
    public function verify() {
        import("ORG.Util.Image");
        Image::buildImageVerify(5, 2);
    }

}

?>
