forked from engineering/cloudservices
fix: usermod lock logic
parent
785baaa902
commit
a075bfdc6e
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue