后台登录 login
{include file='public/header'/}
<body style="background-color: #393D49">
<div class="x-box">
<div class="x-top">
<i class="layui-icon x-login-close">
ဇ
</i>
<ul class="x-login-right">
<li style="background-color: #F1C85F;" color="#F1C85F">
</li>
<li style="background-color: #EA569A;" color="#EA569A">
</li>
<li style="background-color: #393D49;" color="#393D49">
</li>
</ul>
</div>
<div class="x-mid">
<div class="x-avtar">
<img src="__STATIC__/images/logo.png" alt="">
</div>
<div class="input">
<form class="layui-form">
<div class="layui-form-item x-login-box">
<label for="username" class="layui-form-label">
<i class="layui-icon"></i>
</label>
<div class="layui-input-inline">
<input type="text" id="username" name="username" required=""
placeholder="username" class="layui-input">
</div>
</div>
<div class="layui-form-item x-login-box">
<label for="pass" class="layui-form-label">
<i class="layui-icon"></i>
</label>
<div class="layui-input-inline">
<input type="password" id="password" name="password" required=""
placeholder="******" class="layui-input">
</div>
</div>
<div class="layui-form-item" id="loginbtn">
<button class="layui-btn" lay-filter="save" lay-submit="" type="button" id="loginbtn">
登 录
</button>
</div>
</form>
</div>
</div>
</div>
<p style="color:#fff;text-align: center;">Copyright © 2017.Company name All rights X-admin </p>
{include file='public/base_js'/}
<script>
layui.use(['form'],
function() {
$ = layui.jquery;
var form = layui.form(),
layer = layui.layer;
$('.x-login-right li').click(function(event) {
color = $(this).attr('color');
$('body').css('background-color', color);
});
//监听提交
// form.on('submit(save)',
// function(data) {
// console.log(data);
// layer.alert(JSON.stringify(data.field), {
// title: '最终的提交信息'
// },function () {
// location.href = "./index.html";
// })
// return false;
// });
});
</script>
<script>
$(function () {
$("#loginbtn").on('click',function () {
$.ajax({
type:'POST',
url:"{:url('login/check')}",
data:$(".layui-form").serialize(),
dataType:"json",
success:function (data) {
if (data.status == 1){
alert(data.message);
window.location.href = "{:url('index/index')}";
}else {
alert(data.message);
window.location.href = "{:url('login/index')}";
}
}
})
})
})
</script>
</body>
</html>
lohin 控制器
<?php
namespace app\admin\controller;
use app\admin\common\Base;
use think\Request;
use app\admin \model\Admin;
use think\Session;
class Login extends Base
{
//Render login interface
public function index()
{
//
return $this -> view -> fetch('login');
}
//Verify user identity
public function check(Request $request)
{
//Set status
$status = 0;
use using using ’s ’ through ’’s ’’’ ’s ’ through ’ s through through ‐ through ‐‐‐‐‐‐‐'s to 0; $data['username'];
$password = md5($data['password']);
using admin using admin table ’ ’ ’ ’ s ’ through admin’s ’ using ‐ ‐ ‐‐‐ $map = [ 'username' => $userName];
$admin = Admin::get($map);
//Verify username and password separately
//If not Query the user
use ’ s ‐ ‐ ‐ ‐ ‐ ‐ ’ ’ s Error ’s ’ s ’ s ‐ ‐ ‐ ‐ ‐ ‐ to find the user = $password) {
# $ admin -& gt; setinc ('login_count');
$ admin -& gt; save (['last_time' = & gt; time ()]; Save it to the session for other controllers to make login decisions
// Session::set('user_id', $userName);
// Session::set('user_inf',$data);
Session::set('user_id', $userName);
Session::set('suer_inf', $data);
}
return ['status' => $status, 'message' =>$message];
}
//Log out
public function logout()
{
//
Session::delete('user_id');
Session::delete('user_inf');
--$this -> success('Logout Successful, returning....', 'login/index');
}
}
Turn on debug mode prompt