summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2022-03-18 23:38:15 +0800
committerchai <chaifix@163.com>2022-03-18 23:38:15 +0800
commitb970e38c6cbde1e573c1d7a1d1b1685c1ca5bde1 (patch)
tree1c61a26bf0970ce8fc0b2b11d547b926c403ef82
parentf63d8e742f6f1cd0321acfd9ffcfd71afd6c956d (diff)
*admin login
-rw-r--r--admin.php48
-rw-r--r--admin_add_music.php72
-rw-r--r--admin_header.php34
-rw-r--r--authentication.php17
-rw-r--r--checkadmin.php13
-rw-r--r--config.php7
-rw-r--r--login.php41
-rw-r--r--logout.php11
-rw-r--r--paginate.php20
-rw-r--r--res/admin.css13
-rw-r--r--res/styles.css11
11 files changed, 243 insertions, 44 deletions
diff --git a/admin.php b/admin.php
index d75bc08..32e5604 100644
--- a/admin.php
+++ b/admin.php
@@ -20,6 +20,20 @@ form .section{
form .text {
width: 100%;
}
+
+#container a {
+ display:block;
+ text-decoration:none;
+ color:black;
+ padding:10px;
+ margin-bottom: 20px;
+}
+#container a:hover {
+ display:block;
+ text-decoration:none;
+ color:white;
+ background:black;
+}
</style>
</head>
@@ -29,38 +43,14 @@ form .text {
<?php require_once 'functions.php';?>
<?php require_once 'config.php';?>
-
<?php require_once 'music.php';?>
+<?php require_once('checkadmin.php'); ?>
+
+ <a href="admin_add_music.php">Add Music</a>
-<h1 style="font-size:1.2em;display:block;color:#c5c5c5;" >Add Music</h1>
+ <a href="admin_add_music.php">Add Album</a>
-<form action="new.php" method="post" enctype="multipart/form-data">
- <div class="section">
- <label class="title" for="musicFile" >file:</label>
- <input type="file" name="musicFile"/>
- </div>
- <div class="section">
- <label class="title" for="coverImage" >cover:</label>
- <input type="file" name="coverImage"/>
- </div>
- <div class="section">
- <label class="title" for="musicProj" >project:</label>
- <input type="file" name="musicProj"/>
- </div>
- <div class="section">
- <label class="title" for="title" >title:</label>
- <input class="text" type="text" name="title" /><br/>
- </div>
- <div class="section">
- <label class="title" for="tags" >tags (seprate with comma):</label>
- <input class="text" type="text" name="tags" /><br/>
- </div>
- <div class="section">
- <label class="title" for="albums" >albums id (seprate with comma):</label>
- <input class="text" type="text" name="albums" /><br/>
- </div>
- <input style="float:right" type="submit" value="Upload Music" name="submit"/>
-</form>
+ <a href="admin_add_music.php">Delete Tag</a>
<div>
diff --git a/admin_add_music.php b/admin_add_music.php
new file mode 100644
index 0000000..9599a8c
--- /dev/null
+++ b/admin_add_music.php
@@ -0,0 +1,72 @@
+<html>
+
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, target-densityDpi=device-dpi">
+<style type="text/css">
+#container {
+ margin:0 auto;
+ max-width: 500px;
+}
+form .title {
+ display:block;
+ font-size:0.8em;
+ margin-bottom: 3px;
+}
+form .section{
+ margin-bottom: 10px;
+ padding: 5px;
+ background: #efefef;
+}
+form .text {
+ width: 100%;
+}
+</style>
+
+</head>
+
+<body>
+ <div id="container">
+
+<?php require_once 'functions.php';?>
+<?php require_once 'config.php';?>
+<?php require_once 'music.php';?>
+
+<?php
+ require_once('checkadmin.php');
+?>
+
+<h1 style="font-size:1.2em;display:block;color:#c5c5c5;" >Add Music</h1>
+
+<form action="new.php" method="post" enctype="multipart/form-data">
+ <div class="section">
+ <label class="title" for="musicFile" >file:</label>
+ <input type="file" name="musicFile"/>
+ </div>
+ <div class="section">
+ <label class="title" for="coverImage" >cover:</label>
+ <input type="file" name="coverImage"/>
+ </div>
+ <div class="section">
+ <label class="title" for="musicProj" >project:</label>
+ <input type="file" name="musicProj"/>
+ </div>
+ <div class="section">
+ <label class="title" for="title" >title:</label>
+ <input class="text" type="text" name="title" /><br/>
+ </div>
+ <div class="section">
+ <label class="title" for="tags" >tags (seprate with comma):</label>
+ <input class="text" type="text" name="tags" /><br/>
+ </div>
+ <div class="section">
+ <label class="title" for="albums" >albums id (seprate with comma):</label>
+ <input class="text" type="text" name="albums" /><br/>
+ </div>
+ <input style="float:right" type="submit" value="Upload Music" name="submit"/>
+</form>
+
+ <div>
+
+</body>
+
+</html> \ No newline at end of file
diff --git a/admin_header.php b/admin_header.php
new file mode 100644
index 0000000..3ea71e4
--- /dev/null
+++ b/admin_header.php
@@ -0,0 +1,34 @@
+
+<link rel="stylesheet" href="./res/admin.css">
+
+<style type="text/css">
+#admin_header{
+ height:auto;
+ margin-top:0;
+ margin-bottom: 10px;
+}
+#admin_header a{
+ float:right;
+ color:black;
+ text-decoration: none;
+ font-size:12px;
+ padding: 5px;
+ margin-left: 5px;
+}
+#admin_header a:hover{
+ color: white;
+ background: black;
+}
+</style>
+
+<div id="admin_header" style="width:100%;">
+ <a href="logout.php">Logout</a>
+ <a href="admin.php" style="float:left;">Main</a>
+ <a href="admin.php" style="float:left;">Music</a>
+ <a href="admin.php" style="float:left;">Albums</a>
+ <a href="admin.php" style="float:left;">Tags</a>
+<div style="clear:both"></div>
+
+</div>
+
+<div style="clear:both"></div>
diff --git a/authentication.php b/authentication.php
new file mode 100644
index 0000000..882650f
--- /dev/null
+++ b/authentication.php
@@ -0,0 +1,17 @@
+
+<?php // 验证登录
+
+ require_once 'config.php' ;
+
+ $token = $_POST['token'];
+
+ if($token == Config::$admin_token){
+ session_start();
+ $_SESSION['admin'] = true;
+ setcookie(session_name(), session_id(), time() + $lifeTime);
+ header('Location: '.'admin.php');
+ } else {
+ die("Wrong token.");
+ }
+
+?>
diff --git a/checkadmin.php b/checkadmin.php
new file mode 100644
index 0000000..305b211
--- /dev/null
+++ b/checkadmin.php
@@ -0,0 +1,13 @@
+<?php // 验证当前是否已经登录
+
+ session_start();
+ if (isset($_SESSION["admin"]) && $_SESSION["admin"] === true) {
+ //echo "您已经成功登陆";
+ require_once 'admin_header.php' ;
+ } else {
+ // 验证失败,将 $_SESSION["admin"] 置为 false
+ $_SESSION["admin"] = false;
+ header('Location: '.'login.php');
+ }
+
+?> \ No newline at end of file
diff --git a/config.php b/config.php
index b7e0e27..700fe83 100644
--- a/config.php
+++ b/config.php
@@ -20,8 +20,13 @@ class Config
public static $cover_upload_dir = "./cover";
public static $project_upload_dir = "./project";
- //
+ //
public static $music_per_page = 42;
+
+
+ public static $admin_token = "123";
+ public static $cookie_lifetime = 24*3600; //秒
+
}
?> \ No newline at end of file
diff --git a/login.php b/login.php
new file mode 100644
index 0000000..5bd43c6
--- /dev/null
+++ b/login.php
@@ -0,0 +1,41 @@
+<html>
+
+<head>
+<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, target-densityDpi=device-dpi">
+<link rel="stylesheet" href="./res/admin.css">
+<style type="text/css">
+#container {
+ margin:0 auto;
+ max-width: 500px;
+}
+form .title {
+ display:block;
+ font-size:0.8em;
+ margin-bottom: 3px;
+}
+form .section{
+ margin-bottom: 10px;
+ padding: 5px;
+ background: #efefef;
+}
+form .text {
+ width: 100%;
+}
+</style>
+</head>
+
+<body>
+
+ <div id="container">
+ <label style="display:block; margin-bottom:10px;">Login</label>
+ <form action="authentication.php" method="post" enctype="multipart/form-data">
+ <div class="section">
+ <label class="title" for="token" >token:</label>
+ <input class="text" type="text" name="token" /><br/>
+ </div>
+ <input style="float:right" type="submit" value="Login" name="submit"/>
+ </form>
+ </div>
+
+</body>
+</html>
diff --git a/logout.php b/logout.php
new file mode 100644
index 0000000..9cb285c
--- /dev/null
+++ b/logout.php
@@ -0,0 +1,11 @@
+
+<?php
+session_start();
+// 这种方法是将原来注册的某个变量销毁
+unset($_SESSION['admin']);
+// 这种方法是销毁整个 Session 文件
+session_destroy();
+
+header('Location: '.'login.php');
+
+?>
diff --git a/paginate.php b/paginate.php
index c6ce295..e276f53 100644
--- a/paginate.php
+++ b/paginate.php
@@ -6,16 +6,16 @@
// echo $total_page ;
// echo $url;
-
- for ($p=0; $p<$total_page; $p++) {
- if($p == $current_page_index){
- html_paginate_link_current($url, $p);
- }
- else {
- html_paginate_link($url, $p);
- }
- }
-
+ if($total_page > 1){
+ for ($p=0; $p<$total_page; $p++) {
+ if($p == $current_page_index){
+ html_paginate_link_current($url, $p);
+ }
+ else {
+ html_paginate_link($url, $p);
+ }
+ }
+ }
?>
</div>
diff --git a/res/admin.css b/res/admin.css
new file mode 100644
index 0000000..64b6fc8
--- /dev/null
+++ b/res/admin.css
@@ -0,0 +1,13 @@
+
+body{
+ background:#3a3a3a;
+}
+
+#container{
+ background:white;
+ margin-top:0;
+ min-height:100%;
+ padding:10px;
+ box-sizing: border-box;
+}
+
diff --git a/res/styles.css b/res/styles.css
index eaf5ad3..cb0e0a3 100644
--- a/res/styles.css
+++ b/res/styles.css
@@ -5,6 +5,7 @@ body{
*/
background-color: #3a3a3a;
margin-top: 0;
+ margin-bottom: 0;
}
#header{
@@ -21,9 +22,11 @@ body{
#container {
margin:0 auto;
- max-width: 720px;
+ max-width: 730px;
background-color: #fff;
min-height: 100%;
+ box-sizing: border-box;
+ padding: 5px;
}
#container-uppper {
@@ -106,7 +109,7 @@ body{
.tag_link {
font-size: 80%;
- color: #fff;
+ color: rgb(82, 82, 82);
background: #ccc;
text-decoration: none;
padding: 3px 5px;
@@ -124,8 +127,8 @@ body{
#titlebar {
padding:6px;
- border-top:1px solid #000;
- border-bottom:1px solid #000;
+ border-top:1px solid rgb(223, 223, 223);
+ border-bottom:1px solid rgb(223, 223, 223);
}
#titlebar .title_link{