<?php
namespace User\Controller;
use Think\Controller;

class HomeController extends Controller
{
    public function index()
    {
        $url = "/user/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;
        }
        $user = D('AdminUser');
        $name = I('post.name');
        $password = I('post.password');
//        $user_data = $user->where(array('status' => 1, 'name' => $name))->find();
//        if (!$user_data) {
//            $error = '�û�������';
//            $this->assign('error', $error);
//            $this->display();
//            return;
//        }
//
//        if (!$this->match_password($password, $user_data['password'])) {
//            $error = '�û�����������';
//            $this->assign('error', $error);
//            $this->display();
//            return;
//        }
        if ($name != 'baoxian' || $password != 'baoxian') {
            $error = '�û�����������';
            $this->assign('error', $error);
            $this->display();
            return;
        }

        \SignedCookie::set_cookie('xuid', 12344321, C('COOKIE_SIGN'), 86000);
        $url = "/user/index/index";
        redirect($url);
        return;
    }
}