huwhois 1 年間 前
コミット
2d914b30ac
共有10 個のファイルを変更した817 個の追加106 個の削除を含む
  1. 204 49
      application/controller/Index.php
  2. 18 2
      application/model/MySqlite.php
  3. 9 0
      application/model/User.php
  4. 0 1
      public/index.html
  5. 6 1
      public/static/css/index.css
  6. 11 0
      public/static/js/fun.js
  7. 348 0
      view/editor.php
  8. 117 39
      view/index.php
  9. 1 1
      view/login.php
  10. 103 13
      view/userlist.php

+ 204 - 49
application/controller/Index.php

@ -1,12 +1,13 @@
1 1
<?php
2
2 3
namespace app\controller;
3 4
4 5
// use \Firebase\JWT\JWT;
5 6
6 7
use app\Request;
7 8
use app\View;
8
use app\model\User;
9 9
use app\Session;
10
use app\model\User;
10 11
use app\utils\RRException;
11 12
use app\utils\ParsedownExtension;
12 13
@ -31,17 +32,17 @@ class Index extends View
31 32
        $doc = $request->params['doc'];
32 33
33 34
        $doc = ltrim($doc, '/');
34
        
35
35 36
        if (substr($doc, -1) === '/') {
36 37
            $doc = $doc . "index.md";
37 38
        }
38 39
39 40
        $doc = empty($doc) ? 'index.md' : $doc;
40
        
41
        if (pathinfo($doc,PATHINFO_EXTENSION) != 'md') {
41
42
        if (pathinfo($doc, PATHINFO_EXTENSION) != 'md') {
42 43
            $doc = $doc . ".md";
43 44
        }
44
        
45
45 46
        $filename = DATA_PATH . $doc;
46 47
        $text = "";
47 48
        $toc = "";
@ -55,12 +56,12 @@ class Index extends View
55 56
            $toc = $res['toc'];
56 57
            $content = $res['content'];
57 58
        }
58
        
59
        $this->assign('doc',$doc);
59
60
        $this->assign('doc', $doc);
60 61
        $this->assign('is_file_exists', $is_file_exists);
61
        $this->assign('text',$text);
62
        $this->assign('toc',$toc);
63
        $this->assign('content',$content);
62
        $this->assign('text', $text);
63
        $this->assign('toc', $toc);
64
        $this->assign('content', $content);
64 65
65 66
        $this->fetch();
66 67
    }
@ -85,11 +86,11 @@ class Index extends View
85 86
        $content = $requests['content'];
86 87
87 88
        $pathinfo = pathinfo($doc);
88
        
89
89 90
        $dir_name = DATA_PATH . $pathinfo['dirname'];
90 91
91 92
        if (!is_dir($dir_name) && !mkdir($dir_name, 0744, true)) {
92
            die(json_encode(['code'=>2, 'msg'=>'目录创建失败']));
93
            die(json_encode(['code' => 2, 'msg' => '目录创建失败']));
93 94
        }
94 95
95 96
        $filename = DATA_PATH . $doc;
@ -97,30 +98,55 @@ class Index extends View
97 98
        $res = file_put_contents($filename, $content);
98 99
99 100
        if ($res === false) {
100
            echo json_encode(['code'=>2, 'msg'=>'保存失败']);
101
            echo json_encode(['code' => 2, 'msg' => '保存失败']);
101 102
        } else {
102
            echo json_encode(['code'=>0, 'msg'=>'保存成功, 字数:' . $res]);
103
            echo json_encode(['code' => 0, 'msg' => '保存成功, 字数:' . $res]);
103 104
        }
104 105
        die();
105 106
    }
106 107
108
    // private function validate ()
109
    // {
110
    //     $jwt = isset($_SERVER['HTTP_TOKEN']) ? $_SERVER['HTTP_TOKEN'] : '';
111
    //     if (empty($jwt)) {
112
    //         throw new RRException("You do not have permission to access.", 401);
113
    //     }
114
115
    //     try {
116
    //         JWT::$leeway = 60;
117
    //         $decoded = JWT::decode($jwt, KEY, ['HS256']);
118
    //         $arr = (array)$decoded;
119
    //         if ($arr['exp'] < time()) {
120
    //             throw new RRException("认证信息已过期, 请重新登录.", 401);
121
    //         }
122
    //     } catch(\Exception $e) {
123
    //         throw new RRException($e->getMessage(), 401);
124
    //     }
125
126
    //     return true;
127
    // }
128
107 129
    public function login()
108 130
    {
109
        $this->fetch();
110
    }
