web前端 | 博客(十三)评论功能

评论功能

  1. 创建评论集合
  2. 判断用户是否登录,如果用户登录,再允许用户提交评论表单
  3. 在服务器端创建文章评论功能对应的路由
  4. 再路由请求处理函数中接受客户端传递过来的评论信息
  5. 将评论信息存储在评论集合中
  6. 将页面重定向回文章详情页面
  7. 在文章详情页面路由中获取文章评论信息并展示在页面中

在model下新建comment.js

const mongoose = require('mongoose');

const commentSchema = new mongoose.Schema({
   
  //文章id
  aid: {
   
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Article',
  },
  //用户id
  uid: {
   
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
  },
  //评论时间
  publishDate: {
   
    type: Date,
    default: Date.now,  //当前时间
  },
  content: {
   
    type: String
  }
});

//3.  使用规则创建文章集合
const Comment = mongoose.model('Comment', commentSchema);

//4. 将集合规则作为模块成员导出
module.exports = {
   
  Comment
}

判断登录角色

在login.js中判断登录角色

            if(user.role == 'admin') {
   
              //重定向到用户列表页面
              res.redirect('/admin/user');
            } else {
   
              //重定向到用户列表页面
              res.redirect
  • 4
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值