Browse Source

排名显示昵称

pull/6/head
richie 5 years ago
parent
commit
0ca735cc07
  1. 16
      modules/api.js
  2. 2
      modules/user.js
  3. 3
      utility.js
  4. 4
      views/index.ejs
  5. 2
      views/ranklist.ejs
  6. 32
      views/sign_up.ejs
  7. 6
      views/user.ejs
  8. 110
      views/user_edit.ejs

16
modules/api.js

@ -72,6 +72,14 @@ app.post('/api/sign_up', async (req, res) => {
user = await User.findOne({ where: { email: req.body.email } });
if (user) throw 2009;
if (!req.body.nickname) {
res.send({
error_code: 2300,
message : "昵称不能为空"
});
return;
}
// Because the salt is "syzoj2_xxx" and the "syzoj2_xxx" 's md5 is"59cb..."
// the empty password 's md5 will equal "59cb.."
@ -79,6 +87,13 @@ app.post('/api/sign_up', async (req, res) => {
if (req.body.password === syzoj2_xxx_md5) throw 2007;
if (!(req.body.email = req.body.email.trim())) throw 2006;
if (!syzoj.utils.isValidUsername(req.body.username)) throw 2002;
if (!syzoj.utils.isValidEmail(req.body.email)) {
res.send({
error_code: 2300,
message : "邮箱需要以" + syzoj.config.email_suffix + "结尾"
});
return;
}
if (syzoj.config.register_mail) {
let sendObj = {
@ -110,6 +125,7 @@ app.post('/api/sign_up', async (req, res) => {
user = await User.create({
username: req.body.username,
password: req.body.password,
nickname:req.body.nickname,
email: req.body.email,
is_show: syzoj.config.default.user.show,
rating: syzoj.config.default.user.rating,

2
modules/user.js

@ -175,6 +175,8 @@ app.post('/user/:id/edit', async (req, res) => {
user.username = req.body.username;
user.email = req.body.email;
}
if (!req.body.nickname) throw new ErrorMessage('昵称不能为空。');
user.nickname = req.body.nickname;
if (res.locals.user && res.locals.user.is_admin) {
if (!req.body.privileges) {

3
utility.js

@ -270,6 +270,9 @@ module.exports = {
isValidUsername(s) {
return RegExp(syzoj.config.username_regex).test(s);
},
isValidEmail(s) {
return s.endsWith(syzoj.config.email_suffix || "");
},
locks: [],
lock(key, cb) {
let s = JSON.stringify(key);

4
views/index.ejs

@ -28,7 +28,7 @@
<thead>
<tr>
<th style="width: 50px; ">#</th>
<th style="width: 170px; ">用户</th>
<th style="width: 170px; ">用户</th>
<th style="width: 170px; ">积分</th>
<th>个性签名</th>
</tr>
@ -53,7 +53,7 @@
%>
<tr>
<td><b><%= i %></b></td>
<td><a href="<%= syzoj.utils.makeUrl(['user', user.id]) %>"><%= user.username %></a><% if (user.nameplate) { %><%- user.nameplate %><% } %></td>
<td><a href="<%= syzoj.utils.makeUrl(['user', user.id]) %>"><%= user.nickname %></a><% if (user.nameplate) { %><%- user.nameplate %><% } %></td>
<td><%= user.rating %></td>
<td style="font-content">
<script id="user-infomation-script-<%= i %>">

2
views/ranklist.ejs

@ -42,7 +42,7 @@
<td><a href="<%= syzoj.utils.makeUrl(['user', user.id]) %>"><%= user.username %></a><% if (user.nameplate) { %><%- user.nameplate %><% } %></td>
<td><%= user.ac_num %></td>
<td><%= user.submit_num %></td>
<td><%= user.submit_num == 0 ? 0 : Math.round(user.ac_num / user.submit_num * 10000) / 100.00 + "%" %></td>
<td><%= user.ac_num && user.submit_num ? Math.round(user.ac_num / user.submit_num * 10000) / 100.00 + "%" : 0%></td>
<td><%= user.rating %></td>
</tr>
<% } %>

32
views/sign_up.ejs

@ -10,6 +10,10 @@
<label for="username">用户名</label>
<input type="text" placeholder="" id="username">
</div>
<div class="field">
<label for="nickname">昵称</label>
<input type="text" placeholder="" id="nickname">
</div>
<div class="field">
<label for="email">邮箱</label>
<input type="email" placeholder="" id="email">
@ -29,25 +33,25 @@
</div>
<script src="<%- lib('blueimp-md5/2.10.0/js/md5.min.js') %>"></script>
<script type="text/javascript">
function show_error(error) {
function show_error(error) {
$("#error_info").text(error);
$("#error").show();
}
}
function success() {
function success() {
alert("注册成功!");
window.location.href = location.protocol + '//' + location.host + <%- serializejs(req.query.url || '/') %>;
}
}
function mail_required() {
function mail_required() {
alert("注册确认邮件已经发送到您的邮箱的垃圾箱,点击邮件内的链接即可完成注册。");
var s = $("#email").val();
var mailWebsite = 'https://mail.' + s.substring(s.indexOf('@') + 1, s.length);
if (mailWebsite === 'https://mail.gmail.com') mailWebsite = 'https://mail.google.com';
window.location.href = mailWebsite;
}
}
function submit() {
function submit() {
if ($("#password1").val() != $("#password2").val()) {
show_error("两次输入的密码不一致");
return;
@ -60,19 +64,20 @@ function submit() {
async: true,
data: {
username: $("#username").val(),
nickname: $("#nickname").val(),
password: password,
email: $("#email").val(),
prevUrl: <%- serializejs(req.query.url || '/') %>
},
success: function(data) {
success: function (data) {
error_code = data.error_code;
switch(error_code){
switch (error_code) {
case 2001:
show_error("服务器未收到数据");
break;
case 2005:
case 2002:
show_error("用户名需要大于 3 个字符小于 16 个字符,仅允许字母数字和下划线");
show_error("用户名仅允许字母数字和下划线和点");
break;
case 2007:
case 2003:
@ -91,6 +96,9 @@ function submit() {
case 2010:
show_error("验证邮件发送失败:\n" + data.message);
break;
case 2300:
show_error(data.message);
break;
case 1:
success();
break;
@ -103,12 +111,12 @@ function submit() {
}
$("#sign_up").removeClass("loading");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.responseText);
show_error("未知错误");
$("#sign_up").removeClass("loading");
}
});
}
}
</script>
<% include footer %>

6
views/user.ejs

@ -50,6 +50,12 @@
<div class="ui bottom attached segment"><%= show_user.username %><% if (show_user.nameplate) { %><%- show_user.nameplate %><% } %></div>
</div>
</div>
<div class="row">
<div class="column">
<h4 class="ui top attached block header">昵称</h4>
<div class="ui bottom attached segment"><%= show_user.nickname %></div>
</div>
</div>
<% if (show_user.emailVisible) { %>
<div class="row">
<div class="column">

110
views/user_edit.ejs

@ -2,42 +2,58 @@
<% include header %>
<% include monaco-editor %>
<div class="padding">
<div class="ui <% if (error_info === '') { %>success<% } else { %>error<% } %> message" id="error" <% if (error_info === null) { %>hidden<% } %>>
<div class="ui <% if (error_info === '') { %>success<% } else { %>error<% } %> message" id="error"
<% if (error_info === null) { %>hidden
<% } %>
>
<% if (error_info !== null) {
if (error_info === '') error_info = '修改成功。';
%>
<p id="error_info"><%= error_info %></p>
<% } %>
</div>
<form id="form" action="<%= syzoj.utils.makeUrl(['user', edited_user.id, 'edit']) %>" method="post" onsubmit="return check()">
<form id="form" action="<%= syzoj.utils.makeUrl(['user', edited_user.id, 'edit']) %>" method="post"
onsubmit="return check()">
<div class="ui form">
<div class="field">
<label for="username">用户名</label>
<input type="text" id="username" name="username" value="<%= edited_user.username %>"<% if (!user.allowedManage) { %> readonly<% } %>>
<input type="text" id="username" name="username" value="<%= edited_user.username %>"
<% if (!user.allowedManage) { %> readonly
<% } %>
>
</div>
<div class="field">
<label for="sex">性别</label>
<select class="ui dropdown" name="sex">
<option value="0" <%= edited_user.sex == 0 ? 'selected': '' %>>其它</option>
<option value="1" <%= edited_user.sex == 1 ? 'selected': '' %>>男</option>
<option value="-1" <%= edited_user.sex == -1 ? 'selected': '' %>>女</option>
<option value="0" <%= edited_user.sex == 0 ? 'selected' : '' %>>其它</option>
<option value="1" <%= edited_user.sex == 1 ? 'selected' : '' %>>男</option>
<option value="-1" <%= edited_user.sex == -1 ? 'selected' : '' %>>女</option>
</select>
</div>
<div class="field">
<label for="email">Email</label>
<input class="font-content" type="email" id="email" name="email" value="<%= edited_user.email %>"<% if (!user.allowedManage) { %> readonly<% } %>>
<input class="font-content" type="email" id="email" name="email" value="<%= edited_user.email %>"
<% if (!user.allowedManage) { %> readonly
<% } %>
>
</div>
<div class="inline field">
<label class="ui header">公开 Email</label>
<div class="ui toggle checkbox">
<input id="public_email" name="public_email" type="checkbox" <% if (edited_user.public_email) { %> checked<% } %>>
<input id="public_email" name="public_email" type="checkbox"
<% if (edited_user.public_email) { %> checked
<% } %>
>
<label> </label>
</div>
</div>
<div class="inline field">
<label class="ui header">默认显示格式化后的代码(如果可用)</label>
<div class="ui toggle checkbox">
<input id="prefer_formatted_code" name="prefer_formatted_code" type="checkbox" <% if (edited_user.prefer_formatted_code) { %> checked<% } %>>
<input id="prefer_formatted_code" name="prefer_formatted_code" type="checkbox"
<% if (edited_user.prefer_formatted_code) { %> checked
<% } %>
>
<label> </label>
</div>
</div>
@ -52,6 +68,11 @@
<input type="hidden" name="information">
<div class="ui form">
<div class="field">
<label class="ui header">昵称</label>
<input type="text" placeholder="昵称" name="nickname" value="<%= edited_user.nickname %>" id="nickname">
</div>
<div class="field">
<label class="ui header">密码</label>
<input type="password" placeholder="原密码(留空则不修改)" name="old_password" id="old_password">
@ -70,44 +91,62 @@
<div class="inline field">
<label class="ui header">权限</label>
<div class="ui toggle disabled checkbox" style="margin-right: 20px; ">
<input disabled="disabled" type="checkbox" <% if (edited_user.is_admin) { %> checked<% } %>>
<input disabled="disabled" type="checkbox"
<% if (edited_user.is_admin) { %> checked
<% } %>
>
<label>全站管理员</label>
</div>
<div class="ui toggle <% if (!allowedManagePrivilege) { %>disabled <% } %>checkbox checkbox_privilege" data-name="manage_problem" style="margin-right: 20px; ">
<input <% if (!allowedManagePrivilege) { %>disabled="disabled" <% } %>type="checkbox"<% if (edited_user.privileges.includes('manage_problem')) { %> checked<% } %>>
<div class="ui toggle <% if (!allowedManagePrivilege) { %>disabled <% } %>checkbox checkbox_privilege"
data-name="manage_problem" style="margin-right: 20px; ">
<input <% if (!allowedManagePrivilege) { %>disabled="disabled" <% } %>type="checkbox"
<% if (edited_user.privileges.includes('manage_problem')) { %> checked
<% } %>
>
<label>管理题目</label>
</div>
<div class="ui toggle <% if (!allowedManagePrivilege) { %>disabled <% } %>checkbox checkbox_privilege" data-name="manage_problem_tag" style="margin-right: 20px; ">
<input <% if (!allowedManagePrivilege) { %>disabled="disabled" <% } %>type="checkbox"<% if (edited_user.privileges.includes('manage_problem_tag')) { %> checked<% } %>>
<div class="ui toggle <% if (!allowedManagePrivilege) { %>disabled <% } %>checkbox checkbox_privilege"
data-name="manage_problem_tag" style="margin-right: 20px; ">
<input <% if (!allowedManagePrivilege) { %>disabled="disabled" <% } %>type="checkbox"
<% if (edited_user.privileges.includes('manage_problem_tag')) { %> checked
<% } %>
>
<label>管理题目标签</label>
</div>
<div class="ui toggle <% if (!allowedManagePrivilege) { %>disabled <% } %>checkbox checkbox_privilege" data-name="manage_user">
<input <% if (!allowedManagePrivilege) { %>disabled="disabled" <% } %>type="checkbox"<% if (edited_user.privileges.includes('manage_user')) { %> checked<% } %>>
<div class="ui toggle <% if (!allowedManagePrivilege) { %>disabled <% } %>checkbox checkbox_privilege"
data-name="manage_user">
<input <% if (!allowedManagePrivilege) { %>disabled="disabled" <% } %>type="checkbox"
<% if (edited_user.privileges.includes('manage_user')) { %> checked
<% } %>
>
<label>管理用户</label>
</div>
</div>
<div style="text-align: center; margin-top: 30px; ">
<button id="submit_button" type="submit" class="ui disabled blue labeled icon button"><i class="ui icon edit"></i>修改</button>
<a href="<%= syzoj.utils.makeUrl(['user', edited_user.id]) %>" class="ui labeled icon button"><i class="ui icon angle left"></i>返回</a>
<button id="submit_button" type="submit" class="ui disabled blue labeled icon button"><i
class="ui icon edit"></i>修改
</button>
<a href="<%= syzoj.utils.makeUrl(['user', edited_user.id]) %>" class="ui labeled icon button"><i
class="ui icon angle left"></i>返回</a>
</div>
</div>
</form>
</div>
</div>
</div>
<script>
var bakDefine = define;
define = undefined;
var bakDefine = define;
define = undefined;
</script>
<script src="<%- lib('blueimp-md5/2.10.0/js/md5.min.js') %>"></script>
<script>
define = bakDefine;
define = bakDefine;
</script>
<script type="text/javascript">
var editors = {
information: { defaultValue: <%- serializejs(edited_user.information) %> },
};
var editors = {
information: {defaultValue: <%- serializejs(edited_user.information) %> },
};
window.onEditorLoaded(function () {
window.onEditorLoaded(function () {
for (var name in editors) {
var editor = editors[name];
var editorElement = document.getElementById(name);
@ -116,14 +155,15 @@ window.onEditorLoaded(function () {
}
$('#submit_button').removeClass('disabled');
});
});
function make_md5(tag) {
function make_md5(tag) {
if (tag.val()) {
tag.val(md5(tag.val() + "syzoj2_xxx"));
}
}
function check() {
}
function check() {
old_password = $("#old_password");
password1 = $("#password1");
password2 = $("#password2");
@ -139,7 +179,7 @@ function check() {
make_md5(password1);
make_md5(password2);
<% if (allowedManagePrivilege) { %>
<% if (allowedManagePrivilege) { %>
$('.checkbox_privilege').each(function () {
if ($(this).checkbox('is checked')) {
var name = $(this).data('name');
@ -151,14 +191,14 @@ function check() {
document.getElementById('form').appendChild(elem);
}
});
<% } %>
<% } %>
return true;
}
}
</script>
<script>
$(function () {
$(function () {
$('.ui.dropdown:not(.simple)').dropdown();
});
});
</script>
<% include footer %>

Loading…
Cancel
Save