131
        if (Session::get('userid')) {
132
            echo "您已登录请登录";
133
            header("Location: /index", TRUE, 301);
111 134
112
    public function dologin()
113
    {
114
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
115
            $username = strip_tags(htmlentities($_POST['username']));
116
            $password = strip_tags(htmlentities($_POST['password']));
135
            exit();
136
        }
137
138
        $request = Request::getInstance();
139
140
        if ($request->isPost()) {
141
            $username = strip_tags(htmlentities($request->params['username']));
142
            $password = strip_tags(htmlentities($request->params['password']));
117 143
118 144
            if (!$username || !$password) {
119 145
                throw new RRException("用户名或密码不能为空!", 1);
120 146
            }
121
            
147
122 148
            $user = new User();
123
            
149
124 150
            $info = $user->getInfoByUsername($username);
125 151
126 152
            if (!$info) {
@ -149,31 +175,67 @@ class Index extends View
149 175
            Session::set('userid', $info['id']);
150 176
            Session::set('username', $info['username']);
151 177
152
            echo json_encode(['code'=>0, 'msg'=>'success']);
178
            echo json_encode(['code' => 0, 'msg' => 'success']);
179
            die();
180
        } else {
181
            $this->fetch();
153 182
        }
154
        die();
155 183
    }
156 184
157
    // private function validate ()
158
    // {
159
    //     $jwt = isset($_SERVER['HTTP_TOKEN']) ? $_SERVER['HTTP_TOKEN'] : '';
160
    //     if (empty($jwt)) {
161
    //         throw new RRException("You do not have permission to access.", 401);
162
    //     }
163
    
164
    //     try {
165
    //         JWT::$leeway = 60;
166
    //         $decoded = JWT::decode($jwt, KEY, ['HS256']);
167
    //         $arr = (array)$decoded;
168
    //         if ($arr['exp'] < time()) {
169
    //             throw new RRException("认证信息已过期, 请重新登录.", 401);
170
    //         }
171
    //     } catch(\Exception $e) {
172
    //         throw new RRException($e->getMessage(), 401);
173
    //     }
185
    public function logout()
186
    {
187
        Session::destroy();
188
        echo "登出成功.....";
189
        header("Location: /login", TRUE, 301);
174 190
175
    //     return true;
176
    // }
191
        exit();
192
    }
193
194
    public function password()
195
    {
196
        $request = Request::getInstance();
197
        if ($request->isPost()) {
198
            $userid = Session::get('userid');
199
200
            if (!$userid) {
201
                throw new RRException('用户未登录, 请登录');
202
            }
203
204
            $user = new User();
205
206
            // 修改密码
207
            $oldpassword = isset($request->params['oldpassword']) ? (string) $request->params['oldpassword'] : '';
208
            $password    = isset($request->params['newpassword']) ? (string) $request->params['newpassword'] : '';
209
            $repassword  = isset($request->params['repassword']) ? (string) $request->params['repassword'] : '';
210
211
            if (!$password) {
212
                throw new RRException("密码不能为空", 1);
213
            }
214
215
            if ($password != $repassword) {
216
                throw new RRException("两次密码不一致", 1);
217
            }
218
219
            $userinfo = $user->getInfoById($userid);
220
221
            if (md5($oldpassword) != $userinfo['password']) {
222
                throw new RRException("原密码不正确", 1);
223
            }
224
225
            try {
226
                $user->updateById([
227
                    'id' => $userid,
228
                    'password' => md5($password)
229
                ]);
230
            } catch (\Exception $e) {
231
                throw new RRException($e->getMessage(), 1);
232
            }
233
234
            Session::destroy();
235
            echo json_encode(['code' => 0, 'msg' => "保存成功"]);
236
            die();
237
        }
238
    }
177 239
178 240
    public function userlist()
179 241
    {
@ -190,18 +252,111 @@ class Index extends View
190 252
191 253
        if ($request->isPost()) {
192 254
            $id = isset($request->params['userid']) ? (int) $request->params['userid'] : 0;
193
    
194
            if (!$id)
195
            {
255
256
            if (!$id) {
196 257
                throw new RRException('userid 不能为空', 1);
197 258
            }
198 259
199 260
            $res = (new User())->deleteById($id);
200 261
201 262
            if ($res) {
202
                throw new RRException('操作成功', 0); 
263
                throw new RRException('操作成功', 0);
203 264
            } else {
204
                throw new RRException('操作失败', 1); 
265
                throw new RRException('操作失败', 1);
266
            }
267
        }
268
    }
269
270
    public function userinfo()
271
    {
272
        $request = Request::getInstance();
273
274
        $userid = isset($request->params['userid']) ? (int) $request->params['userid'] : 0;
275
276
        if ($userid !== 0) {
277
            $data = (new User())->getInfoById($userid);
278
279
            unset($data['password']);
280
281
            echo  json_encode(['code' => 0, 'info' => $data]);
282
        } else {
283
            throw new RRException("userid 不能为空", 1);
284
        }
285
        die();
286
    }
287
288
    public function usersave()
289
    {
290
        $request = Request::getInstance();
291
292
        if ($request->isPost()) {
293
            $id = isset($request->params['userid']) ? (int) $request->params['userid'] : 0;
294
295
            $user = new User();
296
297
            if ($id === 0) {
298
                // 新增
299
                $username = isset($request->params['username']) ? (string) $request->params['username'] : '';
300
301
                if (!$username) {
302
                    throw new RRException("用户名不能为空", 1);
303
                }
304
305
                $password = isset($request->params['password']) ? (string) $request->params['password'] : '';
306
                $repassword = isset($request->params['repassword']) ? (string) $request->params['repassword'] : '';
307
308
                if (!$password) {
309
                    throw new RRException("密码不能为空", 1);
310
                }
311
312
                if ($password != $repassword) {
313
                    throw new RRException("两次密码不一致", 1);
314
                }
315
316
                try {
317
                    $user->save([
318
                        'username' => $username,
319
                        'password' => md5($password),
320
                        'create_time' => time()
321
                    ]);
322
                } catch (\Exception $e) {
323
                    throw new RRException($e->getMessage(), 1);
324
                }
325
326
                echo json_encode(['code' => 0, 'msg' => "保存成功"]);
327
                die();
328
            } else {
329
                // 修改密码
330
                $password = isset($request->params['password']) ? (string) $request->params['password'] : '';
331
                $repassword = isset($request->params['repassword']) ? (string) $request->params['repassword'] : '';
332
333
                if (!$password) {
334
                    throw new RRException("密码不能为空", 1);
335
                }
336
337
                if ($password != $repassword) {
338
                    throw new RRException("两次密码不一致", 1);
339
                }
340
341
                // $userinfo = $user->getInfoById($id);
342
343
                // $newpassword = md5($password);
344
345
                // if ($newpassword != $userinfo['password']) {
346
                //     throw new RRException("原密码不正确", 1);
347
                // }
348
349
                try {
350
                    $user->updateById([
351
                        'id' => $id,
352
                        'password' => md5($password)
353
                    ]);
354
                } catch (\Exception $e) {
355
                    throw new RRException($e->getMessage(), 1);
356
                }
357
358
                echo json_encode(['code' => 0, 'msg' => "保存成功, 请重新登录."]);
359
                die();
205 360
            }
206 361
        }
207 362
    }

+ 18 - 2
application/model/MySqlite.php

@ -1,6 +1,8 @@
1 1
<?php
2 2
namespace app\model;
3 3
4
use \Exception;
5
4 6
class MySqlite
5 7
{
6 8
    private $mydb;
@ -171,10 +173,18 @@ class MySqlite
171 173
            $columns .=  "`" . $key . "`,";
172 174
            $values .=  "'" . $value . "',";
173 175
        }
176
        
174 177
        $columns = rtrim($columns, ',');
178
        
175 179
        $values = rtrim($values, ',');
180
        
176 181
        $sql = "INSERT INTO `$this->tablename`(" . $columns . ") VALUES(". $values . ");";
177
        return $this->exec($sql);
182
183
        if ($this->exec($sql)) {
184
            return true;
185
        } else {
186
            throw new Exception("Error SQL Request", 1);   
187
        }
178 188
    }
179 189
    
180 190
    /**
@ -189,8 +199,14 @@ class MySqlite
189 199
            $columns .= "`" . $key . "`='" . $value ."',";
190 200
        }
191 201
        $columns = rtrim($columns, ',');
202
        
192 203
        $sql = "UPDATE `$this->tablename` SET $columns WHERE `id`=$id";
193
        return $this->exec($sql);
204
205
        if ($this->exec($sql)) {
206
            return true;
207
        } else {
208
            throw new Exception("Error SQL Request", 1);   
209
        }
194 210
    }
195 211
196 212
    /**

+ 9 - 0
application/model/User.php

@ -27,5 +27,14 @@ class User extends MySqlite
27 27
28 28
        return $data;
29 29
    }
30
31
    public function getInfoById($userid)
32
    {
33
        $sql = "select * from " . $this->tablename . " where id='" . $userid . "' limit 1";
34
35
        $data = $this->getOne($sql);
36
37
        return $data;
38
    }
30 39
}
31 40

+ 0 - 1
public/index.html

@ -1 +0,0 @@
1
test

+ 6 - 1
public/static/css/index.css

@ -16,11 +16,16 @@ header span.logo {
16 16
    opacity: 1;
17 17
}
18 18
19
header button {
19
header button.btn-ml {
20 20
    margin-left: 16%;
21 21
  /* opacity: 1; */
22 22
}
23 23
24
header div.btn-right {
25
    float: right;
26
    margin-right: 10%;
27
}
28
24 29
header span img {
25 30
    position: relative;
26 31
    left: 56%;

+ 11 - 0
public/static/js/fun.js

@ -0,0 +1,11 @@
1
function isNull(str) {
2
    if (str == null || str == "" || str.length < 1)
3
        return true;
4
    else
5
        return false;
6
}
7
8
//检测密码规则--6位以上
9
function pwdFormat(pwd) {
10
    return pwd.match(/^.*(?=.{6,})/) ? true : false;
11
}

+ 348 - 0
view/editor.php

@ -0,0 +1,348 @@
1
<!DOCTYPE html>
2
<html>
3
4
	<head>
5
		<meta charset="UTF-8">
6
		<title>markdown编辑器</title>
7
		<link href="/static/css/markdown.css" rel="stylesheet" />
8
		<script src="/static/js/jquery.min.js"></script>
9
		<script src="/static/js/ace.js"></script>
10
		<script src="/static/js/marked.js"></script>
11
		<script src="/static/js/showPanel.js"></script>
12
13
		<style type="text/css">
14
			* {
15
				margin: 0;
16
				padding: 0;
17
				outline: none;
18
				border-radius: 0;
19
			}
20
			
21
			html,
22
			body {
23
				width: 100%;
24
				height: 100%;
25
				font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
26
				background-color: #ebebeb;
27
			}
28
			
29
			#bar {
30
				height: 130px;
31
				width: 100%;
32
				color: #fff;
33
			}
