Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wunci committed Jul 17, 2017
1 parent 0e90153 commit 6bb2a71
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 53 deletions.
1 change: 0 additions & 1 deletion config/default.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const config = {
// 启动端口
port: 3000,

// 数据库配置
database: {
DATABASE: 'nodesql',
Expand Down
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ app.use(views(path.join(__dirname, './views'), {

app.use(bodyParser())


// 路由
app.use(require('./routers/signin.js').routes())
app.use(require('./routers/signup.js').routes())
app.use(require('./routers/posts.js').routes())
app.use(require('./routers/signout.js').routes())


app.listen(3000)

console.log(`listening on port ${config.port}`)
if (module.parent) {
module.exports = app;
}else{
app.listen(3000)
console.log(`listening on port ${config.port}`)

}
2 changes: 1 addition & 1 deletion lib/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ let deleteAllPostComment = function(id){
let _sql=`delete from comment where postid = ${id}`
return query(_sql)
}
// 查找
// 查找评论数
let findCommentLength = function(id){
let _sql=`select content from comment where postid in (select id from posts where id=${id})`
return query(_sql)
Expand Down
6 changes: 2 additions & 4 deletions middlewares/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
module.exports ={

checkNotLogin:function (ctx) {
if (ctx.session && ctx.session.user) {

if (ctx.session && ctx.session.user) {
ctx.redirect('/posts');
return false;
}
return true;
},

checkLogin:function (ctx) {
if (!ctx.session || !ctx.session.user) {

if (!ctx.session || !ctx.session.user) {
ctx.redirect('/signin');
return false;
}
Expand Down
6 changes: 1 addition & 5 deletions views/edit.ejs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<% include header %>
<div class="container">

<form class="form create" method="post">
<div>
<label>标题:</label>
Expand All @@ -12,7 +11,6 @@
<%= posts[0]['content'] %>
</textarea>
</div>
<!-- <input type="submit" value="修改"> -->
<div class="submit">修改</div>
</form>
</div>
Expand All @@ -32,14 +30,12 @@
window.location.href="/posts"
},1000)
}
},
error: function () {
alert('异常');
}
})
})
})
</script>
<% include footer %>
1 change: 0 additions & 1 deletion views/footer.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

</body>
</html>
2 changes: 0 additions & 2 deletions views/header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
<% } %>
</div>
</header>


<script>
function fade(data){
if ($(data).css('display')!=='none') {
Expand Down
5 changes: 1 addition & 4 deletions views/posts.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<% include header %>

<ul class="posts">

<% posts.forEach(function(res){ %>
<li>
<div class="post_3">
Expand All @@ -23,7 +21,6 @@
<!-- <p>userid:<%= res['uid'] %></p> -->
<p class="post_time">发表时间:<%= res['moment'] %></p>
</li>
<% }) %>

<% }) %>
</ul>
<% include footer %>
3 changes: 0 additions & 3 deletions views/sPost.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,13 @@
</script>
<% }) %>
</div>

<% if(session.user){ %>
<form class="form" method="post" action="/<%= posts[0]['id'] %>">
<textarea name="content" id=""></textarea>
<div class="submit">发表留言</div>
</form>
<% } %>

</div>

<script>
$('.submit').click(function(){
$.ajax({
Expand Down
16 changes: 4 additions & 12 deletions views/signin.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
<input placeholder="密码" type="password" name="password">
</div>
<div class="submit">登录</div>
</form>

</form>
</div>
<script>
$('.submit').click(()=>{
console.log($('.form').serialize())
$.ajax({
url: "/signin",
data: $('.form').serialize(),
Expand All @@ -36,19 +33,14 @@
setTimeout(()=>{
window.location.href="/posts"
},1000)
},1000)
}
//console.log($('.ui.error.message').text);
},
error: function () {
alert('异常');
}
})
})
})
})
</script>
<% include footer %>

Expand Down
20 changes: 5 additions & 15 deletions views/signup.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,36 @@
</div>
<script>
$('.submit').click(()=>{
console.log($('.form').serialize())
$.ajax({
url: "/signup",
data: $('.form').serialize(),
type: "POST",
cache: false,
dataType: 'json',
success: function (msg) {
if (msg.data == 1) {
if (msg.data == 1) {
$('.error').text('用户名存在')
$('input').val('')
fade('.error')
}
else if (msg.data == 2){
$('.error').text('请输入重复的密码')
fade('.error')
fade('.error')
}
else if(msg.data == 3){
$('.success').text('注册成功')
fade('.success')
setTimeout(()=>{
window.location.href="/signin"
window.location.href="/signin"
},1000)
}
//console.log($('.ui.error.message').text);
},
error: function () {
alert('异常');
}
})
})
})
})
</script>
<% include footer %>

0 comments on commit 6bb2a71

Please sign in to comment.