refactor: usermod account lock logic

pull/15/head
Hiroyuki 2021-09-12 21:52:03 -04:00
parent ec343d541c
commit d4c740206d
No known key found for this signature in database
GPG Key ID: AF65958B7B7362E6
1 changed files with 10 additions and 4 deletions

View File

@ -45,7 +45,10 @@ export default class Usermod extends Command {
try { try {
await this.client.commands.get('notify') await this.client.commands.get('notify')
.run(message, [account.username, ...`Changing your username from \`${account.username}\` to \`${value}\`. DN/C`.split(' ')]); .run(message, [account.username, ...`Changing your username from \`${account.username}\` to \`${value}\`. DN/C`.split(' ')]);
await this.client.util.exec(`lock ${account.username}`); if (!account.locked) {
await account.updateOne({ locked: true });
await this.client.util.exec(`lock ${account.username}`);
}
await this.client.util.exec(`usermod -l ${value} ${account.username}`); await this.client.util.exec(`usermod -l ${value} ${account.username}`);
await this.client.util.exec(`usermod -d /home/${value} ${value}`); await this.client.util.exec(`usermod -d /home/${value} ${value}`);
@ -59,10 +62,13 @@ export default class Usermod extends Command {
} catch (error) { } catch (error) {
await this.client.commands.get('notify') await this.client.commands.get('notify')
.run(message, [account.username, ...'Your username change was unsuccessful. Please contact a Technician for more details.'.split(' ')]); .run(message, [account.username, ...'Your username change was unsuccessful. Please contact a Technician for more details.'.split(' ')]);
this.error(message.channel, 'Failed to modify username.'); await this.client.util.handleError(error);
return this.client.util.handleError(error); return this.error(message.channel, 'Failed to modify username. Please check <#595788220764127272> for more information.');
} finally { } finally {
await this.client.util.exec(`unlock ${account.username}`); if (account.locked) {
await this.client.util.exec(`unlock ${account.username}`);
await account.updateOne({ locked: false });
}
} }
modifyingPropertyResponse.delete(); modifyingPropertyResponse.delete();