34
			
35
			#bar #topbar {
36
				height: 40px;
37
				background-color: #337AB7;
38
				width: 100%;
39
				color: #fff;
40
				line-height: 50px;
41
			}
42
			
43
			#bar #czbar {
44
				height: 50px;
45
				background-color: #FFFFFF;
46
				width: 100%;
47
				color: #fff;
48
				line-height: 50px;
49
			}
50
			
51
			#bar #toolbar {
52
				height: 40px;
53
				background-color: #337AB7;
54
				width: 100%;
55
				color: #fff;
56
				line-height: 50px;
57
			}
58
			
59
			#container {
60
				overflow: auto;
61
				position: absolute;
62
				bottom: 0;
63
				left: 0;
64
				right: 0;
65
				top: 130px;
66
			}
67
			
68
			#editor-column,
69
			#preview-column {
70
				width: 49.5%;
71
				height: 100%;
72
				overflow: auto;
73
				position: relative;
74
				background-color: #F6F6F6;
75
			}
76
			
77
			.pull-left {
78
				float: left;
79
			}
80
			
81
			.pull-right {
82
				float: right;
83
			}
84
			
85
			#toolbar img {
86
				width: 25px;
87
				height: 25px;
88
				padding-top: 8px;
89
				padding-bottom: 7px;
