-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
277 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
'use strict' | ||
const path = require('path') | ||
const fs = require('fs') | ||
const bodyParser = require('body-parser') | ||
const MongoClient = require('mongodb').MongoClient | ||
|
||
module.exports.getLoginPage = (req, res) => { | ||
|
||
console.log('LoginPage') | ||
fs.readFile(path.join(__dirname, '../views/login.html'), (error, content) => { | ||
if (error) console.log(error) | ||
res.setHeader('Content-Type', 'text/html;charset=utf-8') | ||
res.end(content) | ||
}) | ||
} | ||
|
||
module.exports.login = (req, res) => { | ||
|
||
console.log(req.body) | ||
|
||
const url = 'mongodb://localhost:27017/musicmanager' | ||
// 连接数据库 | ||
MongoClient.connect(url, (error, db) => { | ||
db.collection('account').findOne({ | ||
username: req.body.uname, | ||
password: req.body.pwd, | ||
status: 0 | ||
}, (error, doc) => { | ||
if (error) console.log(error) | ||
console.log(doc) | ||
if (doc !== null) { | ||
res.end('login success') | ||
} else { | ||
res.end('<script>alert("用户名或密码错误,请重新登录"); window.location.href = "/account/login"</script>') | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict' | ||
const path = require('path') | ||
const fs = require('fs') | ||
const MongoClient = require('mongodb').MongoClient | ||
|
||
module.exports.getStudentList = (req, res) => { | ||
console.log('studentList') | ||
fs.readFile(path.join(__dirname, '../views/login.html'), (error, content) => { | ||
if (error) console.log(error) | ||
res.setHeader('Content-Type', 'text/html;charset=utf-8') | ||
res.end(content) | ||
}) | ||
} | ||
|
||
module.exports.login = (req, res) => { | ||
console.log(req.body) | ||
|
||
const url = 'mongodb://localhost:27017/musicmanager' | ||
// 连接数据库 | ||
MongoClient.connect(url, (error, db) => { | ||
db.collection('account').findOne({ | ||
username: req.body.uname, | ||
password: req.body.pwd, | ||
status: 0 | ||
}, (error, doc) => { | ||
if (error) console.log(error) | ||
console.log(doc) | ||
if (doc !== null) { | ||
res.end('login success') | ||
} else { | ||
res.end('<script>alert("用户名或密码错误,请重新登录"); window.location.href = "/account/login"</script>') | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict' | ||
const express = require('express') | ||
const path = require('path') | ||
|
||
// 创建路由 | ||
const studentManagerRouter = express.Router() | ||
|
||
const studentManagerCtrl = require(path.join(__dirname, '../controller/studentManagerController')) | ||
|
||
studentManagerRouter.get('/login', studentManagerCtrl.getStudentList) | ||
|
||
// studentManagerRouter.post('/login', studentManagerCtrl.login) | ||
|
||
module.exports = studentManagerRouter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,47 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>欢迎登录</title> | ||
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css"> | ||
<title>欢迎登录</title> | ||
<link rel="stylesheet" type="text/css" href="/bootstrap/css/bootstrap.min.css"> | ||
</head> | ||
|
||
<body> | ||
<div class="container" style="margin-top:180px; "> | ||
<div class="container" style="margin-top:180px; "> | ||
|
||
<div class="col-md-6 col-md-offset-3"> | ||
<div class="panel panel-primary"> | ||
<div class="panel-heading">登录学生管理系统</div> | ||
<div class="panel-body"> | ||
<form action="/account/login" method="post" class="form-horizontal"> | ||
<div class="form-group"> | ||
<label for="uname" class="col-sm-2 control-label">用户名</label> | ||
<div class="col-sm-10"> | ||
<input type="text" class="form-control" name="uname" id="uname" placeholder="请输入用户名"> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label for="pwd" class="col-sm-2 control-label">密码</label> | ||
<div class="col-sm-10"> | ||
<input type="password" class="form-control" name="pwd" id="upwd" placeholder="请输入密码"> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<div class="col-sm-offset-2 col-sm-10"> | ||
<button type="submit" class="btn btn-default">登录</button> | ||
| ||
<input onclick="register();" type="button" value="注册" class="btn btn-danger"> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script type="text/javascript"> | ||
function register() { | ||
window.location.href = '/account/register'; | ||
} | ||
</script> | ||
<div class="col-md-6 col-md-offset-3"> | ||
<div class="panel panel-primary"> | ||
<div class="panel-heading">登录音乐管理系统</div> | ||
<div class="panel-body"> | ||
<form action="/account/login" method="post" class="form-horizontal"> | ||
<div class="form-group"> | ||
<label for="uname" class="col-sm-2 control-label">用户名</label> | ||
<div class="col-sm-10"> | ||
<input type="text" class="form-control" name="uname" id="uname" placeholder="请输入用户名"> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label for="pwd" class="col-sm-2 control-label">密码</label> | ||
<div class="col-sm-10"> | ||
<input type="password" class="form-control" name="pwd" id="upwd" placeholder="请输入密码"> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<div class="col-sm-offset-2 col-sm-10"> | ||
<button type="submit" class="btn btn-default">登录</button> | ||
<input onclick="register();" type="button" value="注册" class="btn btn-danger"> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script type="text/javascript"> | ||
function register() { | ||
window.location.href = '/account/register'; | ||
} | ||
</script> | ||
</body> | ||
</html> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!-- 父页面中包含头部 左边的内容 还有右边的占位符 --> | ||
<!DOCTYPE html> | ||
<html lang="zh-CN"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! --> | ||
<title></title> | ||
<!-- Bootstrap --> | ||
<link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet"> | ||
<script type="text/javascript" src="/js/jquery.min.js"></script>> | ||
<link rel="stylesheet" href="/css/site.css"> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<nav class="navbar navbar-default"> | ||
<div class="container-fluid"> | ||
<div class="navbar-header"> | ||
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-5" aria-expanded="false"> | ||
<span class="sr-only">Toggle navigation</span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
<span class="icon-bar"></span> | ||
</button> | ||
<a class="navbar-brand" href="#">欢迎进入后台管理</a> | ||
</div> | ||
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-5"> | ||
<p class="navbar-text navbar-right">欢迎【{{loginedname}}】登录 <a href="javascript:logout()" class="navbar-link">退出</a></p> | ||
</div> | ||
</div> | ||
</nav> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-md-3"> | ||
<div class="list-group"> | ||
<a href="#" class="list-group-item active"> | ||
学生管理 | ||
</a> | ||
<a href="#" class="list-group-item">系统管理</a> | ||
<a href="#" class="list-group-item">用户管理</a> | ||
<a href="#" class="list-group-item">修改密码</a> | ||
<a href="#" class="list-group-item">退出系统</a> | ||
</div> | ||
</div> | ||
<div class="col-md-9"> | ||
|
||
{{{block ("body")}}} | ||
|
||
</div> | ||
</div> | ||
</div> | ||
<script type="text/javascript"> | ||
function logout(){ | ||
if (confirm("确认退出?")) { | ||
window.location.href = '/account/logout'; | ||
} | ||
} | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{{extend ("./parent.html")}} | ||
|
||
{{#block ("body")}} | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<ol class="breadcrumb"> | ||
<li><a href="#">首页</a></li> | ||
<li><a href="#">学生管理</a></li> | ||
<li class="active">学生列表</li> | ||
</ol> | ||
</div> | ||
<div class="panel-heading"> | ||
<div class="input-group"> | ||
<span class="input-group-addon" id="basic-addon1">学生姓名</span> | ||
<input type="text" class="form-control" id="studentName" placeholder="请输入学生姓名进行查询" aria-describedby="basic-addon1" style="width:200px;margin-right:10px;" value="{{keyword}}"> | ||
<input type="button" class="btn btn-success" onclick='search()' value="查找" style="margin-right:10px;"> | ||
<input type="button" class="btn btn-success" value="新增" onclick="window.location='/studentmanager/add'"> | ||
</div> | ||
</div> | ||
<div class="panel-body"> | ||
<table class="table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th>姓名</th> | ||
<th>年龄</th> | ||
<th>性别</th> | ||
<th>手机号码</th> | ||
<th>操作</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{{#each(studentlist)}} | ||
<tr> | ||
<td>{{this.name}}</td> | ||
<td>{{this.age}}</td> | ||
<td>{{this.sex}}</td> | ||
<td>{{this.phone}}</td> | ||
<td> | ||
<a href="/studentmanager/edit/{{this._id}}" class ="btn btn-success" >编辑</a> | | ||
|
||
<input type="button" class ="btn btn-danger" onclick="del('{{this._id}}')" value="删除"> | ||
</td> | ||
</tr> | ||
{{/each}} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
<script type="text/javascript"> | ||
function del(studentId) { | ||
if (!confirm("确定要删除该条数据吗?")) { | ||
return; | ||
} | ||
|
||
var url = '/studentmanager/delete/'+studentId; | ||
$.getJSON(url,null,function(jsObj){ | ||
if (jsObj.status==0) {//失败 | ||
alert(jsObj.message) | ||
}else{ //成功 | ||
//alert(jsObj.message) | ||
window.location = window.location | ||
} | ||
}) | ||
} | ||
|
||
//搜索 | ||
function search(){ | ||
var studentName = $("#studentName").val(); | ||
|
||
window.location.href="/studentmanager/list?keyword="+studentName; | ||
} | ||
</script> | ||
{{/block}} |