Prevent username reusing

This commit is contained in:
syuilo
2019-07-22 10:15:00 +09:00
parent 3432d6e615
commit 85008303f5
7 changed files with 59 additions and 3 deletions

View File

@ -1,6 +1,6 @@
import $ from 'cafy';
import define from '../../define';
import { Users } from '../../../../models';
import { Users, UsedUsernames } from '../../../../models';
export const meta = {
tags: ['users'],
@ -21,7 +21,9 @@ export default define(meta, async (ps) => {
usernameLower: ps.username.toLowerCase()
});
const exist2 = await UsedUsernames.count({ username: ps.username.toLowerCase() });
return {
available: exist === 0
available: exist === 0 && exist2 === 0
};
});