Beispiel #1
0
 public function login()
 {
     //如果登录跳回来源页
     if (!empty($_SESSION['user_info'])) {
         header("Location:" . $_COOKIE['url']);
     } else {
         $model = new \Model\UserModel();
         if ($_COOKIE['url'] == '/index.php/Home/user/login.html' || $_COOKIE['url'] == '/index.php/Home/user/null') {
             setcookie('url', '/', time() + 1800, '/');
         }
         //如果有post值判断为ajax,如果没展示界面
         if (empty($_POST)) {
             //                //随机AB方案
             $this->assign(head, rand(1, 4));
             //                $this->assign(zjj_xm,$zjj_xm);
             $user_agent = $_SERVER['HTTP_USER_AGENT'];
             if (strpos($user_agent, 'MicroMessenger') === false) {
                 // 非微信浏览器禁止浏览
                 $is_wx = '0';
             } else {
                 $is_wx = '1';
             }
             $this->assign('is_wx', $is_wx);
             //公共目录下模型
             //                $model = new \Model\UserModel();
             $isLogin = $model->IsLogin('liyulin', '17951123');
             echo $isLogin['user_name'];
             //home目录下模型 namespace Home\Model
             //                echo D('User')->IsLogin();
             $this->display('login');
         } else {
             $user = $_POST['Account'];
             $pass = $_POST['Password'];
             //判断用户是否存在
             $isUser = $model->IsLogin($user, $pass, 1);
             //                $isUser = D('User')->IsLogin($user,$pass, 3);
             //判读密码是否正确\
             //使用手机号码,邮箱,用户名都能登录
             //                $userInfo = D('User')->IsLogin($user, $pass, 1);
             $userInfo = $model->IsLogin($user, $pass, 1);
             if (empty($isUser)) {
                 $jsonArr = array('status' => false, 'message' => '11您输入的用户名不存在,user' . $isUser['user_name'] . " and pass:"******" end");
             } elseif (empty($userInfo)) {
                 $jsonArr = array('status' => false, 'message' => '22您输入的密码错误');
                 //登录成功页面跳转回来源页面
             } elseif (!empty($userInfo)) {
                 session_start();
                 $_SESSION['user_info'] = $userInfo;
                 $jsonArr = array('status' => true, 'message' => $_COOKIE['url']);
             }
             echo json_encode($jsonArr);
             //                $this->display('index');
         }
     }
 }