1
0
Fork 0

fix: usermod lock logic

master
Hiroyuki 2021-09-16 19:55:28 -04:00
parent 785baaa902
commit a075bfdc6e
No known key found for this signature in database
GPG Key ID: AF65958B7B7362E6
1 changed files with 7 additions and 9 deletions

View File

@ -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] }] }); 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) 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) { switch (property) {
case 'email': { case 'email': {
@ -47,20 +48,19 @@ 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}\`.`.split(' ')]); .run(message, [account.username, ...`Changing your username from \`${account.username}\` to \`${value}\`.`.split(' ')]);
if (!account.locked) { if (!account.locked) await this.client.util.exec(`lock ${account.username}`);
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 rename(account.homepath, `/home/${value}`); await rename(account.homepath, `/home/${value}`);
await this.client.util.exec(`usermod -d /home/${value} ${value}`); await this.client.util.exec(`usermod -d /home/${value} ${value}`);
await this.client.util.exec(`groupmod -n ${value} ${account.username}`); await this.client.util.exec(`groupmod -n ${value} ${account.username}`);
if (!account.locked) await this.client.util.exec(`unlock ${value}`);
await account.updateOne({ await account.updateOne({
username: value, username: value,
homepath: `/home/${value}`, homepath: `/home/${value}`,
}); });
await this.client.db.Moderation.updateMany( await this.client.db.Moderation.updateMany(
{ {
username: account.username, username: account.username,
@ -71,15 +71,13 @@ export default class Usermod extends Command {
await this.client.commands.get('notify') 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(' ')]); .run(message, [value, ...`Your username has been successfully changed. Remember to use \`ssh ${value}@cloud.libraryofcode.org\` when logging in.`.split(' ')]);
} catch (error) { } catch (error) {
if (!account.locked) await this.client.util.exec(`unlock ${account.username}`);
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(' ')]);
await this.client.util.handleError(error); await this.client.util.handleError(error);
return this.error(message.channel, 'Failed to modify username. Please check <#595788220764127272> for more information.'); 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(); modifyingPropertyResponse.delete();