diff --git a/misc/conf.example.json b/misc/conf.example.json index 39269aa..c4f1802 100644 --- a/misc/conf.example.json +++ b/misc/conf.example.json @@ -56,7 +56,7 @@ }, "connections": { "frontend_url_base": "http://localhost:8888", - "login_url": null + "login_url": "https://login.example.org" } }, "outputs": [ diff --git a/misc/sampledata.json b/misc/sampledata.json index eef9e1f..aba990c 100644 --- a/misc/sampledata.json +++ b/misc/sampledata.json @@ -39,21 +39,24 @@ "name": "alexandra", "label": "Alexandra Ahorn", "email_address": "alex-rockt@example.org", - "groups": [1, 2, 3] + "groups": [1, 2, 3], + "password": "aaa111" }, { "id": 2, "name": "berthold", "label": "Berthold Buche", "email_address": "bert-ohne-ernie@example.org", - "groups": [4, 5, 2] + "groups": [4, 5, 2], + "password": "bbb222" }, { "id": 3, "name": "charlotte", "label": "Charlotte Castania", "email_address": "charly-the-unicorn@example.org", - "groups": [4, 1] + "groups": [4, 1], + "password": "ccc333" } ], "invitations": [ diff --git a/source/data/localization/deu.loc.json b/source/data/localization/deu.loc.json index d86a9e3..f4cea87 100644 --- a/source/data/localization/deu.loc.json +++ b/source/data/localization/deu.loc.json @@ -4,7 +4,7 @@ }, "tree": { "email.registration.subject": "Registrierung erfolgt", - "email.registration.body": "Das Mitglied '{{name_display}}' hat sich soeben registriert:\n\n{{url}}", + "email.registration.body": "'{{name}}' ('{{label}}') wurde soeben registriert", "email.activation.subject": "Freischaltung erfolgt", "email.activation.body": "Hi, {{name_display}}\n\nDein Mitglieder-Konto wurde gerade freigeschalten. Du kannst dich nun anmelden:\n\nURL: {{url}}\nAnmelde-Name: {{name_login}}\n{{password_info}}", "email.activation.password_info": "Passwort: {{password}}\n\nBitte ändere dein Passwort zeitnah!", diff --git a/source/data/localization/eng.loc.json b/source/data/localization/eng.loc.json index 8d8875b..1cfced3 100644 --- a/source/data/localization/eng.loc.json +++ b/source/data/localization/eng.loc.json @@ -4,7 +4,7 @@ }, "tree": { "email.registration.subject": "Registration received", - "email.registration.body": "The member '{{name_display}}' just registered:\n\n{{url}}", + "email.registration.body": "'{{name}}' ('{{label}}') just has been registered", "email.activation.subject": "Activated", "email.activation.body": "Hi, {{name_display}}\n\nYour account has just been activated. You may login now:\n\nURL: {{url}}\nLogin name: {{name_login}}\n{{password_info}}", "email.activation.password_info": "Password: {{password}}\n\nPlease change your password soon!", diff --git a/source/sample.ts b/source/sample.ts index f0db8f7..5190480 100644 --- a/source/sample.ts +++ b/source/sample.ts @@ -41,6 +41,7 @@ namespace _espe.sample label : string; email_address : (null | string); groups : Array; + password : string; } >; invitations : Array< @@ -94,15 +95,19 @@ namespace _espe.sample { for (const member_raw of data.members) { - const member_id : _espe.type.member_id = await _espe.service.member.project( + const member_id : _espe.type.member_id = await _espe.service.member.add( { "name": member_raw.name, "label": member_raw.label, "email_address": member_raw.email_address, "groups": member_raw.groups.map(group_id => track_groups.get(group_id)), + "password": member_raw.password, }, { - "silent": true, + "password_generated": false, + "signal_change": false, + "greet_member": false, + "notify_admins": false, } ); } diff --git a/source/services/invitation.ts b/source/services/invitation.ts index 1e526b3..652dbbb 100644 --- a/source/services/invitation.ts +++ b/source/services/invitation.ts @@ -295,14 +295,15 @@ namespace _espe.service.invitation } else { - const password : string = ( - ( - (data.password !== null) - && - (data.password !== "") - ) + let password_generated : boolean = ( + (data.password === null) + || + (data.password === "") + ); + const password_value : string = ( + password_generated ? - data.password + (data.password as string) : _espe.service.member.generate_password() ); @@ -311,7 +312,7 @@ namespace _espe.service.invitation incident : string; details : Record; } - > = _espe.service.member.validate_password(password); + > = _espe.service.member.validate_password(password_value); if (flaws_password.length > 0) { return ( @@ -373,7 +374,13 @@ namespace _espe.service.invitation ?? [] ), - "password": password, + "password": password_value, + }, + { + "password_generated": password_generated, + "signal_change": true, + "greet_member": true, + "notify_admins": true, } ); diff --git a/source/services/member.ts b/source/services/member.ts index 445313d..ea608c1 100644 --- a/source/services/member.ts +++ b/source/services/member.ts @@ -145,18 +145,15 @@ namespace _espe.service.member */ async function send_activation_email( member_object : _espe.type.member_object, - options : { + { + "password": password = null, + } : { password ?: (null | string); } = {} ) : Promise { - options = Object.assign( - { - "password": null, - }, - options - ); - if (! member_object.enabled) { + if (! member_object.enabled) + { // do nothing } else { @@ -185,15 +182,17 @@ namespace _espe.service.member "url": (_espe.conf.get().settings.connections.login_url ?? "--"), "password_info": ( ( - (options.password === undefined) + (password === undefined) || - (options.password === null) + (password === null) ) - ? "" - : lib_plankton.string.coin( + ? + "" + : + lib_plankton.string.coin( lib_plankton.translate.get("email.activation.password_info"), { - "password": options.password, + "password": password, } ) ), @@ -260,47 +259,6 @@ namespace _espe.service.member } - /** - * legt ein Mitglied an - */ - export async function project( - data : { - name : string; - label : string; - email_address : (null | string); - groups : Array<_espe.type.group_id>; - }, - { - "silent": silent = false, - } : { - silent ?: boolean; - } = { - } - ) : Promise<_espe.type.member_id> - { - const object : _espe.type.member_object = { - "name": data.name, - "label": data.label, - "email_address": data.email_address, - "groups": data.groups, - "enabled": true, - "password_image": null, - "password_change_last_attempt": null, - "password_change_token": null, - }; - const id : _espe.type.member_id = await _espe.repository.member.create(object); - if (silent) - { - // do nothing - } - else - { - signal_change(); - } - return id; - } - - /** * legt ein Mitglied an */ @@ -313,9 +271,15 @@ namespace _espe.service.member password : string; }, { - "silent": silent = false, + "password_generated": password_generated = false, + "signal_change": flag_signal_change = false, + "greet_member": flag_greet_member = false, + "notify_admins": flag_notify_admins = false, } : { - silent ?: boolean; + password_generated ?: boolean; + signal_change ?: boolean; + greet_member ?: boolean; + notify_admins ?: boolean; } = { } ) : Promise<_espe.type.member_id> @@ -331,13 +295,58 @@ namespace _espe.service.member "password_change_token": null, }; const id : _espe.type.member_id = await _espe.repository.member.create(object); - if (silent) + // change { - // do nothing + if (! flag_signal_change) + { + // do nothing + } + else + { + signal_change(); + } } - else + // greet member { - signal_change(); + if (! flag_greet_member) + { + // do nothing + } + else + { + await send_activation_email( + object, + { + "password": (password_generated ? data.password : null), + } + ); + } + } + // notify admins + { + if (! flag_notify_admins) + { + // do nothing + } + else + { + _espe.service.admin.notify_all( + lib_plankton.string.coin( + "{{head}} | {{core}}", + { + "head": _espe.conf.get().settings.organisation.name, + "core": lib_plankton.translate.get("email.registration.subject"), + } + ), + lib_plankton.string.coin( + lib_plankton.translate.get("email.registration.body"), + { + "name": object.name, + "label": object.label, + } + ) + ); + } } return id; }