diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php new file mode 100644 index 000000000..ac657a464 --- /dev/null +++ b/application/admin/controller/Index.php @@ -0,0 +1,13 @@ + + * @date 2017/02/10 13:59 + */ +class Login extends Controller { + + /** + * 用户登录 + * @return \think\response\View + */ + public function index() { + if ($this->request->isGet()) { + return view(); + } + $username = $this->request->post('username', '', 'trim'); + $password = $this->request->post('password', '', 'trim'); + (empty($username) || strlen($username) < 4) && $this->error('登录账号长度不能少于4位有效字符!'); + (empty($password) || strlen($password) < 4) && $this->error('登录密码长度不能少于4位有效字符!'); + $user = Db::name('SystemUser')->where('username', $username)->find(); + empty($user) && $this->error('登录账号不存在,请重新输入!'); + ($user['password'] !== md5($password)) && $this->error('登录密码与账号不匹配,请重新输入!'); + session('user', $user); + $this->error('登录成功,正在进入系统...'); + } + + /** + * 退出登录 + */ + public function out() { + session('user', null); + $this->success('退出登录成功!', '@admin/login'); + } +} \ No newline at end of file diff --git a/application/admin/controller/index.php b/application/admin/controller/index.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/application/admin/model/User.php b/application/admin/model/User.php new file mode 100644 index 000000000..564d87b71 --- /dev/null +++ b/application/admin/model/User.php @@ -0,0 +1,10 @@ +isLogin()) { + $this->redirect('@admin/login'); + } + } + + public function isLogin() { + return false; + } +} \ No newline at end of file