From 9d29998578cad1a4bab76bb2a9d1585a9741a28d Mon Sep 17 00:00:00 2001 From: Pisces000221 <1786762946@qq.com> Date: Sat, 17 Jun 2017 16:46:44 +0800 Subject: [PATCH] Add option for uploading anonymously Migration (SQLite): `ALTER TABLE problem ADD COLUMN is_anonymous BOOLEAN;` --- models/problem.js | 2 ++ modules/problem.js | 1 + views/problem.ejs | 26 ++++++++++++++------------ views/problem_edit.ejs | 5 +++++ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/models/problem.js b/models/problem.js index 731c96f..0678c28 100644 --- a/models/problem.js +++ b/models/problem.js @@ -171,6 +171,7 @@ let model = db.define('problem', { key: 'id' } }, + is_anonymous: { type: Sequelize.BOOLEAN }, description: { type: Sequelize.TEXT }, input_format: { type: Sequelize.TEXT }, @@ -216,6 +217,7 @@ class Problem extends Model { title: '', user_id: '', publicizer_id: '', + is_anonymous: false, description: '', input_format: '', diff --git a/modules/problem.js b/modules/problem.js index 371f443..b823406 100644 --- a/modules/problem.js +++ b/modules/problem.js @@ -315,6 +315,7 @@ app.post('/problem/:id/edit', async (req, res) => { problem.output_format = req.body.output_format; problem.example = req.body.example; problem.limit_and_hint = req.body.limit_and_hint; + problem.is_anonymous = (req.body.is_anonymous === 'on'); // Save the problem first, to have the `id` allocated await problem.save(); diff --git a/views/problem.ejs b/views/problem.ejs index 0c5b669..1da7e1e 100644 --- a/views/problem.ejs +++ b/views/problem.ejs @@ -85,25 +85,27 @@ if (contest) { <% } %>
-
- - <%= problem.user.username %> +
+ <% if (problem.is_anonymous) { %> + + 匿名用户 + <% } else { %> + + <%= problem.user.username %> + <% } %>
上传
<% if (problem.is_public) { %> - <% if (problem.publicizer) { %> -
+
+ <% if (problem.publicizer) { %> <%= problem.publicizer.username %> -
公开
-
- <% } else { %> -
+ <% } else { %> LibreOJ 管理员 -
公开
-
- <% } %> + <% } %> +
公开
+
<% } %>
<% } %> diff --git a/views/problem_edit.ejs b/views/problem_edit.ejs index d0b3b19..80bd457 100644 --- a/views/problem_edit.ejs +++ b/views/problem_edit.ejs @@ -43,6 +43,11 @@ <% } %> +
+ checked=""<% } %> name="is_anonymous" type="checkbox"> + +

选择后,上传者的用户名将不在题目页面中显示。

+