error(lang('login fail') . ":{$e->getMessage()}"); } $this->success(lang('login success') . '...', '/admin/index'); } } /* * 验证码 * */ public function verify() { return Captcha::create(); } /** * 根据用户名密码,验证用户是否能成功登陆 * @param string $user * @param string $pwd * @throws \Exception * @return mixed */ public static function checkLogin($user, $password, $rememberMe) { try { $where['username'] = strip_tags(trim($user)); $password = strip_tags(trim($password)); $info = Admin::where($where)->find(); // if (!$info){ // $info = Admin::where($where)->find(); // } if (!$info) { throw new \Exception(lang('please check username or password')); } if ($info['status'] == 0) { throw new \Exception(lang('account is disabled')); } if (!password_verify($password, $info['password'])) { throw new \Exception(lang('please check username or password')); } if (!$info['group_id']) { $info['group_id'] = 1; } // Session::set('quanxian', $info["project_status"]); Session::set('adminid', $info["id"]); // Session::set('project', $info["project"]); Session::set('is_admin', 0); $rules = AuthGroup::where('id', $info['group_id']) ->value('rules'); $info['rules'] = $rules; if (!$info['username']) { $info['username'] =""; } unset($info['password']); if ($rememberMe) { Session::set('admin', $info, 7 * 24 * 3600); Session::set('admin_sign', SignHelper::authSign($info), 7 * 24 * 3600); } else { Session::set('admin', $info); Session::set('admin_sign', SignHelper::authSign($info)); } } catch (\Exception $e) { throw new \Exception($e->getMessage()); } return true; } // 代理商登录 public static function userlog($user, $password, $rememberMe) { try { $where['mail|phone'] = strip_tags(trim($user)); $password = strip_tags(trim($password)); $info = User::where($where)->find(); // if (!$info){ // $info = Admin::where($where)->find(); // } if (!$info["is_admin"]){ throw new \Exception(lang('please check username or password')); } // var_dump($info->toArray());die(); if (!$info) { throw new \Exception(lang('please check username or password')); } if ($info['status'] == 1) { throw new \Exception(lang('account is disabled')); } if (!password_verify($password, $info['pwd'])) { throw new \Exception(lang('please check username or password')); } // if (!$info['group_id']) { // $info['group_id'] = 1; // } $info['group_id'] = 2; // Session::set('quanxian', $info["project_status"]); Session::set('adminid', $info["id"]); Session::set('is_admin', 1); $rules = AuthGroup::where('id', $info['group_id']) ->value('rules'); $info['rules'] = $rules; if (!$info['name']) { $info['username'] = $info['name']; } unset($info['pwd']); if ($rememberMe) { Session::set('admin', $info, 7 * 24 * 3600); Session::set('admin_sign', SignHelper::authSign($info), 7 * 24 * 3600); } else { Session::set('admin', $info); Session::set('admin_sign', SignHelper::authSign($info)); } } catch (\Exception $e) { throw new \Exception($e->getMessage()); } return true; } }