90
				margin-left: 10px;
91
			}
92
			
93
			#toolbar img:hover {
94
				background: #EBEBEB;
95
				cursor: pointer;
96
			}
97
			
98
			#commit {
99
				color: #FFFFFF;
100
				padding: 5px 15px;
101
				background: #BE1A21;
102
				border: 0px none #FFECEC;
103
			}
104
			
105
			#commit:hover {
106
				cursor: pointer;
107
				background: #CB474D;
108
			}
109
			
110
			#dialog{
111
				position: fixed;
112
				height: 400px;
113
				width: 550px;
114
				background: #FFFFFF;
115
				z-index: 5;
116
				left: 30%;
117
				border: 1px solid gray;
118
				top: 25%;
119
				display: none;
120
			}
121
			
122
			#showImg{
123
				height: 160px;
124
				width: 160px;
125
				position: absolute;
126
				border: 0.5px solid gainsboro;
127
				bottom: 80px;
128
				left:35%;
129
			}
130
			
131
			#cancel{
132
				border: 0px none #FFECEC;
133
				background: #999999;
134
				color: #FFFFFF;
135
				padding: 5px 15px;
136
				position: absolute;
137
				top: 8px;
138
				right: 100px;
139
			}
140
			
141
			#cancel:hover{
142
				background: #AAAAAA;	
143
			}
144
			
145
			#insert{
146
				border: 0px none #FFECEC;
147
				background: #BE1A21;
148
				color: #FFFFFF;
149
				padding: 5px 15px;
150
				position: absolute;
151
				top: 8px;
152
				right: 30px;
153
			}
154
			
155
			#insert:hover{
156
				background: #CB474D;
157
			}
158
			
159
			#upload{
160
				border: 0px none #FFECEC;
161
				background: #999999;
162
				color: #FFFFFF;
163
				padding: 7px 30px;
164
				position: absolute;
165
				top: 67px;
166
				right: 40px;
167
			}
168
			
169
			#upload:hover{
170
				background: #AAAAAA;	
171
			}
172
			
173
			#filediv{
174
				width: 70%;
175
				height: 30px;
176
				top: 70px;
177
				left: 20px;
178
				position: absolute;
179
				
180
			}
181
			
182
			#file{
183
				width: 95%;
184
				height: 30px;
185
				position: relative;
186
				top: -27px;
187
				opacity: 0.000001;
188
				cursor: pointer;
189
			}
190
			
191
			
192
		</style>
193
		
194
		<script>
195
			$(function(){
196
				$('#dialog').hide();
197
			})
198
			
199
			
200
		</script>
201
	</head>
202
203
	<body>
204
		<div id='bar'>
205
			<div id="topbar">
206
			</div>
207
			<div id="czbar">
208
				<input style="font-size: 26px;width: 80%;padding-left: 10px;border: 0px none #FFFFFF;padding-top: 5px;" type="text" value="文章标题" placeholder="文章标题" />
209
				<select id="group">
210
					<option value="volvo">android</option>
211
					<option value="saab">算法</option>
212
					<option value="opel">java思想</option>
213
					<option value="audi">web</option>
214
				</select>
215
				<button id="commit">发表博客</button>
216
			</div>
217
			<div id="toolbar">
218
				<img src="/static/img/bold.png" id="bold" onclick="insertText('**这里填写要加粗的文字**')"/>
219
				<img src="/static/img/italic.png" id="italic" onclick="insertText('_这里填写要斜体的文字_')"/>
220
				<img src="/static/img/hyperlink.png" id="hyperlink" onclick="insertText('[这里写连接的描述](这里填写连接地址)')"/>
221
				<img src="/static/img/code.png" id="code" onclick="insertText('```\n这里插入代码\n```')"/>
