This commit is contained in:
syuilo
2018-08-17 19:17:23 +09:00
parent dcdb57df9d
commit 2c8f962889
9 changed files with 124 additions and 33 deletions

View File

@ -0,0 +1,26 @@
import rndstr from 'rndstr';
import RegistrationTicket from '../../../../models/registration-tickets';
export const meta = {
desc: {
ja: '招待コードを発行します。'
},
requireCredential: true,
requireAdmin: true,
params: {}
};
export default (params: any) => new Promise(async (res, rej) => {
const code = rndstr({ length: 5, chars: '0-9' });
await RegistrationTicket.insert({
createdAt: new Date(),
code: code
});
res({
code: code
});
});

View File

@ -4,43 +4,43 @@ import getParams from '../../get-params';
import User from '../../../../models/user';
export const meta = {
desc: {
ja: '指定したユーザーを凍結します。',
en: 'Suspend a user.'
},
desc: {
ja: '指定したユーザーを凍結します。',
en: 'Suspend a user.'
},
requireCredential: true,
requireAdmin: true,
requireCredential: true,
requireAdmin: true,
params: {
userId: $.type(ID).note({
desc: {
ja: '対象のユーザーID',
en: 'The user ID which you want to suspend'
}
}),
}
params: {
userId: $.type(ID).note({
desc: {
ja: '対象のユーザーID',
en: 'The user ID which you want to suspend'
}
}),
}
};
export default (params: any) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const user = await User.findOne({
_id: ps.userId
});
const user = await User.findOne({
_id: ps.userId
});
if (user == null) {
return rej('user not found');
}
if (user == null) {
return rej('user not found');
}
await User.findOneAndUpdate({
_id: user._id
}, {
$set: {
isSuspended: true
}
});
await User.findOneAndUpdate({
_id: user._id
}, {
$set: {
isSuspended: true
}
});
res();
res();
});

View File

@ -28,6 +28,7 @@ export default () => new Promise(async (res, rej) => {
model: os.cpus()[0].model,
cores: os.cpus().length
},
broadcasts: meta.broadcasts
broadcasts: meta.broadcasts,
disableRegistration: meta.disableRegistration
});
});

View File

@ -6,6 +6,7 @@ import User, { IUser, validateUsername, validatePassword, pack } from '../../../
import generateUserToken from '../common/generate-native-user-token';
import config from '../../../config';
import Meta from '../../../models/meta';
import RegistrationTicket from '../../../models/registration-tickets';
if (config.recaptcha) {
recaptcha.init({
@ -29,6 +30,29 @@ export default async (ctx: Koa.Context) => {
const username = body['username'];
const password = body['password'];
const invitationCode = body['invitationCode'];
const meta = await Meta.findOne({});
if (meta.disableRegistration) {
if (invitationCode == null || typeof invitationCode != 'string') {
ctx.status = 400;
return;
}
const ticket = await RegistrationTicket.findOne({
code: invitationCode
});
if (ticket == null) {
ctx.status = 400;
return;
}
RegistrationTicket.remove({
_id: ticket._id
});
}
// Validate username
if (!validateUsername(username)) {