From a075bfdc6e7c02bc56f0e7e65bffd2b373f12d6f Mon Sep 17 00:00:00 2001 From: Hiroyuki Date: Thu, 16 Sep 2021 19:55:28 -0400 Subject: [PATCH] fix: usermod lock logic --- src/commands/usermod.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/commands/usermod.ts b/src/commands/usermod.ts index 7f9fe38..5c1af1f 100644 --- a/src/commands/usermod.ts +++ b/src/commands/usermod.ts @@ -19,6 +19,7 @@ export default class Usermod extends Command { const account = await this.client.db.Account.findOne({ $or: [{ username: args[0] }, { userID: args[0] }] }); if (!account) return this.error(message.channel, 'Cannot find user.'); + if (account.root || account.username === 'matthew') return this.error(message.channel, 'You cannot modify properties of root accounts.'); switch (property) { case 'email': { @@ -47,20 +48,19 @@ export default class Usermod extends Command { try { await this.client.commands.get('notify') .run(message, [account.username, ...`Changing your username from \`${account.username}\` to \`${value}\`.`.split(' ')]); - if (!account.locked) { - await account.updateOne({ locked: true }); - await this.client.util.exec(`lock ${account.username}`); - } + if (!account.locked) await this.client.util.exec(`lock ${account.username}`); await this.client.util.exec(`usermod -l ${value} ${account.username}`); await rename(account.homepath, `/home/${value}`); await this.client.util.exec(`usermod -d /home/${value} ${value}`); await this.client.util.exec(`groupmod -n ${value} ${account.username}`); + if (!account.locked) await this.client.util.exec(`unlock ${value}`); await account.updateOne({ username: value, homepath: `/home/${value}`, }); + await this.client.db.Moderation.updateMany( { username: account.username, @@ -71,15 +71,13 @@ export default class Usermod extends Command { await this.client.commands.get('notify') .run(message, [value, ...`Your username has been successfully changed. Remember to use \`ssh ${value}@cloud.libraryofcode.org\` when logging in.`.split(' ')]); } catch (error) { + if (!account.locked) await this.client.util.exec(`unlock ${account.username}`); + await this.client.commands.get('notify') .run(message, [account.username, ...'Your username change was unsuccessful. Please contact a Technician for more details.'.split(' ')]); await this.client.util.handleError(error); + return this.error(message.channel, 'Failed to modify username. Please check <#595788220764127272> for more information.'); - } finally { - if (!account.locked) { - await this.client.util.exec(`unlock ${account.username}`); - await account.updateOne({ locked: false }); - } } modifyingPropertyResponse.delete();