core&ui: bug fix

This commit is contained in:
undefined committed 2021-07-17 18:23:33 +08:00
1 parent 177dcd6b80
commit e9d1988cba
5 files changed
+22 -21

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.29.26", "version": "2.29.27",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
+16 -15
View File
@@ -191,35 +191,36 @@ class SystemUserImportHandler extends SystemHandler {
@param('users', Types.Content) @param('users', Types.Content)
@param('draft', Types.Boolean) @param('draft', Types.Boolean)
async post(domainId: string, _users: string, draft: boolean) { async post(domainId: string, _users: string, draft = true) {
const users = _users.split('\n'); const users = _users.split('\n');
const udocs = []; const udocs = [];
const tasks = [];
const messages = []; const messages = [];
for (const i in users) { for (const i in users) {
const u = users[i]; const u = users[i];
if (!u.trim()) continue;
const [email, username, password, displayName] = u.split(',').map((t) => t.trim()); const [email, username, password, displayName] = u.split(',').map((t) => t.trim());
if (email && username && password) { if (email && username && password) {
if (!isEmail(email)) messages.push(`Line ${i + 1}: Invalid email.`); if (!isEmail(email)) messages.push(`Line ${+i + 1}: Invalid email.`);
else if (!isUname(username)) messages.push(`Line ${i + 1}: Invalid username`); else if (!isUname(username)) messages.push(`Line ${+i + 1}: Invalid username`);
else if (!isPassword(password)) messages.push(`Line ${i + 1}: Invalid password`); else if (!isPassword(password)) messages.push(`Line ${+i + 1}: Invalid password`);
else { else {
udocs.push({ udocs.push({
email, username, password, displayName, email, username, password, displayName,
}); });
if (!draft) {
tasks.push(
(async () => {
const uid = await user.create(email, username, password);
if (displayName) await domain.setUserInDomain(domainId, uid, { displayName });
})(),
);
} }
} } else messages.push(`Line ${+i + 1}: Input invalid.`);
} else messages.push(`Line ${i + 1}: Input invalid.`);
} }
messages.push(`${udocs.length} users found.`); messages.push(`${udocs.length} users found.`);
await Promise.all(tasks); if (!draft) {
for (const {
email, username, password, displayName,
} of udocs) {
// eslint-disable-next-line no-await-in-loop
const uid = await user.create(email, username, password);
// eslint-disable-next-line no-await-in-loop
if (displayName) await domain.setUserInDomain(domainId, uid, { displayName });
}
}
this.response.body.path.push(['manage_user_import']); this.response.body.path.push(['manage_user_import']);
this.response.body.users = udocs; this.response.body.users = udocs;
this.response.body.messages = messages; this.response.body.messages = messages;
@@ -65,7 +65,7 @@ const mapDispatchToProps = (dispatch) => ({
}); });
}, },
handleClickRefresh() { handleClickRefresh() {
this.loadSubmissions(); if (this.props.recordsVisible) this.loadSubmissions();
}, },
}); });
@@ -75,7 +75,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
}; };
componentDidMount() { componentDidMount() {
this.props.loadSubmissions(); if (this.props.recordsVisible) this.props.loadSubmissions();
} }
render() { render() {
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.12.23", "version": "4.12.24",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",
@@ -23,8 +23,8 @@ const page = new NamedPage('manage_user_import', () => {
} }
} }
$('[name="preview"]').click(() => post(true)); $('[name="preview"]').on('click', () => post(true));
$('[name="submit"]').click(() => post(false)); $('[name="submit"]').on('click', () => post(false));
}); });
export default page; export default page;