222
				<img src="/static/img/image.png" id="image" onclick="showDialog()"/>
223
			</div>
224
225
		</div>
226
		<div id='container'>
227
			<div id='editor-column' class='pull-left'>
228
				<div id='panel-editor' style="height: 100%;">
229
					<!--编辑区-->
230
					<div class="editor-content" id="mdeditor" style="height: 100%;"></div>
231
232
				</div>
233
			</div>
234
			<div id='preview-column' class='pull-right'>
235
				<div id='panel-preview'>
236
					<!--显示区-->
237
					<div id="preview" class="markdown-body"></div>
238
239
				</div>
240
			</div>
241
			
242
			<div id="dialog">
243
				<div style="position: absolute;height: 40px;width: 100%;background: #FFFFFF;border-bottom: 1px solid gray;">
244
					<span style="position: absolute;left: 10px;top: 10px;color: gray;">插入图片</span>
245
					<img src="img/X.png" style="height: 25px;width: 25px;position: absolute;right: 10px;top: 10px;cursor: pointer;" onclick="f_cancel()"/>
246
				</div>
247
				
248
				<div>
249
					<div id="filediv">
250
						<span style="background: gray;color: #FFFFFF;padding: 6px 10px;">选择图片</span>
251
						<input type="text" id="fileName" style="height: 25px;width: 70%;"/>
252
						
253
						<input type="file" id="file" name="file" onchange="setFile()"/>
254
					</div>
255
					<button id="upload" onclick="uploadFile()">上传</button>
256
				</div>
257
				
258
				<img  id="showImg"/>
259
				
260
				<div style="position: absolute;bottom: 1px;width: 100%;height: 40px;border-top: 1px solid gray;">
261
					<button id="cancel" onclick="f_cancel()">取消</button>
262
					<button id="insert" onclick="insert()">插入</button>
263
				</div>
264
			</div>
265
			
266
			<script>
267
				var imgUrl='';//上传图片返回的url
268
			
269
				var acen_edit = ace.edit('mdeditor');//左侧编辑框
270
				acen_edit.setTheme('ace/theme/chrome');
271
				acen_edit.getSession().setMode('ace/mode/markdown');
272
				acen_edit.renderer.setShowPrintMargin(false);
273
				$("#mdeditor").keyup(function() {//给左侧编辑框添加事件,,当键盘抬起时,右侧实时显示左侧的md内容
274
					$("#preview").html(marked(acen_edit.getValue()));
275
				});
276
				
277
278
				function f_commit() {
279
					console.log($('#group').val());
280
				}
281
				//DownPanel是我自己写的一个提示,当鼠标移到该dom上,回显示相关提示
282
				$('#bold').DownPanel({
283
					render: '<span style="color:#ffffff;">加粗</span>',
284
					background: '#000000',
285
					top: ($('#bold').offset().top + 40),
286
					left: ($('#bold').offset().left)
287
				});
288
				$('#code').DownPanel({
289
					render: '<span style="color:#ffffff;">插入代码</span>',
290
					background: '#000000',
291
					top: ($('#code').offset().top + 40),
292
					left: ($('#code').offset().left)
293
				});
294
				$('#hyperlink').DownPanel({
295
					render: '<span style="color:#ffffff;">插入超链接</span>',
296
					background: '#000000',
297
					top: ($('#hyperlink').offset().top + 40),
298
					left: ($('#hyperlink').offset().left)
299
				});
300
				$('#image').DownPanel({
301
					render: '<span style="color:#ffffff;">插入图片</span>',
302
					background: '#000000',
303
					top: ($('#image').offset().top + 40),
304
					left: ($('#image').offset().left)
305
				});
306
				$('#italic').DownPanel({
307
					render: '<span style="color:#ffffff;">斜体</span>',
308
					background: '#000000',
309
					top: ($('#italic').offset().top + 40),
310
					left: ($('#italic').offset().left)
311
				});
312
				
313
				//左侧插入,用户插入一些特定方法
314
				function insertText(val) {
315
					acen_edit.insert(val); //光标位置插入
316
				}
317
				
318
				//选择图片后,用于显示图片路径
319
				function setFile(){
320
					$('#fileName').val($('#file').val());
321
				}
322
				
323
				//上传图片到服务器,返回图片地址
324
				function uploadFile(){
325
					imgUrl='https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/logo_white.png';
326
					$('#showImg').attr('src','https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/logo_white.png');
327
				}
328
				
329
				//插入图片弹窗取消
330
				function f_cancel(){
331
					$('#dialog').hide();
332
				}
333
				
334
				//插入图片
335
				function insert(){
336
					$('#dialog').hide();
337
					insertText('![这里写图片描述]('+imgUrl+')')
338
				}
339
				
340
				//显示弹窗
341
				function showDialog(){
342
					$('#dialog').show();
343
				}
344
				
345
			</script>
346
	</body>
347
348
</html>

+ 117 - 39
view/index.php

@ -4,6 +4,7 @@
4 4
    <link rel="stylesheet" href="/static/css/bootstrap.min.css">
5 5
    <link rel="stylesheet" href="/static/css/index.css">
6 6
    <script src="/static/js/jquery.min.js"></script>
