mirror of
https://github.com/HeyPuter/puter.git
synced 2026-01-01 02:30:41 -06:00
fix: move temp users to 'user' group when email is confirmed
Temporary users can go through email confirmation which effectively makes these users registered/permanent users. When email is confirmed they should be moved to the default group for registered users.
This commit is contained in:
@@ -367,6 +367,9 @@ const install = async ({ services, app, useapi, modapi }) => {
|
||||
|
||||
const { ReferralCodeService } = require('./services/ReferralCodeService');
|
||||
services.registerService('referral-code', ReferralCodeService);
|
||||
|
||||
const { VerifiedGroupService } = require('./services/VerifiedGroupService');
|
||||
services.registerService('__verified-group', VerifiedGroupService);
|
||||
|
||||
const { UserService } = require('./services/UserService');
|
||||
services.registerService('user', UserService);
|
||||
|
||||
28
src/backend/src/services/VerifiedGroupService.js
Normal file
28
src/backend/src/services/VerifiedGroupService.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const { get_user } = require("../helpers");
|
||||
const BaseService = require("./BaseService");
|
||||
|
||||
class VerifiedGroupService extends BaseService {
|
||||
async _init () {
|
||||
const config = this.global_config;
|
||||
|
||||
const svc_event = this.services.get('event');
|
||||
svc_event.on('user.email-confirmed', async (_, { user_uid }) => {
|
||||
const user = await get_user({ uuid: user_uid });
|
||||
|
||||
// Update group
|
||||
const svc_group = this.services.get('group');
|
||||
await svc_group.remove_users({
|
||||
uid: config.default_temp_group,
|
||||
users: [user.username],
|
||||
});
|
||||
await svc_group.add_users({
|
||||
uid: config.default_user_group,
|
||||
users: [user.username]
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
VerifiedGroupService,
|
||||
};
|
||||
Reference in New Issue
Block a user