request->isAjax()) { // 验证登录状态 if (isset($this->user) AND (int)$this->user['is_login'] === 1) { return redirect(url('index/index')); } View::layout(false); return View::fetch(); } $model = new UserModel; if ($model->login($this->postData('data'))) { return $this->renderSuccess('登录成功', url('index/index')); } $error = $model->getError() ?: '登录失败'; return $this->renderError($error); } /** * 更新密码 */ public function renew() { $model = (new UserModel)->where([ 'status' => 10, 'user_name' => $this->user['user']['user_name']]) ->find(); if (!$this->request->isAjax()) { return View::fetch('renew', compact('model')); } if ($model->renew($this->postData('data'))) { return $this->renderSuccess('更新成功'); } return $this->renderError($model->getError() ?: '更新失败'); } /** * 退出登录 */ public function logout() { // 清空登录状态 Session::delete('hema_admin'); return redirect(url('passport/login')); } }