7
    <script src="/static/js/fun.js"></script>
7 8
    <script src="/static/js/bootstrap.min.js"></script>
8 9
    <script src="/static/js/axios.min.js"></script>
9 10
    <!-- <script src="https://cdn.bootcss.com/axios/0.17.1/axios.min.js"></script> -->
@ -32,39 +33,44 @@
32 33
            <a href="/index">HUWIKI</a>
33 34
        </span>
34 35
        <!-- Button trigger modal -->
35
        <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" onclick="edit()">
36
        <button type="button" class="btn btn-primary btn-lg btn-ml" data-toggle="modal" onclick="edit()">
36 37
            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> 编辑
37 38
        </button>
38
        <button type="button" class="btn btn-primary btn-lg" onclick="logout()">
39
            <span class="glyphicon glyphicon-log-out" aria-hidden="true"></span> 退出
40
        </button>
41
        <button type="button" class="btn btn-primary btn-lg" onclick="window.location.href='/userlist'">
42
            <span class="glyphicon glyphicon-user" aria-hidden="true"></span> 用户管理
43
        </button>
39
        <div class="btn-group btn-right" role="group" aria-label="user">
40
            <button type="button" class="btn btn-primary" onclick="window.location.href='/logout'">
41
                <span class="glyphicon glyphicon-log-out" aria-hidden="true"></span> 退出
42
            </button>
43
            <button type="button" class="btn btn-primary" onclick="window.location.href='/userlist'">
44
                <span class="glyphicon glyphicon-user" aria-hidden="true"></span> 用户管理
45
            </button>
46
            <button type="button" class="btn btn-primary" onclick="password()">
47
                <span class="glyphicon glyphicon-cog" aria-hidden="true"></span> 修改密码
48
            </button>
49
        </div>
44 50
    </header>
45 51
    <aside>
46 52
        <div class="nav" style="z-index: 99;">
47 53
            <span>位置: <a href="/index">index</a></span>
48 54
            <?php
49
                $dir_name = pathinfo($doc, PATHINFO_DIRNAME);
50
                $nav = explode('/',$dir_name);
51
                $temp = "/index/";
