Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: dgunzi/newcookbook
base: 19af37dd7b
...
head fork: dgunzi/newcookbook
compare: 8c1eb7cbfb
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 13 files changed
  • 0 commit comments
  • 1 contributor
Commits on Nov 08, 2012
@dgunzi 界面样式修改 eecbcf0
Commits on Nov 23, 2012
@dgunzi 添加用户登录和退出功能 8c1eb7c
View
4 app.js
@@ -21,7 +21,9 @@ app.configure(function(){
app.use(express.session({
secret: config.session_secret
}));
-
+ //检测用户中间件
+ app.use(require('./controllers/user').auth_user);
+
app.set('view engine', 'html');
app.engine('html', ejs.renderFile);
View
1  config/config.js
@@ -12,6 +12,7 @@ exports.config = {
password : "admin",
node_port : process.argv[2] || 3000,
upload_dir : '/public/uploads/',
+ admins : {admin: true}, //超级管理员
tmp_dir : 'tmp',
db : 'mongodb://127.0.0.1:27017/nodeblog'
}
View
88 controllers/user.js
@@ -107,4 +107,90 @@ exports.add_action = function(req, res, next){
});
});
-}
+}
+
+//login
+exports.login = function(req, res, next){
+ var method = req.method.toLowerCase();
+ if(method === 'get'){
+ res.render('login');
+ return;
+ }
+ if(method === 'post'){
+ var user_name = sanitize(req.body.user_name).trim();
+ user_name = sanitize(user_name).xss();
+ var password = sanitize(req.body.password).trim();
+ password = sanitize(password).xss();
+
+ if(!user_name || !password){
+ res.render('login',{error: '信息不完整'});
+ return;
+ }
+ User.findOne({'user_name': user_name},function(err, userRow){
+ if(err){
+ return next(err);
+ }
+ if(!userRow){
+ res.render('login',{error: '没有此用户,或已被删除'});
+ return;
+ }
+ password = md5(password);
+ if(password != userRow.password){
+ res.render('login',{error: '密码错误'});
+ return;
+ }
+
+ //设置cookie
+ gen_session(userRow, res, req);
+
+ res.redirect('/');
+
+ })
+ }
+}
+
+//logout
+exports.logout = function(req, res, next){
+ req.session.destroy();
+ res.clearCookie(config.auth_cookie_name, {path: '/'});
+ res.redirect('/');
+}
+
+//检测用户中间件
+exports.auth_user = function(req,res,next){
+ if(req.session.user){
+ //如果存在session,直接调用b
+ if(config.admins[req.session.user.user_name]){
+ req.session.user.is_admin = true;
+ }else{
+ req.session.user.is_admin = false;
+ }
+ res.locals.current_user = req.session.user;
+ return next();
+ }else{
+ //如果不存在session,从cookie中调用并设置session
+ var cookie = req.cookies[config.auth_cookie_name];
+ if(!cookie) return next();
+
+ var auth_token = decrypt(cookie, config.session_secret);
+ var auth = auth_token.split('\t');
+ var user_id = auth[0];
+ User.findOne({_id:user_id},function(err,user){
+ if(err) return next(err);
+ if(user){
+ if(config.admins[user.user_name]){
+ user.is_admin = true;
+ }else{
+ user.is_admin = false;
+  }
+ req.session.user = user;
+ req.session.cookie.maxAge = 1000 * 60 * 60;
+ res.locals.current_user = req.session.user;
+ return next();
+ }else{
+ return next();
+ }
+ });
+ }
+};
+
View
4 public/css/bootstrap.css
@@ -165,7 +165,7 @@ a:hover {
.container,
.navbar-fixed-top .container,
.navbar-fixed-bottom .container {
- width: 940px;
+ width: 960px;
}
.span12 {
width: 940px;
@@ -180,7 +180,7 @@ a:hover {
width: 700px;
}
.span8 {
- width: 620px;
+ width: 640px;
}
.span7 {
width: 540px;
View
26 public/css/custom.css
@@ -134,10 +134,15 @@ img { max-width: 100%;}
.cookbookitem .finalPic{
text-align: center;
}
-
+.cookbookDetail .minfo{
+ margin-left:15px;
+}
.cookbookitem .info i{
margin-right:3px;
}
+.cookbookDetail .detailTitle h3 i{
+ margin:3px 3px 0 0;
+}
.side_bar .thumbnail{
margin-top: 15px;
}
@@ -158,3 +163,22 @@ img { max-width: 100%;}
.side_bar .login p{
padding:5px 0;
}
+.pull-left{
+ float:left;
+}
+#user_login{
+ height:50px;padding-left:15px;
+}
+#user_login ul{
+ text-align: left;margin-left: 10px;
+}
+#user_login ul li b{
+ background: #C8CFE0;
+ padding: 0 5px;
+ margin-left: 5px;
+ color: #fff;
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ border-radius: 3px;
+}
+#footer{text-align:center;}
View
3  routes.js
@@ -39,6 +39,9 @@ module.exports = function (app) {
app.get('/user_add', user.add_html);
app.post('/useradd', user.add_action);
+ app.get('/login', user.login);
+ app.post('/login', user.login);
+ app.get('/logout', user.logout);
//view
app.get('/:post', cookbook.cookbook_view);
View
2  views/common/footer.html
@@ -1,4 +1,4 @@
- <footer>
+ <footer id="footer">
<p><%=site.copyright%></p>
</footer>
</div>
View
23 views/common/header.html
@@ -21,17 +21,20 @@
<div class="nav-collapse">
<ul class="nav">
<li><a href="/">首页</a></li>
- <li><a href="#contact">联系</a></li>
+ <% if(locals.current_user){ %>
+ <li><a href="/cookbook">菜谱管理</a></li>
+ <li><a href="/logout">账户设置</a></li>
<li><a href="/write">发布菜谱</a></li>
- <li class="dropdown">
- <a href="#" class="dropdown-toggle" data-toggle="dropdown">网站管理 <b class="caret"></b></a>
- <ul class="dropdown-menu">
- <li><a href="/cookbook">菜谱管理</a></li>
- <li><a href="/user">新菜谱</a></li>
- <li><a href="/logout">个人账户</a></li>
- </ul>
- <li><a href="#about">关于</a></li>
- </li>
+ <li><a href="/logout">退出登录</a></li>
+ <%
+ }else{
+ %>
+ <li><a href="/login">登录</a></li>
+ <%
+ }
+ %>
+ <li><a href="/about">关于</a></li>
+
</ul>
<form class="navbar-search pull-left" action="">
<input type="text" class="search-query span2" style="height:25px;line-height:25px" placeholder="搜索">
View
54 views/cookbookview.html
@@ -1,32 +1,50 @@
<%- include common/header.html -%>
- <div class="container-fluid">
+ <div class="mainContainer">
<div class="row-fluid">
<div class="span8">
<% var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
-
+ var levelClass = ["","label-success","label-warning","label-important","label-info","label-inverse"];
var d = cookbook.datetime;
var datetime = monthNames[d.getMonth()] + " " + d.getDay() + ", " + d.getFullYear();
+ var levelIndex = cookbook.level-1;
%>
- <section class="cookbookitem">
+ <section class="cookbookitem thumbnail">
<div class="page-header">
<h2><%=cookbook.title %></h2>
- <div class="row-fluid">
- <div class="span9">
- <%= cookbook.user %>
- </div>
- <div class="span3">
- <span style="margin-left: 35px;"><small><%=datetime%></small></span>
- </div>
+ <div class="info">
+ <span><i class="icon-user"></i>作者:<%= cookbook.user %></span>
+ <span style="margin-left: 35px;"><i class="icon-calendar"></i>发表于:<small><%=datetime%></small></span>
+ <span class="label <%=levelClass[levelIndex]%> fr"><%=cookconfig.level[levelIndex]%></span>
</div>
</div>
-
- <div class="steps">
+ <div class="steps cookbookDetail">
+ <div class="detailTitle"><h3><i class="icon-home"></i>主料:</h3></div>
+ <p class="minfo"><%- cookbook.major %></p>
+ <%
+ if(cookbook.minor!=""){
+ %>
+ <div class="detailTitle"><h3><i class="icon-tags"></i>配料:</h3></div>
+ <p class="minfo"><%- cookbook.minor %></p>
+ <%
+ }
+ %>
+ <div class="detailTitle"><h3><i class="icon-leaf"></i>调料:</h3></div>
+ <p class="minfo"><%- cookbook.seasoning %></p>
+ <div class="detailTitle"><h3><i class="icon-list"></i>做法:</h3></div>
<%- cookbook.steps %>
</div>
</section>
</div>
- <div class="span4">
- <section>
+ <div class="span4 side_bar">
+ <section class="login thumbnail">
+ <h3>Homely Dishes,欢迎您!</h3>
+ <a href="/user_add" class="btn btn-info">注册</a>
+ <p>
+ 已注册用户请
+ <a href="/login">登录</a>
+ </p>
+ </section>
+ <section class="thumbnail">
<div class="page-header">
<h2>大家在看</h2>
</div>
@@ -41,7 +59,7 @@
<li><a>魔芋烧鸭</a></li>
</ol>
</section>
- <section>
+ <section class="thumbnail">
<div class="page-header">
<h2>随机菜谱</h2>
</div>
@@ -56,7 +74,7 @@
<li><a>以服务人民为荣,以背离人民为耻吗?</a></li>
</ol>
</section>
- <section>
+ <section class="thumbnail">
<div class="page-header">
<h2>今日推荐</h2>
</div>
@@ -68,7 +86,7 @@
</ul>
<div class="tab-content">
<div class="tab-pane active" id="1">
- <div class="thumbnail">
+ <div>
<img src="/img/thumb/huangdouyumifagao.png" alt="">
<div class="caption">
<h3>黄豆玉米面发糕</h3>
@@ -80,7 +98,7 @@
</div>
</div>
<div class="tab-pane" id="2">
- <div class="thumbnail">
+ <div>
<img src="/img/thumb/jiamaji.png" alt="">
<div class="caption">
<h3>椒麻鸡</h3>
View
4 views/cookbookwrite.html
@@ -38,8 +38,8 @@
<div class="span3">
<ul class="nav nav-pills nav-stacked">
<li><a href="/cookbook">菜谱管理</a></li>
- <li class="active"><a href="/write">新菜谱</a></li>
- <li><a href="#">个人账户</a></li>
+ <li class="active"><a href="/write">发布菜谱</a></li>
+ <li><a href="#">账户设置</a></li>
</ul>
</div>
<div class="span9">
View
27 views/index.html
@@ -1,5 +1,5 @@
<%- include common/header.html -%>
- <div class="container-fluid">
+ <div class="mainContainer">
<div class="subnav">
<ul class="nav nav-pills">
<li><a href="/">全部</a></li>
@@ -47,7 +47,7 @@
if(pages == current_page) nextPage = pages;
if(current_page == 1) prePage = 1;
%>
- <div class="finalPic"><%- lastPic %></div>
+ <div class="finalPic" ><a href="/<%=cookbooks[item].url%>" target="_blank"><%- lastPic %></a></div>
<%- steps %>
</div>
<div class="row">
@@ -67,6 +67,26 @@
</ul>
</div>
<div class="span4 side_bar">
+ <%
+ if(locals.current_user){
+ %>
+ <section class="login thumbnail" id="user_login">
+ <div class="pull-left user_icon">
+ <a href="/user_view/<%= current_user.user_name %>" class="btn btn-info">
+ <i class="icon-user icon-white"></i>
+ <span><%= current_user.user_name%></span>
+ </a>
+ </div>
+ <ul class="pull-left unstyled">
+ <li>
+ 发表的菜谱:<b>12</b>
+ </li>
+ <li>
+ 发表的回复:<b>79</b>
+ </li>
+ </ul>
+ </section>
+ <% }else{ %>
<section class="login thumbnail">
<h3>Homely Dishes,欢迎您!</h3>
<a href="/user_add" class="btn btn-info">注册</a>
@@ -75,6 +95,9 @@
<a href="/login">登录</a>
</p>
</section>
+ <%
+ }
+ %>
<section class="thumbnail">
<div class="page-header">
<h2>大家在看</h2>
View
84 views/login.html
@@ -0,0 +1,84 @@
+<%- include common/header.html -%>
+<div class="mainContainer">
+ <style type="text/css">
+ .loginBox{
+ width:360px;height:330px;
+ padding:15px 15px 0 25px;
+ border:1px solid #CCC;
+ color:#000;
+ margin-top:40px;
+ border-radius:8px;
+ background: white; font:11px/1.5em 'Microsoft YaHei' ;
+ position: absolute;
+ left:50%;top:50%;
+ margin-left:-210px;
+ margin-top:-205px;
+ -moz-box-shadow:2px 2px 10px #ccc;
+ -webkit-box-shadow:2px 2px 10px #ccc;
+ box-shadow:2px 2px 10px #ccc;
+ }
+ .loginBox h2{height:45px;font-size:24px;font-weight:600;}
+ .loginhelp{text-align:center;padding-top:15px;}
+ .loginhelp span{display:block;}
+ #loginboxPanel .input-prepend{
+ margin-bottom:15px;
+ }
+ #loginboxPanel .input-prepend .add-on,#loginboxPanel .input-append .add-on{padding:10px 12px;}
+ #loginboxPanel .btns{
+ border-bottom:1px solid #ccc;padding-bottom:25px;
+ }
+ #loginboxPanel .btns .span1{
+ margin-left:30px;
+ }
+ #loginboxPanel .btns .span8{
+ margin-top:12px;
+ }
+ #loginboxPanel .btns .span8 span{
+ padding-left:5px;
+ }
+ #loginboxPanel .tip{
+ margin-bottom:25px;font-size:14px;
+ }
+ #loginboxPanel input.span3{
+ font-size:14px;
+ font-weight:600;
+ width:300px;
+ }
+ #footer{text-align:center;z-index:999; position:fixed; bottom:0; left:0; width:100%; height:80px; line-height:40px;/* for ie6 */ _position:absolute; _top: expression(documentelement.scrolltop + documentelement.clientheight-this.offsetheight);overflow:visible; }
+ </style>
+ <%if(locals.error){%>
+ <div class="alert alert-error">
+ <a class="close" data-dismiss="alert" href="#">x</a>
+ <%= error %>
+ </div>
+ <%}%>
+ <section class="loginBox">
+ <form id="loginform" name="loginform" method="post">
+ <section id="loginboxPanel">
+ <h2>登 录</h2>
+ <div class="tip">请使用已注册账户登录:</div>
+ <div class="input-prepend">
+ <span class="add-on"><i class="icon-user"></i></span><input class="span3" type="text" name="user_name" placeholder="用户名" style="margin:0;padding:19px;">
+ </div>
+ <div class="input-prepend">
+ <span class="add-on"><i class="icon-lock"></i></span><input class="span3" type="password" name="password" placeholder="&nbsp;&nbsp;&nbsp;" style="margin:0;padding:19px;">
+ </div>
+ <section class="row-fluid btns">
+ <section class="span8 lh30"><input type="checkbox" name="rememberme" /><span>下次自动登录</span></section>
+ <section class="span1"><input type="submit" value=" 登 录 " class="btn btn-success btn-large"></section>
+ </section>
+ <section class="loginhelp">
+ <span>您还没有账户吗?<a href="/user_add">去注册一个</a></span>
+ <span><a>忘记密码?</a>| <a href="/">回到主页</a></span>
+ </section>
+ </section>
+ </form>
+ </section>
+ </div>
+ <footer id="footer">
+ <hr/>
+ <p><%=site.copyright%></p>
+ </footer>
+ </div>
+</body>
+</html>
View
4 views/user_add.html
@@ -7,7 +7,7 @@
text-align: right;
}
</style>
-<div class="container-fluid">
+<div class="mainContainer">
<div class="row-fluid">
<div class="span8">
<%if(locals.error){%>
@@ -54,7 +54,7 @@ <h2 class="pull-left"><i class="icon-user"></i>注册</h2>
</div>
</form>
</div>
- <div class="span4">
+ <div class="span4 side_bar">
sdfsdf
</div>
</div>

No commit comments for this range

Something went wrong with that request. Please try again.