Skip to content

Commit

Permalink
1. admin.php页面完成 2. 调整部分文件目录
Browse files Browse the repository at this point in the history
  • Loading branch information
shinn-lancelot committed Aug 23, 2018
1 parent a26c9f9 commit 0798f35
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 36 deletions.
207 changes: 204 additions & 3 deletions admin.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
session_start();
$token = $_SESSION['token'];
if (empty($token)) {
$user = $_SESSION['wop_admin_user'];
if (empty($user)) {
header('Location: ./login.html');
}
?>
Expand All @@ -16,8 +16,209 @@
<title>后台管理</title>
<link rel="shortcut icon" href="./asset/image/favicon.ico">
<link rel="stylesheet" href="./asset/css/reset.css">
<style>
@media screen and (max-width: 640px) {
.btn-size {
height: 10vw;
margin: 3vw auto 0;
padding: 0 3vw;
font-size: 4vw;
}
.user-size, .logout-size {
line-height: 3vw;
font-size: 3vw;
}
.logo {
margin: 0 auto 10vw;
width: 30vw;
height: 30vw;
background: url("./asset/image/oauth_proxy.png") no-repeat center / contain;
}
}

@media screen and (min-width: 640px) {
.btn-size {
height: calc(640px * 0.1);
margin: calc(640px * 0.03) auto 0;
padding: 0 calc(640px * 0.03);
font-size: calc(640px * 0.04);
}
.user-size, .logout-size {
line-height: calc(640px * 0.03);
font-size: calc(640px * 0.03);
}
.logo {
margin: 0 auto calc(640px * 0.1);
width: calc(640px * 0.3);
height: calc(640px * 0.3);
background: url("./asset/image/oauth_proxy.png") no-repeat center / contain;
}
}

.wrapper {
width: 100vw;
height: 100vh;
}

.container {
margin: 0 auto;
width: 100%;
max-width: 640px;
height: 100vh;
overflow: hidden;
position: relative;
}

.user-box {
width: 100%;
padding: 0 2vw;
box-sizing: border-box;
text-align: right;
position: absolute;
top: 2vw;
left: 0;
z-index: 100;
}

.user {
margin-left: 1vw;
display: inline-block;
overflow: hidden;
color: #36a82e;
}

.logout-btn {
margin-left: 1vw;
display: inline-block;
overflow: hidden;
color: #ddd;
text-decoration: underline;
cursor: pointer;
}

.box {
width: 100%;
position: absolute;
overflow: auto;
top: 50%;
left: 50%;
z-index: 10;
transform: translate(-50%, -50%);
-webkit-transform: translate(-50%, -50%);
}

.box-content {
margin: 0 2vw;
max-height: 100vh;
}

.btn {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
box-sizing: border-box;
text-align: center;
border: 0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
color: #fff;
background: #36a82e;
cursor: pointer;
border-radius: 3px;
-moz-user-select: none;
-o-user-select:none;
-webkit-user-select:none;
-ms-user-select:none;
user-select: none;
}

.btn p {
width: 100%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}

.disable {
background: #ddd !important;
cursor: not-allowed !important;
}
</style>
</head>
<body>
admin
<div class="wrapper">
<div class="container">
<div class="user-box">
<p class="user user-size"><?php echo $user; ?></p>
<p class="logout-btn logout-size">退出登录</p>
</div>
<div class="box">
<div class="box-content">
<div class="logo"></div>
<a href="./verify.html">
<div class="btn btn-size">
<p>添加微信公众号授权登录txt验证内容</p>
</div>
</a>
<a href="">
<div class="btn btn-size">
<p>添加接口允许域名</p>
</div>
</a>
<a href="">
<div class="btn btn-size">
<p>添加管理员账号</p>
</div>
</a>
</div>
</div>
</div>
</div>

<script>
var loginoutBtnObj = document.getElementsByClassName('logout-btn')[0],
logoutState = 1,
xhr = '';

if (window.ActiveXObject) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}

var logout = function(e) {
e.preventDefault();
if (logoutState != 1) {
return;
}
logoutState = 0;

xhr.open('post', './common/logout.php', true);
xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xhr.send('');
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
responseObj = JSON.parse(xhr.response);
alert(responseObj.message);
if (responseObj.code == 1) {
setTimeout(function() {
window.location.href = './login.html';
}, 500);
} else {
logoutState = 1;
}

} else {
console.log(xhr.readyState);
}
}
}

loginoutBtnObj.addEventListener('click', function(e) {
confirm('您确定要退出吗?') && logout(e);
});
</script>
</body>
</html>
30 changes: 2 additions & 28 deletions login.php → common/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@

// 密码盐
$salt = md5('shinn_lancelot');
$res = json_decode(file_get_contents(__DIR__ . '/user.json'), true);
$res = json_decode(file_get_contents('./user.json'), true);
$hasUser = false;
foreach ($res as $key=>$value) {
if ($value['user'] == $user) {
$hasUser = true;
if ($value['password'] == md5($password . $salt)) {
// 生成用户登录令牌
$token = getNonceStr();
session_start();
$_SESSION['token'] = $token;
$_SESSION['wop_admin_user'] = $user;

$res['code'] = 1;
$res['message'] = '登录成功!';
Expand All @@ -43,28 +41,4 @@
}

echo json_encode($res);
}

/**
* 获取随机字符串
* @param int $length
* @return string
*/
function getNonceStr($length = 16)
{
$str2 = time();
$length2 = strlen($str2);
$length1 = $length - $length2;
if($length1 <= 0){
$length1 = 6;
}

$chars = "abcdefghijklmnopqrstuvwxyz";
$str1 = "";
for ( $i = 0; $i < $length1; $i++ ) {
$str1 .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
}
$str = $str1.$str2;

return $str;
}
18 changes: 18 additions & 0 deletions common/logout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
$res['code'] = 0;
$res['message'] = '退出失败!';

session_start();
$token = $_SESSION['wop_admin_user'];
if (!$token) {
echo json_encode($res);
exit();
}

$_SESSION['wop_admin_user'] = '';
$res['code'] = 1;
$res['message'] = '退出成功!';
echo json_encode($res);
}
File renamed without changes.
6 changes: 3 additions & 3 deletions verify.php → common/verify.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
$res['code'] = -1001;
$res['code'] = 0;
$res['message'] = '提交失败!';

$filePrefix = 'MP_verify_';
Expand All @@ -14,8 +14,8 @@
exit();
}

file_put_contents('./' . $filePrefix . $txt . '.txt' , $txt);
$res['code'] = 1001;
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/' . $filePrefix . $txt . '.txt' , $txt);
$res['code'] = 1;
$res['message'] = '提交成功!';
$res['data'] = array(
'callBackUrl'=>$callBackUrl
Expand Down
2 changes: 1 addition & 1 deletion login.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
return;
}

xhr.open('post', './login.php', true);
xhr.open('post', './common/login.php', true);
xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xhr.send('user=' + user + '&password=' + password);
xhr.onreadystatechange = function() {
Expand Down
2 changes: 1 addition & 1 deletion verify.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
return;
}

xhr.open('post', '/verify.php', true);
xhr.open('post', './common/verify.php', true);
xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xhr.send('txt=' + txt);
xhr.onreadystatechange = function() {
Expand Down

0 comments on commit 0798f35

Please sign in to comment.