| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace app\base\controller;
- use think\Controller;
- use think\Session;
- use app\user\model\Admin;
- class Login extends Controller
- {
-
- private $adminModel;
-
- protected function _initialize(){
-
- $this->adminModel = new Admin();
- }
-
- public function login(){
- $this->view->engine->layout(false);
-
- if ($this->request->isPost()){
- // 判断验证码
- $username = $this->request->post('username');
- $password = $this->request->post('password');
- // 判断用户名
- if (empty($username)) {
- return $this->error("用户名不能为空", $this->request->baseUrl());
- }
-
- // 判断密码
- if (empty($password)) {
- return $this->error("密码不能为空", $this->request->baseUrl());
- }
-
- $res = $this->adminModel->login($username, $password);
-
- if($res){
- Session::set('admin', $res);
- $this->success("登录成功", url('user/index/index'));
- } else {
- $this->error("用户不存在或密码不正确", $this->request->baseUrl());
- }
- }
-
- return $this->fetch('login');
- }
-
- public function out(){
- session(null);
- $this->redirect(url('base/login/login'));
- }
-
- public function register(){
- $this->view->engine->layout(false);
-
- if($this->request->isPost()){
- $this->adminModel->register();
- }
-
- return $this->fetch('register');
- }
-
- }
|