public function dologin()
 {
     $username = Input::get('username');
     $password = Input::get('password');
     //验证
     $adminModel = AdminModel::where('username', $username)->first();
     if (!$adminModel) {
         echo "<script>alert('无此管理员!');history.go(-1);</script>";
         exit;
     }
     if ($adminModel && !Hash::check($password, $adminModel->password)) {
         echo "<script>alert('密码错误!');history.go(-1);</script>";
         exit;
     }
     $serial = date('YmdHis', time()) . rand(0, 10000);
     $loginTime = time();
     //加入session
     $adminInfo = ['adminid' => $adminModel->id, 'username' => $adminModel->username, 'role_id' => $adminModel->role_id, 'role_name' => $adminModel->role(), 'serial' => $serial, 'createTime' => $adminModel->createTime(), 'loginTime' => date('Y年m月d日 H:i', $loginTime)];
     Session::put('admin', $adminInfo);
     //登陆加入用户日志表
     $ip = \App\Tools::getIp();
     $ipaddress = \App\Tools::getCityByIp($ip);
     $userlog = ['uid' => $adminModel->id, 'uname' => Input::get('username'), 'ip' => $ip, 'genre' => 2, 'serial' => $serial, 'ipaddress' => $ipaddress, 'action' => $_SERVER['REQUEST_URI'], 'loginTime' => $loginTime, 'created_at' => $adminModel->created_at];
     LogModel::create($userlog);
     return redirect(DOMAIN . 'admin');
 }
 public function dologin()
 {
     $userModel = UserModel::where('username', Input::get('username'))->first();
     //查看是否有此用户
     if (!$userModel) {
         echo "<script>alert('没有此用户!');history.go(-1);</script>";
         exit;
     }
     //验证密码正确否
     if (!Hash::check(Input::get('password'), $userModel->password)) {
         echo "<script>alert('密码错误!');history.go(-1);</script>";
         exit;
     }
     //查看2次密码输入是否一致
     if (Input::get('password') != Input::get('password2')) {
         echo "<script>alert('2次密码输入不一致!');history.go(-1);</script>";
         exit;
     }
     //验证码验证
     $rules = ['captcha' => 'required|captcha'];
     $messages = ['captcha.required' => '请输入验证码', 'captcha.captcha' => '验证码错误,请重试'];
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         echo "<script>alert('验证码错误!');history.go(-1);</script>";
         exit;
     }
     //个人资料
     if (in_array($userModel->isuser, [1, 3])) {
         $personModel = PersonModel::where('uid', $userModel->id)->first();
         $persons['per_id'] = $personModel->id;
         $persons['realname'] = $personModel->realname;
         $persons['sex'] = $personModel->sex;
         $persons['idcard'] = $personModel->idcard;
         $persons['idfront'] = $personModel->idfront;
     }
     $userperson = isset($persons) ? serialize($persons) : [];
     //企业资料
     if (in_array($userModel->isuser, [2, 4])) {
         $companyModel = CompanyModel::where('uid', $userModel->id)->first();
         $companys['cid'] = $companyModel->id;
         $companys['name'] = $companyModel->name;
         $companys['area'] = $companyModel->area;
         $companys['address'] = $companyModel->address;
         $companys['yyzzid'] = $companyModel->yyzzid;
     }
     $usercompany = isset($companys) ? serialize($companys) : [];
     $serial = date('YmdHis', time()) . rand(0, 10000);
     $userInfo = ['uid' => $userModel->id, 'username' => Input::get('username'), 'email' => $userModel->email, 'userType' => $userModel->isuser, 'serial' => $serial, 'area' => $userModel->area, 'address' => $userModel->address, 'cid' => isset($companyModel) ? $companyModel->id : '', 'loginTime' => time(), 'person' => $userperson, 'company' => $usercompany];
     Session::put('user', $userInfo);
     //登陆加入用户日志表
     $ip = \App\Tools::getIp();
     $ipaddress = \App\Tools::getCityByIp($ip);
     $userlog = ['uid' => $userModel->id, 'uname' => Input::get('username'), 'genre' => 1, 'serial' => $serial, 'ip' => $ip, 'ipaddress' => $ipaddress, 'action' => $_SERVER['REQUEST_URI'], 'loginTime' => time(), 'created_at' => $userModel->created_at];
     LogModel::create($userlog);
     //最近登录更新
     UserModel::where('id', $userModel->id)->update(['lastLogin' => time()]);
     return redirect(DOMAIN . 'member');
 }
 public function doregist()
 {
     //查看同ip是否已有3个注册,满3个则限制
     if (count(UserModel::where('ip', Tools::getIp())->get()) == 3) {
         echo "<script>alert('此用户已经注册过,不要重复注册!');history.go(-1);</script>";
         exit;
     }
     //查看是否有此用户
     if (UserModel::where('username', Input::get('username'))->first()) {
         echo "<script>alert('此用户已经注册!');history.go(-1);</script>";
         exit;
     }
     //        //验证密码正确否
     //        if (!(Hash::check(Input::get('password'),$userModel->password))) {
     //            echo "<script>alert('密码错误!');history.go(-1);</script>";exit;
     //        }
     //查看2次密码输入是否一致
     if (Input::get('password') != Input::get('password2')) {
         echo "<script>alert('2次密码输入不一致!');history.go(-1);</script>";
         exit;
     }
     //验证码验证
     $rules = [];
     $messages = ['captcha.required' => '请输入验证码', 'captcha.captcha' => '验证码错误,请重试'];
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         echo "<script>alert('验证码错误!');history.go(-1);</script>";
         exit;
     }
     //数据写入用户表
     $data = ['username' => Input::get('username'), 'password' => Hash::make(Input::get('password')), 'ip' => Tools::getIp(), 'email' => Input::get('email'), 'created_at' => time(), 'lastLogin' => time()];
     UserModel::create($data);
     //加入session
     $userinfo = UserModel::where('username', Input::get('username'))->first();
     $userInfo = ['uid' => $userinfo->id, 'username' => Input::get('username'), 'email' => Input::get('email')];
     Session::put('user', $userInfo);
     //登陆加入用户日志表
     $serial = date('YmdHis', time()) . rand(0, 10000);
     $ip = \App\Tools::getIp();
     $ipaddress = \App\Tools::getCityByIp($ip);
     $userlog = ['uid' => $userinfo->id, 'uname' => Input::get('username'), 'genre' => 1, 'serial' => $serial, 'ip' => $ip, 'ipaddress' => $ipaddress, 'action' => $_SERVER['REQUEST_URI'], 'loginTime' => time(), 'created_at' => $userinfo->created_at];
     \App\Models\Admin\LogModel::create($userlog);
     return redirect(DOMAIN . 'regist/success');
 }