core&ui: bug fix

pull/163/head
undefined 3 years ago
parent 177dcd6b80
commit e9d1988cba

@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.29.26",
"version": "2.29.27",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",

@ -191,35 +191,36 @@ class SystemUserImportHandler extends SystemHandler {
@param('users', Types.Content)
@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 udocs = [];
const tasks = [];
const messages = [];
for (const i in users) {
const u = users[i];
if (!u.trim()) continue;
const [email, username, password, displayName] = u.split(',').map((t) => t.trim());
if (email && username && password) {
if (!isEmail(email)) messages.push(`Line ${i + 1}: Invalid email.`);
else if (!isUname(username)) messages.push(`Line ${i + 1}: Invalid username`);
else if (!isPassword(password)) messages.push(`Line ${i + 1}: Invalid password`);
if (!isEmail(email)) messages.push(`Line ${+i + 1}: Invalid email.`);
else if (!isUname(username)) messages.push(`Line ${+i + 1}: Invalid username`);
else if (!isPassword(password)) messages.push(`Line ${+i + 1}: Invalid password`);
else {
udocs.push({
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.`);
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.users = udocs;
this.response.body.messages = messages;

@ -65,7 +65,7 @@ const mapDispatchToProps = (dispatch) => ({
});
},
handleClickRefresh() {
this.loadSubmissions();
if (this.props.recordsVisible) this.loadSubmissions();
},
});
@ -75,7 +75,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadTool
};
componentDidMount() {
this.props.loadSubmissions();
if (this.props.recordsVisible) this.props.loadSubmissions();
}
render() {

@ -1,6 +1,6 @@
{
"name": "@hydrooj/ui-default",
"version": "4.12.23",
"version": "4.12.24",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0",
"main": "hydro.js",

@ -23,8 +23,8 @@ const page = new NamedPage('manage_user_import', () => {
}
}
$('[name="preview"]').click(() => post(true));
$('[name="submit"]').click(() => post(false));
$('[name="preview"]').on('click', () => post(true));
$('[name="submit"]').on('click', () => post(false));
});
export default page;

Loading…
Cancel
Save