Prevent duplicate user registration (#5129)

This commit is contained in:
MeiMei
2019-07-10 03:47:07 +09:00
committed by syuilo
parent a59ab79da0
commit a091cbb93a
2 changed files with 14 additions and 1 deletions

View File

@ -104,6 +104,13 @@ export default async (ctx: Koa.BaseContext) => {
// Start transaction
await getConnection().transaction(async transactionalEntityManager => {
const exist = await transactionalEntityManager.findOne(User, {
usernameLower: username.toLowerCase(),
host: null
});
if (exist) throw 'already registered';
account = await transactionalEntityManager.save(new User({
id: genId(),
createdAt: new Date(),