mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
增加用户登录
This commit is contained in:
parent
c84f76095a
commit
2107a39c32
application/admin
extend/controller
13
application/admin/controller/Index.php
Normal file
13
application/admin/controller/Index.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use controller\BasicAdmin;
|
||||
|
||||
class Index extends BasicAdmin {
|
||||
|
||||
public function index() {
|
||||
return view();
|
||||
}
|
||||
|
||||
}
|
42
application/admin/controller/Login.php
Normal file
42
application/admin/controller/Login.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 系统登录控制器
|
||||
* Class Login
|
||||
* @package app\admin\controller
|
||||
* @author Anyon <zoujingli@qq.com>
|
||||
* @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');
|
||||
}
|
||||
}
|
10
application/admin/model/User.php
Normal file
10
application/admin/model/User.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\model;
|
||||
|
||||
|
||||
use think\Model;
|
||||
|
||||
class User extends Model {
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
admin
|
1
application/admin/view/login.index.html
Normal file
1
application/admin/view/login.index.html
Normal file
@ -0,0 +1 @@
|
||||
login
|
19
extend/controller/BasicAdmin.php
Normal file
19
extend/controller/BasicAdmin.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace controller;
|
||||
|
||||
use think\Controller;
|
||||
|
||||
class BasicAdmin extends Controller {
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
if (!$this->isLogin()) {
|
||||
$this->redirect('@admin/login');
|
||||
}
|
||||
}
|
||||
|
||||
public function isLogin() {
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user