mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-04 00:20:45 +00:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user