From 0ca735cc073acc6719a5604752a480725082de90 Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 28 Jun 2019 14:03:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E5=90=8D=E6=98=BE=E7=A4=BA=E6=98=B5?= =?UTF-8?q?=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/api.js | 16 +++ modules/user.js | 2 + utility.js | 3 + views/index.ejs | 4 +- views/ranklist.ejs | 2 +- views/sign_up.ejs | 174 ++++++++++++++++---------------- views/user.ejs | 6 ++ views/user_edit.ejs | 234 ++++++++++++++++++++++++++------------------ 8 files changed, 258 insertions(+), 183 deletions(-) diff --git a/modules/api.js b/modules/api.js index 8731053..0ece71e 100644 --- a/modules/api.js +++ b/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, diff --git a/modules/user.js b/modules/user.js index ab559ab..180ec83 100644 --- a/modules/user.js +++ b/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) { diff --git a/utility.js b/utility.js index f8a0903..7f36b4f 100644 --- a/utility.js +++ b/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); diff --git a/views/index.ejs b/views/index.ejs index 397b9c5..ed1cd91 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -28,7 +28,7 @@ # - 用户名 + 用户 积分 个性签名 @@ -53,7 +53,7 @@ %> <%= i %> - <%= user.username %><% if (user.nameplate) { %><%- user.nameplate %><% } %> + <%= user.nickname %><% if (user.nameplate) { %><%- user.nameplate %><% } %> <%= user.rating %> <% include footer %> diff --git a/views/user.ejs b/views/user.ejs index f7c9d73..f6c63b9 100644 --- a/views/user.ejs +++ b/views/user.ejs @@ -50,6 +50,12 @@
<%= show_user.username %><% if (show_user.nameplate) { %><%- show_user.nameplate %><% } %>
+
+
+

昵称

+
<%= show_user.nickname %>
+
+
<% if (show_user.emailVisible) { %>
diff --git a/views/user_edit.ejs b/views/user_edit.ejs index 583dad0..54e360e 100644 --- a/views/user_edit.ejs +++ b/views/user_edit.ejs @@ -2,58 +2,79 @@ <% include header %> <% include monaco-editor %>
-
hidden<% } %>> - <% if (error_info !== null) { - if (error_info === '') error_info = '修改成功。'; - %> -

<%= error_info %>

- <% } %> -
-
-
+
hidden + <% } %> + > + <% if (error_info !== null) { + if (error_info === '') error_info = '修改成功。'; + %> +

<%= error_info %>

+ <% } %> +
+ +
- - readonly<% } %>> -
+ + readonly + <% } %> + > +
- - + + + -
-
- - readonly<% } %>> -
+
+
+ + readonly + <% } %> + > +
- checked<% } %>> + checked + <% } %> + >
-
+
- checked<% } %>> + checked + <% } %> + >
-
-
+
+
+
+
+ <%- this.showLoadingEditor(); %> +
+ +
+ +
+ +
-
- <%- this.showLoadingEditor(); %> -
- -
- +
@@ -70,95 +91,114 @@
- checked<% } %>> + checked + <% } %> + >
-
- disabled="disabled" <% } %>type="checkbox"<% if (edited_user.privileges.includes('manage_problem')) { %> checked<% } %>> +
+ disabled="disabled" <% } %>type="checkbox" + <% if (edited_user.privileges.includes('manage_problem')) { %> checked + <% } %> + >
-
- disabled="disabled" <% } %>type="checkbox"<% if (edited_user.privileges.includes('manage_problem_tag')) { %> checked<% } %>> +
+ disabled="disabled" <% } %>type="checkbox" + <% if (edited_user.privileges.includes('manage_problem_tag')) { %> checked + <% } %> + >
-
- disabled="disabled" <% } %>type="checkbox"<% if (edited_user.privileges.includes('manage_user')) { %> checked<% } %>> +
+ disabled="disabled" <% } %>type="checkbox" + <% if (edited_user.privileges.includes('manage_user')) { %> checked + <% } %> + >
- - 返回 + + 返回
-
- -
+
+ +
<% include footer %>