52
                foreach ($nav as $val) {
53
                    if ($val=='.' || $val == '..') {
54
                        continue;
55
                    } else {
55
            $dir_name = pathinfo($doc, PATHINFO_DIRNAME);
56
            $nav = explode('/', $dir_name);
57
            $temp = "/index/";
58
            foreach ($nav as $val) {
59
                if ($val == '.' || $val == '..') {
60
                    continue;
61
                } else {
56 62
            ?>
57
            <span> / <a href="<?php echo $temp.$val.'/index.md';?>">
58
                    <?php echo $val;?>
59
                </a></span>
63
                    <span> / <a href="<?php echo $temp . $val . '/index.md'; ?>">
64
                            <?php echo $val; ?>
65
                        </a></span>
60 66
            <?php
61
                    }
62
                    $temp .= $val ."/";
63 67
                }
68
                $temp .= $val . "/";
69
            }
64 70
            ?>
65 71
        </div>
66 72
        <div class="toc">
67
            <?php echo $toc;?>
73
            <?php echo $toc; ?>
68 74
        </div>
69 75
    </aside>
70 76
    <!--article标签中就是我们编写的文本内容-->
@ -74,15 +80,15 @@
74 80
        </div>
75 81
        <div class="content">
76 82
            <?php
77
                if ($is_file_exists) {
78
                    echo $content;
79
                } else {
83
            if ($is_file_exists) {
84
                echo $content;
85
            } else {
80 86
            ?>
81
            <div class="is_file_exists">
82
                <span>文档不存在, 点击<a href='javascript:void(0213123);' onclick='edit()'>新建文档</a></span>
83
            </div>
87
                <div class="is_file_exists">
88
                    <span>文档不存在, 点击<a href='javascript:void(0213123);' onclick='edit()'>新建文档</a></span>
89
                </div>
84 90
            <?php
85
                }
91
            }
86 92
            ?>
87 93
        </div>
88 94
    </article>
@ -92,31 +98,61 @@
92 98
        <div class="modal-dialog" role="document">
93 99
            <div class="modal-content modal-edit">
94 100
                <div class="modal-header">
95
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
96
                            aria-hidden="true">&times;</span></button>
101
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
97 102
                    <h4 class="modal-title" id="myModalLabel">编辑</h4>
98 103
                </div>
99 104
                <div class="modal-body">
100
                    <div class="editor-content" id="mdeditor" style="height: 70%;"><?php echo $text;?></div>
101
                    <!-- <textarea class="form-control" rows="20" style="resize:vertical" id="mdeditor" name="mdeditor"><?php echo $text;?></textarea> -->
105
                    <div class="editor-content" id="mdeditor" style="height: 70%;"><?php echo $text; ?></div>
106
                    <!-- <textarea class="form-control" rows="20" style="resize:vertical" id="mdeditor" name="mdeditor"><?php echo $text; ?></textarea> -->
102 107
                    <!-- begin code -->
103
                    <!-- <textarea class="form-control" id="mdeditor" name="mdeditor"><?php echo $text;?></textarea> -->
108
                    <!-- <textarea class="form-control" id="mdeditor" name="mdeditor"><?php echo $text; ?></textarea> -->
104 109
                    <!-- end code-->
105 110
                </div>
106 111
                <div class="modal-footer">
107 112
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
108
                    <button type="button" class="btn btn-primary" onclick="save('<?php echo $doc;?>')">Save
113
                    <button type="button" class="btn btn-primary" onclick="save('<?php echo $doc; ?>')">Save
109 114
                        changes</button>
110 115
                </div>
111 116
            </div>
112 117
        </div>
113 118
    </div>
114 119
120
    <!-- 修改密码 Modal  -->
121
    <div class="modal fade" id="passModal" tabindex="-1" role="dialog" aria-labelledby="passModalLabel">
122
        <div class="modal-dialog" role="document" style="margin-top: 200px;">
123
            <div class="modal-content modal-add">
124
                <div class="modal-header">
125
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
126
                    <h4 class="modal-title" id="passModalLabel">修改密码</h4>
127
                </div>
128
                <div class="modal-body">
129
                    <div class="form-group">
130
                        <label for="oldpassword">原密码</label>
131
                        <input type="password" class="form-control" id="oldpassword" placeholder="请输入原密码">
132
                    </div>
133
                    <div class="form-group">
134
                        <label for="newpassword">新密码</label>
135
                        <input type="password" class="form-control" id="newpassword" placeholder="请输入新密码">
136
                    </div>
137
                    <div class="form-group">
138
                        <label for="password">确认密码</label>
139
                        <input type="password" class="form-control" id="repassword" placeholder="请再次输入密码">
140
                    </div>
141
                </div>
142
                <div class="modal-footer">
143
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
144
                    <button type="button" class="btn btn-primary" onclick="dopassword()">SAVE</button>
145
                </div>
146
            </div>
147
        </div>
148
    </div>
149
    <!-- model end -->
150
115 151
    <script>
116
        $(document).ready(function () {
152
        $(document).ready(function() {
117 153
            // 表格加上边框
118 154
            $("table").addClass('table table-bordered');
119
            
155
120 156
            if (storage.getItem("headerColor")) {
121 157
                var color = storage.getItem("headerColor");
122 158
@ -136,6 +172,7 @@
136 172
                $(obj).data("status", 0);
137 173
            }
138 174
        }
175
139 176
        function doChange(color) {
140 177
            // console.log(color);
141 178
            // var color = $(obj).val();
@ -151,12 +188,12 @@
151 188
        });
152 189
153 190
        // ace 编辑器
154
        var editor = ace.edit('mdeditor');//左侧编辑框
191
        var editor = ace.edit('mdeditor'); //左侧编辑框
155 192
        editor.setTheme('ace/theme/chrome');
156 193
        editor.getSession().setMode('ace/mode/markdown');
157 194
        editor.renderer.setShowPrintMargin(false);
158 195
159
        var imgUrl = '';//上传图片返回的url
196
        var imgUrl = ''; //上传图片返回的url
160 197
161 198
        // codemirror
162 199
        // var editor = CodeMirror.fromTextArea(document.getElementById("mdeditor"), {
@ -195,7 +232,7 @@
195 232
                method: "POST",
196 233
                url: `/save`,
197 234
                data: JSON.stringify(params),
198
            }).then(function (res) {
235
            }).then(function(res) {
199 236
                if (res.data.code == 0) {
200 237
                    // acen_edit.destroy();
201 238
                    // acen_edit.container.remove();
@ -206,10 +243,51 @@
206 243
                } else {
207 244
                    alert(res.data.msg);
208 245
                }
209
            }).catch(function (error) {
246
            }).catch(function(error) {
210 247
                console.log(error);
211 248
            });
212 249
        }
250
251
        function password() {
252
            $("#passModal").modal('show');
253
        }
254
255
        function dopassword() {
256
            let oldpassword = document.querySelector('#oldpassword').value;
257
            let newpassword = document.querySelector('#newpassword').value;
258
            let repassword = document.querySelector('#repassword').value;
259
260
            if (isNull(newpassword)) {
261
                alert("密码不能为空.");
262
                return false;
263
            }
264
265
            if (!pwdFormat(newpassword)) {
266
                alert("密码需6位以上.");
267
                return false;
268
            }
269
270
            if (newpassword != repassword) {
271
                alert("两次密码不一致.");
272
                return false;
273
            }
274
275
            $.post(
276
                '/password', {
277
                    "oldpassword": oldpassword,
278
                    "newpassword": newpassword,
279
                    "repassword": repassword
280
                },
281
                function(res) {
282
                    if (res.code == 0) {
283
                        alert(res.msg);
284
                        window.location.href = "/login";
285
                    } else {
286
                        alert(res.msg);
287
                        return false;
288
                    }
289
                }, 'json');
290
        }
213 291
    </script>
214 292
</body>
215 293

+ 1 - 1
view/login.php

@ -64,7 +64,7 @@
64 64
                var uname = $("#username").val();
65 65
                var upwd = $("#userpwd").val();
