Skip to content

Commit 1676c25

Browse files
committed
修改了登录页面
1 parent ff5ddd1 commit 1676c25

File tree

12 files changed

+255
-7
lines changed

12 files changed

+255
-7
lines changed

app.js

+14
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ app.configure('development', function(){
3535
app.use(express.errorHandler());
3636
});
3737

38+
39+
app.all('/*', function (req, res,next) {
40+
if(req.url.indexOf('/login')!=-1||req.session.uid){
41+
res.locals({
42+
session: req.session
43+
});
44+
return next();
45+
}else{
46+
console.log(req.url);
47+
req.session.lasturl=req.url;
48+
return res.redirect('/login');
49+
}
50+
});
51+
3852
routes(app);
3953

4054
http.createServer(app).listen(app.get('port'), function(){

controllers/login.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
exports.index = function(req, res) {
3+
res.render('login',{layout:false});
4+
}
5+
6+
exports.check = function(req, res) {
7+
var uid = req.body.id;
8+
var pwd =req.body.pswd;
9+
req.session.uid = uid;
10+
res.redirect('/bbsdoc?board=PPPerson');
11+
}
12+
13+
exports.logout = function(req, res, next) {
14+
req.session.destroy();
15+
// res.clearCookie(config.auth_cookie_name, { path: '/' });
16+
res.redirect('/');
17+
};

libs/client.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var http = require('http');
2+
var parse = require('url').parse;
3+
var timeoutTime= 15000; //timeout in millisecond
4+
5+
exports.get = function(path,callback){
6+
var options = {
7+
host : 'bbs.sjtu.edu.cn',
8+
port : '80',
9+
path : path,
10+
method :'GET',
11+
headers: {
12+
'Host':'bbs.sjtu.edu.cn',
13+
}
14+
};
15+
// 设置请求超时
16+
var req = null ,req_timeout = null;
17+
var bufArr = [];
18+
var size = 0;
19+
20+
req_timeout = setTimeout(function() {
21+
req_timeout = null;
22+
console.log("timed out here in global");
23+
req.abort();
24+
callback(null);
25+
}, timeoutTime);
26+
27+
req = http.request(options, function(res) {
28+
res.on('data', function (chuck) {
29+
tmp = new Buffer(chuck);
30+
size += tmp.length;
31+
bufArr.push(tmp);
32+
}).on('end', function(){
33+
//clear the timeout when the request is finished or failed
34+
clearTimeout(req_timeout);
35+
callback(Buffer.concat(bufArr,size));
36+
37+
}).on('error', function(err) {
38+
clearTimeout(req_timeout);
39+
callback(err /* , res */);
40+
}).on('aborted', function() {
41+
clearTimeout(req_timeout);
42+
});
43+
}).on('error', function(e) {
44+
if(req_timeout) {
45+
clearTimeout(req_timeout);
46+
//console.log("Got error: " + e.message);
47+
callback(null );
48+
}
49+
});
50+
req.end();
51+
52+
}
53+
54+

libs/logger.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*!
2+
* MongDB logger
3+
* Copyright(c) 2010 Taguage Inc.
4+
* Copyright(c) 2011 Tank
5+
* MIT Licensed
6+
*/
7+
8+
/**
9+
* Module dependencies.
10+
*/
11+
12+
exports = module.exports = function logger(req,res,next) {
13+
console.log(req.url);
14+
var data = {};
15+
data['date'] = new Date();
16+
var end = res.end;
17+
res.end = function(chunk, encoding){
18+
res.end = end;
19+
res.end(chunk, encoding);
20+
console.log('---');
21+
data['uid'] = req.body.myaid;
22+
data['method'] = req.method.toLowerCase();
23+
data['path'] = req.path;
24+
data['params'] = req.params||req.body;
25+
data['user-agent'] = req.headers['user-agent'];
26+
data['remote-addr'] = req.socket && (req.socket.remoteAddress || (req.socket.socket && req.socket.socket.remoteAddress));
27+
data['http-ver'] = req.httpVersionMajor + '.' + req.httpVersionMinor;
28+
data['ref'] = req.headers['referer'] || req.headers['referrer'];
29+
data['status'] = res.statusCode;
30+
data['resp-time'] = new Date - data['date'];
31+
};
32+
next();
33+
};
34+
35+

public/bootstrap/css/bootstrap.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ input[type="color"],
10031003
input,
10041004
textarea,
10051005
.uneditable-input {
1006-
width: 206px;
1006+
width: 146px;
10071007
}
10081008

10091009
textarea {
@@ -5827,7 +5827,7 @@ a.badge:hover {
58275827
left: 0;
58285828
padding: 15px;
58295829
background: #333333;
5830-
background: rgba(0, 0, 0, 0.75);
5830+
background: rgba(0, 0, 0, 0.4);
58315831
}
58325832

58335833
.carousel-caption h4,

public/css/main.css

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ a.redbtn{
2828
top:80px;
2929
left:40px;
3030
z-index: 100;
31+
border:solid 2px #d0d0d0;
3132
}
3233

3334
#html {

py/deal.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
#
4+
5+
import pymongo
6+
7+
#MongoDB基本配置
8+
MONGO_IP = '202.120.32.15'
9+
MONGO_PORT = 27017
10+
11+
#数据库相关初始化
12+
connection = pymongo.Connection(MONGO_IP, MONGO_PORT)
13+
db_bbs = connection['bbs']
14+
15+
16+
'''
17+
处理图片节点
18+
'''
19+
def dealImgTag():
20+
count = 0
21+
for i in db_bbs['article_p'].find():
22+
count = count + 1
23+
tmp = i['content'].encode('utf-8');
24+
tmp = tmp.replace('<img src="http://bbs.sjtu.edu.cn/file','<img src="/file')
25+
print tmp
26+
print count
27+
db_bbs['article_p'].update({'_id':i['_id']},{'$set':{'content':tmp}})
28+
29+
if __name__ == "__main__":
30+
dealImgTag()
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+

py/html模板.txt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
http://themeforest.net/item/wrapper-responsive-template/full_screen_preview/3105611
2+
3+
http://themeforest.net/item/shiny-html-version/full_screen_preview/3164427
4+
5+
http://themeforest.net/item/folio-a-single-page-portfolio-template/full_screen_preview/3140062
6+
7+
http://themeforest.net/item/sniper-premium-photography-template/full_screen_preview/3058003
8+
9+
http://themeforest.net/item/crevision-responsive-html-template/full_screen_preview/3083469
10+
11+
http://themeforest.net/item/3deep-3d-perspective-template/full_screen_preview/3080522
12+
13+
http://themeforest.net/item/synergy-responsive-interactive-html-portfolio/full_screen_preview/3054099
14+
15+
http://themeforest.net/item/pizzeria-responsive-fullscreen-onepage-template/full_screen_preview/3000382
16+
17+
http://themeforest.net/item/protondiagonal-scrolling-responsive-portfolio-theme/full_screen_preview/2906713
18+
19+
http://themeforest.net/item/spotless-responsive-one-page-theme/full_screen_preview/2892317
20+
21+
http://themeforest.net/item/scrn-responsive-parallax-template/full_screen_preview/2862569
22+
23+
http://themeforest.net/item/scrn-responsive-parallax-template/full_screen_preview/2862569
24+
25+
26+
http://themeforest.net/item/starlight-responsive-portfolio/full_screen_preview/2790032
27+
28+
http://www.unpezvivo.com/proyectos/themeforest/agora/sans-serif/index.html
29+
30+
http://demo.brankic.net/?theme=BigBang
31+
32+
http://themes.virae.org/?theme=plain

routes.js

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var login = require('./controllers/login');
99
exports = module.exports = function(app) {
1010
app.get ('/' , main.index);
1111
app.get ('/login' , login.index);
12+
app.get ('/logout' , login.logout);
13+
app.post ('/login' , login.check);
1214
app.get ('/bbsdoc' , board.list);
1315
app.get ('/bbscont/:id' , article.view);
1416
app.get ('/page/:id' , page.next);

views/board/info.ejs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<div id="board-info">
22
<h5 class="title">PPPerson(美丽人物)</h5>
3-
<div style="padding:10px">
3+
<div style="padding:10px;">
44
<p>版主:</p>
55
<a style="color:#009a61;text-decoration:none" href="/bbsqry?userid=Oct" target="_blank">Oct</a>
66
</div>
77
<div class="bottom">
8-
<a href="/bbscont/508fcfc10a26c1056c167657" class="mybtn" target="_blank">查看 ➔</a>
98
</div>
109
</div>

views/layout.ejs

+6-3
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,18 @@
4444
</form>
4545
<ul class="nav pull-right">
4646
<li class="divider-vertical"></li>
47-
<li><a href="/">登录</a></li>
47+
<%if(session.uid){%>
4848
<li class="dropdown">
49-
<a href="#" class="dropdown-toggle" data-toggle="dropdown">登录<b class="caret"></b></a>
49+
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><%=session.uid%><b class="caret"></b></a>
5050
<ul class="dropdown-menu">
5151
<li><a href="#">设置</a></li>
5252
<li class="divider"></li>
53-
<li><a href="#">退出</a></li>
53+
<li><a href="/logout">退出</a></li>
5454
</ul>
5555
</li>
56+
<%}else{%>
57+
<li><a href="/">登录</a></li>
58+
<%}%>
5659
</ul>
5760
</div><!-- /.nav-collapse -->
5861
</div>

views/login/index.ejs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>饮水思源·交大bbs站</title>
5+
<link rel="stylesheet" href="/bootstrap/css/bootstrap.css">
6+
<link rel="stylesheet" href="/css/isotope.css">
7+
<link rel="stylesheet" href="/bootstrap/css/bootstrap-responsive.css">
8+
<script src="/js/jquery-1.7.2.min.js"></script>
9+
<script src="/bootstrap/js/bootstrap.min.js"></script>
10+
<style>
11+
#login{
12+
margin: auto;
13+
width:90%;
14+
padding:10px;
15+
border:solid 1px #d0d0d0;
16+
}
17+
</style>
18+
<body>
19+
<div style="width:700px;float:center;margin:auto;margin-top:50px;">
20+
<div id="myCarousel" class="carousel slide">
21+
<div class="carousel-inner">
22+
<div class="item active">
23+
<img src="https://bbs.sjtu.edu.cn/file/bbs/index/default1.jpg" alt="">
24+
<div class="carousel-caption">
25+
<h4>图一</h4>
26+
<p>爱水源爱交大</p>
27+
</div>
28+
</div>
29+
<div class="item">
30+
<img src="https://bbs.sjtu.edu.cn/file/bbs/index/default2.jpg" alt="">
31+
<div class="carousel-caption">
32+
<h4>图二</h4>
33+
<p>爱水源爱交大</p>
34+
</div>
35+
</div>
36+
</div>
37+
<a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>
38+
<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>
39+
</div>
40+
<form id="login" class="form-inline" action="/login" method="post">
41+
<input name="id" type="text" class="input" placeholder="账号">
42+
<input name="pswd "type="password" class="input" placeholder="密码">
43+
<label class="checkbox">
44+
<input type="checkbox"> 记住密码
45+
</label>
46+
<button type="submit" class="btn">登录进站</button>
47+
</form>
48+
</div>
49+
</body>
50+
</html>

0 commit comments

Comments
 (0)