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 %>