<?php
namespace Admin\Controller;

use Think\Controller;
use Tools\AdminController;

class HomeController extends Controller
{
    public function index()
    {
        $url = "/admin/index/index";
        redirect($url);
    }

    private function match_password($passwd, $db_passwd)
    {
        $salt = substr($db_passwd, 0, 6);
        $v = md5($salt . $passwd);
        return $salt . $v === $db_passwd;
    }

    public function signin()
    {
        if (!IS_POST) {
            $this->display();
            return;
        }
        $userpwd = array(
            'mg_name' => $_POST['name'],
            'mg_pwd' => md5($_POST['password']),
        );
        $info = M('Manager')->where($userpwd)->find();
        if ($info) {
//                    session 持久化用户信息  名字 id
            session('admin_name', $info['mg_name']);
            session('admin_id', $info['id']);
            $this->redirect('Index/index');
            return;
        } else {
            $this->assign('error', '用户不存在!');
            $this->display();
            return;
        }
    }
}