mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core&ui: bug fix
This commit is contained in:
1 parent
177dcd6b80
commit
e9d1988cba
5 files changed
+22
-21
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user