tweak: make monthly username changes configurable

The monthly number of username changes was hardcoded as `2`. Being able
to configure this value makes it easier to test the username change
flow. Hosters of OSS Puter may also find this configuration beneficial.
This commit is contained in:
KernelDeimos
2026-02-11 18:41:27 -05:00
parent d532b3d47b
commit 3a9a345600
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -78,9 +78,9 @@ module.exports = eggspress('/change_username', {
mysql: '`created_at` > DATE_SUB(NOW(), INTERVAL 1 MONTH)',
sqlite: "`created_at` > datetime('now', '-1 month')",
})}`,
[ req.user.id, 'change_username' ]);
[req.user.id, 'change_username']);
if ( rows[0].count >= 2 ) {
if ( rows[0].count >= (config.max_username_changes ?? 2) ) {
throw APIError.create('too_many_username_changes');
}
@@ -57,16 +57,16 @@ module.exports = {
mysql: '`created_at` > DATE_SUB(NOW(), INTERVAL 1 MONTH)',
sqlite: "`created_at` > datetime('now', '-1 month')",
})}`,
[ user.id, 'change_username' ]);
[user.id, 'change_username']);
if ( rows[0].count >= 2 ) {
if ( rows[0].count >= (config.max_username_changes ?? 2) ) {
throw APIError.create('too_many_username_changes');
}
await db.write('INSERT INTO `user_update_audit` ' +
'(`user_id`, `user_id_keep`, `old_username`, `new_username`, `reason`) ' +
'VALUES (?, ?, ?, ?, ?)',
[ user.id, user.id, user.username, new_username, 'change_username' ]);
[user.id, user.id, user.username, new_username, 'change_username']);
await change_username(user.id, new_username);