增加违禁词表
This commit is contained in:
11
back/main.py
11
back/main.py
@@ -65,6 +65,11 @@ class Comment(db.Model):
|
||||
downvotes = db.Column(db.Integer, default=0)
|
||||
parent_comment_id = db.Column(db.Integer, db.ForeignKey('comments.id'), nullable=True)
|
||||
|
||||
class DenyWord(db.Model):
|
||||
__tablename__ = 'deny_words'
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
word = db.Column(db.String(255), unique=True, nullable=False)
|
||||
|
||||
# 初始化数据库函数
|
||||
def init_db():
|
||||
if not os.path.exists('./data'):
|
||||
@@ -180,6 +185,12 @@ def submit_post():
|
||||
|
||||
identity_token = data.get('identity')
|
||||
|
||||
# 违禁词检测
|
||||
deny_words = DenyWord.query.all()
|
||||
for dw in deny_words:
|
||||
if dw.word in content:
|
||||
return jsonify({"code": 2005, "data": "提交内容包含违禁词"})
|
||||
|
||||
# Identity 验证
|
||||
if identity_token:
|
||||
if not Identity.query.filter_by(token=identity_token).first():
|
||||
|
||||
Reference in New Issue
Block a user