Browse Source

Add option for uploading anonymously

Migration (SQLite):
`ALTER TABLE problem ADD COLUMN is_anonymous BOOLEAN;`
master
Pisces000221 8 years ago
parent
commit
9d29998578
  1. 2
      models/problem.js
  2. 1
      modules/problem.js
  3. 14
      views/problem.ejs
  4. 5
      views/problem_edit.ejs

2
models/problem.js

@ -171,6 +171,7 @@ let model = db.define('problem', {
key: 'id' key: 'id'
} }
}, },
is_anonymous: { type: Sequelize.BOOLEAN },
description: { type: Sequelize.TEXT }, description: { type: Sequelize.TEXT },
input_format: { type: Sequelize.TEXT }, input_format: { type: Sequelize.TEXT },
@ -216,6 +217,7 @@ class Problem extends Model {
title: '', title: '',
user_id: '', user_id: '',
publicizer_id: '', publicizer_id: '',
is_anonymous: false,
description: '', description: '',
input_format: '', input_format: '',

1
modules/problem.js

@ -315,6 +315,7 @@ app.post('/problem/:id/edit', async (req, res) => {
problem.output_format = req.body.output_format; problem.output_format = req.body.output_format;
problem.example = req.body.example; problem.example = req.body.example;
problem.limit_and_hint = req.body.limit_and_hint; 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 // Save the problem first, to have the `id` allocated
await problem.save(); await problem.save();

14
views/problem.ejs

@ -85,26 +85,28 @@ if (contest) {
<% } %> <% } %>
</div> </div>
<div class="ui large labels" style="float: right; vertical-align: middle"> <div class="ui large labels" style="float: right; vertical-align: middle">
<div class="ui basic image label" style="font-size: 1.1em; margin-right: 0;"> <div class="ui basic image label" style="font-size: 1.1em; margin-right: 0.3em;">
<% if (problem.is_anonymous) { %>
<img src="<%= syzoj.utils.gravatar('', 64) %>">
<a>匿名用户</a>
<% } else { %>
<img src="<%= syzoj.utils.gravatar(problem.user.email, 64) %>"> <img src="<%= syzoj.utils.gravatar(problem.user.email, 64) %>">
<a href="<%= syzoj.utils.makeUrl(['user', problem.user_id]) %>"><%= problem.user.username %></a> <a href="<%= syzoj.utils.makeUrl(['user', problem.user_id]) %>"><%= problem.user.username %></a>
<% } %>
<div class="detail">上传</div> <div class="detail">上传</div>
</div> </div>
<% if (problem.is_public) { %> <% if (problem.is_public) { %>
<div class="ui basic image label" style="font-size: 1.1em; margin-right: <% if (problem.allowedEdit || problem.allowedManage) { %>0.3em<% } else { %>0<% } %>;">
<% if (problem.publicizer) { %> <% if (problem.publicizer) { %>
<div class="ui basic image label" style="font-size: 1.1em; margin-left: 0.3em; margin-right: 0;">
<img src="<%= syzoj.utils.gravatar(problem.publicizer.email, 64) %>"> <img src="<%= syzoj.utils.gravatar(problem.publicizer.email, 64) %>">
<a href="<%= syzoj.utils.makeUrl(['user', problem.publicizer_id]) %>"><%= problem.publicizer.username %></a> <a href="<%= syzoj.utils.makeUrl(['user', problem.publicizer_id]) %>"><%= problem.publicizer.username %></a>
<div class="detail">公开</div>
</div>
<% } else { %> <% } else { %>
<div class="ui basic image label" style="font-size: 1.1em; margin-left: 0.3em; margin-right: 0;">
<img src="<%= syzoj.utils.gravatar('', 64) %>"> <img src="<%= syzoj.utils.gravatar('', 64) %>">
<a>LibreOJ 管理员</a> <a>LibreOJ 管理员</a>
<% } %>
<div class="detail">公开</div> <div class="detail">公开</div>
</div> </div>
<% } %> <% } %>
<% } %>
</div> </div>
<% } %> <% } %>
</div> </div>

5
views/problem_edit.ejs

@ -43,6 +43,11 @@
<option value="<%= tag.id %>" selected><%= tag.name %></option> <option value="<%= tag.id %>" selected><%= tag.name %></option>
<% } %> <% } %>
</select> </select>
<div class="ui <% if (problem.is_anonymous) { %>checked <% } %>checkbox" style="margin-top: 15px; ">
<input <% if (problem.is_anonymous) { %>checked=""<% } %> name="is_anonymous" type="checkbox">
<label><strong>匿名上传</strong></label>
<p style="margin-top: 5px; ">选择后,上传者的用户名将不在题目页面中显示。</p>
</div>
</div> </div>
</div> </div>
<div class="ui bottom attached tab segment" data-tab="preview" id="preview"> <div class="ui bottom attached tab segment" data-tab="preview" id="preview">

Loading…
Cancel
Save