Skip to content

Commit

Permalink
revert reset password
Browse files Browse the repository at this point in the history
  • Loading branch information
xquanluu committed Dec 19, 2024
1 parent 95b0f55 commit 974682b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion db/reset_admin_password.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const sqlInsert = `INSERT into users
(user_sid, name, email, hashed_password, force_change, provider, email_validated)
values (?, ?, ?, ?, ?, ?, ?)
`;

const sqlInsertAdminToken = `INSERT into api_keys
(api_key_sid, token)
values (?, ?)`;
const sqlQueryAccount = 'SELECT * from accounts LEFT JOIN api_keys ON api_keys.account_sid = accounts.account_sid';
const sqlAddAccountToken = `INSERT into api_keys (api_key_sid, token, account_sid)
VALUES (?, ?, ?)`;
const sqlInsertPermissions = `
INSERT into user_permissions (user_permissions_sid, user_sid, permission_sid)
VALUES (?,?,?)`;
Expand All @@ -31,13 +36,23 @@ const doIt = async() => {
1
]
);
await promisePool.execute(sqlInsertAdminToken, [uuidv4(), uuidv4()]);

/* assign all permissions to the admin user */
const [p] = await promisePool.query('SELECT * from permissions');
for (const perm of p) {
await promisePool.execute(sqlInsertPermissions, [uuidv4(), sid, perm.permission_sid]);
}

/* create admin token for single account */
const [r] = await promisePool.query({sql: sqlQueryAccount, nestTables: true});
if (1 === r.length && r[0].api_keys.api_key_sid === null) {
const api_key_sid = uuidv4();
const token = uuidv4();
const {account_sid} = r[0].accounts;
await promisePool.execute(sqlAddAccountToken, [api_key_sid, token, account_sid]);
}

process.exit(0);
};

Expand Down

0 comments on commit 974682b

Please sign in to comment.