mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
批量导入用户功能
This commit is contained in:
1 parent
21347e75d4
commit
37d449d42f
5 files changed
+40
-7
No files matched your search
@@ -6,6 +6,4 @@ pdoc.secretConfig?
|
||||
message.markAsRead
|
||||
批量导入用户
|
||||
domain_join_application
|
||||
user.displayName
|
||||
problem.difficulty_setting
|
||||
用户等级计算
|
||||
problem.difficulty_setting
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hydrooj",
|
||||
"version": "2.12.4",
|
||||
"version": "2.12.5",
|
||||
"bin": "bin/hydrooj.js",
|
||||
"main": "dist/loader.js",
|
||||
"typings": "dist/loader.d.ts",
|
||||
|
||||
@@ -3,12 +3,15 @@ import { ValidationError } from '../error';
|
||||
import * as check from '../check';
|
||||
import * as setting from '../model/setting';
|
||||
import * as system from '../model/system';
|
||||
import * as user from '../model/user';
|
||||
import { STATUS, PRIV } from '../model/builtin';
|
||||
import * as record from '../model/record';
|
||||
import {
|
||||
Route, Connection, Handler, ConnectionHandler, param, Types,
|
||||
} from '../service/server';
|
||||
import { validate } from '../lib/validator';
|
||||
import {
|
||||
validate, isEmail, isUname, isPassword,
|
||||
} from '../lib/validator';
|
||||
|
||||
function set(key, value) {
|
||||
if (setting.SYSTEM_SETTINGS_BY_KEY[key]) {
|
||||
@@ -159,11 +162,44 @@ class SystemSettingHandler extends SystemHandler {
|
||||
}
|
||||
}
|
||||
|
||||
class SystemUserImportHandler extends SystemHandler {
|
||||
async get() {
|
||||
this.response.body.users = [];
|
||||
this.response.template = 'manage_user_import.html';
|
||||
}
|
||||
|
||||
@param('users', Types.String)
|
||||
@param('confirm', Types.Boolean)
|
||||
async post(domainId: string, _users: string, confirm: boolean) {
|
||||
const users = _users.split('\n');
|
||||
const udocs = [];
|
||||
const tasks = [];
|
||||
const messages = [];
|
||||
for (const i in users) {
|
||||
const u = users[i];
|
||||
const [email, username, password] = 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`);
|
||||
else {
|
||||
udocs.push({ email, username, password });
|
||||
if (!confirm) tasks.push(user.create(email, username, password));
|
||||
}
|
||||
} else messages.push(`Line ${i + 1}: Input invalid.`);
|
||||
}
|
||||
await Promise.all(tasks);
|
||||
this.response.body.users = udocs;
|
||||
this.response.body.messages = messages;
|
||||
}
|
||||
}
|
||||
|
||||
async function apply() {
|
||||
Route('manage', '/manage', SystemMainHandler);
|
||||
Route('manage_dashboard', '/manage/dashboard', SystemDashboardHandler);
|
||||
Route('manage_script', '/manage/script', SystemScriptHandler);
|
||||
Route('manage_setting', '/manage/setting', SystemSettingHandler);
|
||||
Route('manage_user_import', '/manage/userimport', SystemUserImportHandler);
|
||||
Connection('manage_check', '/manage/check-conn', SystemCheckConnHandler);
|
||||
}
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ export async function inc(_id: number, field: string, n = 1) {
|
||||
|
||||
export async function create(
|
||||
mail: string, uname: string, password: string,
|
||||
uid: number, regip = '127.0.0.1', priv = PRIV.PRIV_DEFAULT,
|
||||
uid?: number, regip = '127.0.0.1', priv = PRIV.PRIV_DEFAULT,
|
||||
) {
|
||||
const salt = String.random();
|
||||
if (!uid) uid = await system.inc('user');
|
||||
|
||||
@@ -9,7 +9,6 @@ import * as record from '../model/record';
|
||||
import { STATUS } from '../model/builtin';
|
||||
import rating from '../lib/rating';
|
||||
import paginate from '../lib/paginate';
|
||||
import ranked from '../lib/rank';
|
||||
|
||||
export const description = 'Calculate rp of a domain, or all domains';
|
||||
|
||||
|
||||
Reference in new issue
Block a user