66 66
67
                $.post('/dologin', {
67
                $.post('/login', {
68 68
                   'username' :  uname,
69 69
                   'password' :  upwd,
70 70
                }, function(res){

+ 103 - 13
view/userlist.php

@ -6,6 +6,7 @@
6 6
    <link rel="stylesheet" href="/static/css/bootstrap.min.css">
7 7
    <script src="/static/js/jquery.min.js"></script>
8 8
    <script src="/static/js/bootstrap.min.js"></script>
9
    <script src="/static/js/fun.js"></script>
9 10
    <title>用户列表</title>
10 11
11 12
    <style>
@ -21,7 +22,8 @@
21 22
<body>
22 23
    <div class="box">
23 24
        <div class="row col-md-8">
24
            <button type="button" class="btn btn-primary">新增</button>
25
            <button type="button" class="btn btn-primary" onclick="add()">新增</button>
26
            <a href="/index" type="button" class="btn btn-default">返回</a>
25 27
            <table class="table table-bordered">
26 28
                <thead>
27 29
                    <tr>
@ -47,8 +49,12 @@
47 49
                            <td><?php echo $value['id']; ?></td>
48 50
                            <td><?php echo $value['username']; ?></td>
49 51
                            <td><?php echo date('Y-m-d H:i:s', $value['create_time']); ?></td>
50
                            <td><a type="button" class="btn btn-danger" href="javascript:del(<?php echo $value['id']; ?>)">
51
                                <span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></td>
52
                            <td>
53
                                <a type="button" class="btn btn-primary" href="javascript:add(<?php echo $value['id']; ?>)">
54
                                    <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a>
55
                                <a type="button" class="btn btn-danger" href="javascript:del(<?php echo $value['id']; ?>)">
56
                                    <span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
57
                            </td>
52 58
                        </tr>
53 59
                    <?php
54 60
                    }
@ -57,27 +63,111 @@
57 63
            </table>
58 64
        </div>
59 65
    </div>
60
    
61 66
67
    <!-- 新增 Modal  -->
68
    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel">
69
        <div class="modal-dialog" role="document" style="margin-top: 200px;">
70
            <div class="modal-content modal-add">
71
                <div class="modal-header">
72
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
73
                    <h4 class="modal-title" id="addModalLabel">新增</h4>
74
                </div>
75
                <div class="modal-body">
76
                    <input type="hidden" name="userid" id="userid" value="0">
77
                    <div class="form-group">
78
                        <label for="username">用户名</label>
79
                        <input type="text" class="form-control" id="username" placeholder="请输入用户名">
80
                    </div>
81
                    <div class="form-group">
82
                        <label for="password">密码</label>
83
                        <input type="password" class="form-control" id="password" placeholder="请输入密码">
84
                    </div>
85
                    <div class="form-group">
86
                        <label for="password">确认密码</label>
87
                        <input type="password" class="form-control" id="repassword" placeholder="请再次输入密码">
88
                    </div>
89
                </div>
90
                <div class="modal-footer">
91
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
92
                    <button type="button" class="btn btn-primary" onclick="save()">SAVE</button>
93
                </div>
94
            </div>
95
        </div>
96
    </div>
97
    <!-- model end -->
62 98
63 99
    <script>
64
        function del(id)
65
        {
100
        function del(id) {
66 101
            $.post('/userdelete', {
67
                   'userid' :  id,
68
                }, function(res){
69
                    console.log(res);
102
                'userid': id,
103
            }, function(res) {
104
                console.log(res);
105
                if (res.code == 0) {
106
                    alert('操作成功');
107
108
                    window.location.reload();
109
                } else {
110
                    alert(res.msg);
111
                }
112
                return false;
113
            }, 'json');
114
        }
115
116
        function add(userid) {
117
            userid = userid || 0;
118
119
            if (userid != 0) {
120
                $.get('userinfo', {
121
                    'userid': userid,
122
                }, function(res) {
123
                    $("#userid").val(res.info.id);
124
                    $("#username").val(res.info.username);
125
                    $("#username").attr('disabled', true);
126
                }, 'json')
127
            }
128
129
            $("#addModal").modal('show');
130
        }
131
132
        function save() {
133
            let userid = document.querySelector('#userid').value;
134
            let username = document.querySelector('#username').value;
135
            let password = document.querySelector('#password').value;
136
            let repassword = document.querySelector('#repassword').value;
137
138
            if (isNull(password)) {
139
                alert("密码不能为空.");
140
                return false;
141
            }
142
143
            if (!pwdFormat(password)) {
144
                alert("密码需6位以上.");
145
                return false;
146
            }
147
148
            if (password != repassword) {
149
                alert("两次密码不一致.");
150
                return false;
151
            }
152
153
            $.post(
154
                '/usersave', {
155
                    "userid": userid,
156
                    "username": username,
157
                    "password": password,
158
                    "repassword": repassword
159
                },
160
                function(res) {
161
                    // console.log(res);
70 162
                    if (res.code == 0) {
71
                        alert('操作成功');
72
                        
163
                        alert(res.msg);
73 164
                        window.location.reload();
74 165
                    } else {
75 166
                        alert(res.msg);
167
                        return false;
76 168
                    }
77
                    return false;
78 169
                }, 'json');
79 170
        }
80
81 171
    </script>
82 172
</body>
83 173