diff --git a/role-verification/role-verification.component.ts b/role-verification/role-verification.component.ts index b50d9aaa..1883662f 100644 --- a/role-verification/role-verification.component.ts +++ b/role-verification/role-verification.component.ts @@ -8,6 +8,8 @@ import {Subscriber} from "rxjs"; import {FormBuilder, FormControl, Validators} from "@angular/forms"; import {AlertModal} from "../utils/modal/alert"; import {properties} from "../../../environments/environment"; +import {EmailService} from "../utils/email/email.service"; +import {Composer} from "../utils/email/composer"; @Component({ selector: 'role-verification', @@ -103,6 +105,7 @@ export class RoleVerificationComponent implements OnInit, OnDestroy { constructor(private route: ActivatedRoute, private router: Router, private fb: FormBuilder, + private emailService: EmailService, private userManagementService: UserManagementService, private userRegistryService: UserRegistryService) { } @@ -178,14 +181,31 @@ export class RoleVerificationComponent implements OnInit, OnDestroy { public verifyManager() { this.loading = true; this.subs.push(this.userRegistryService.verify(this.verification.id, this.code.value).subscribe(() => { - this.loading = false; this.managerModal.cancel(); this.error = null; this.userManagementService.updateUserInfo(() => { if(this.service === "monitor") { + this.loading = false; this.router.navigate(['/admin/' + this.verification.entity]); } else { - window.location.href = properties.adminPortalURL + '/' + this.verification.entity; + this.subs.push(this.emailService.notifyManagers(this.id, 'manager', + Composer.composeEmailToInformOldManagersForTheNewOnes(this.name, this.id)).subscribe(() => { + this.subs.push(this.emailService.notifyNewManager(Composer.composeEmailForNewManager(this.id, this.name)).subscribe( + () => { + this.loading = false; + window.location.href = properties.adminPortalURL + '/' + this.verification.entity; + }, + error1 => { + console.error(error1); + this.loading = false; + window.location.href = properties.adminPortalURL + '/' + this.verification.entity; + } + )); + }, error => { + console.error(error); + this.loading = false; + window.location.href = properties.adminPortalURL + '/' + this.verification.entity; + })); } }); }, error => { diff --git a/utils/email/composer.ts b/utils/email/composer.ts index bc1fadd4..de9feb2c 100644 --- a/utils/email/composer.ts +++ b/utils/email/composer.ts @@ -14,11 +14,11 @@ export class Composer { private static ifYouAreNotResponsible(mail): string { return "If you are not responsible for this community, please " - + "contact us. "; + + "contact us. "; } private static manageNotificationSettings(communityId: string): string { - return "Click here to manage your notification settings. "; } @@ -27,7 +27,7 @@ export class Composer { + "" + communityName + ". "; } - public static composeEmailForNewManager(communityId: string, communityName: string, newCommunityManagers: any, mail: string): Email { + public static composeEmailForNewManager(communityId: string, communityName: string): Email { let email: Email = new Email(); email.subject = this.subjectPrefix + communityName + ": Welcome new manager"; @@ -41,10 +41,8 @@ export class Composer { + "You can access the administration tool by clicking the \"Manage\" button that will be available in the top right corner of the dashboard." + "

" + this.signature - + "

" + this.ifYouAreNotResponsible(mail) + "

" + + "

" + this.ifYouAreNotResponsible(properties.admins[0]) + "

" + ""; - email.recipients = newCommunityManagers; - return email; } @@ -135,34 +133,32 @@ export class Composer { return email; } - public static composeEmailToInformOldManagersForTheNewOnes(communityName: string, communityId: string, firstVersionOfManagers: any, managers: any, mail: string) : Email { + public static composeEmailToInformOldManagersForTheNewOnes(communityName: string, communityId: string) : Email { let email: Email = new Email(); email.subject = this.subjectPrefix + communityName + ": Managers list notification"; email.body = "

" + "

There are updates in the managers list for \"" + communityName + "\" community.
" - + "The list of managers is: " + managers.join(', ') + "

" + + "The list of managers is: ((__managers__))

" + this.signature + "

" + this.youAreManagerOfTheCommunity(communityId, communityName) - + this.ifYouAreNotResponsible(mail) + + this.ifYouAreNotResponsible(properties.admins[0]) + "
" + this.manageNotificationSettings(communityId) + "

" + "
"; - email.recipients = firstVersionOfManagers; - return email; } - public static composeEmailToInformManagers(communityName: string, communityId: string, managers: any, subscriberMail: any, adminPortalURL: string): Email { + public static composeEmailToInformManagers(communityName: string, communityId: string, subscriberName: string): Email { let email: Email = new Email(); email.subject = this.subjectPrefix + communityName + ": New subscriber notification"; email.body = "
" - + "

There is a new subscriber ("+subscriberMail+") for \"" + communityName + "\" community. Click " - + "here to manage the subscribers list.

" + + "

There is a new subscriber ("+subscriberName+") for \"" + communityName + "\" community. Click " + + "here to manage the subscribers list.

" + this.signature + "

" + this.youAreManagerOfTheCommunity(communityId, communityName) @@ -170,8 +166,6 @@ export class Composer { + this.manageNotificationSettings(communityId) + "

" + "
"; - email.recipients = managers; - return email; } diff --git a/utils/email/email.service.ts b/utils/email/email.service.ts index bac4c7c4..92db0aed 100644 --- a/utils/email/email.service.ts +++ b/utils/email/email.service.ts @@ -5,25 +5,24 @@ import {CustomOptions} from '../../services/servicesUtils/customOptions.class'; import {EmailRecaptcha} from "../entities/EmailRecaptcha"; import {Observable} from "rxjs"; import {EnvProperties} from "../properties/env-properties"; +import {properties} from "../../../../environments/environment"; @Injectable() export class EmailService { constructor(private http:HttpClient) { } - - notifyForNewManagers(properties: EnvProperties, pid: string, email: Email) { - let body = JSON.stringify(email); - - return this.http.post(properties.adminToolsAPIURL + "/notifyForNewSubscribers/" + pid, body, CustomOptions.getAuthOptionsWithBody()); - //.map(request => request.json()); + + notifyManagers(pid: string, role: "manager" | "subscriber", email: Email) { + return this.http.post(properties.adminToolsAPIURL + '/notifyManagers/' + pid + '/' + role, email, CustomOptions.getAuthOptions()) + } + + notifyNewManager(email: Email) { + return this.http.post(properties.adminToolsAPIURL + '/notifyNewManager', email, CustomOptions.getAuthOptions()) } sendEmail(properties: EnvProperties, email: Email) { - let body = JSON.stringify(email); - - return this.http.post(properties.adminToolsAPIURL + "/sendMail/", body, CustomOptions.getAuthOptionsWithBody()); - //.map(request => request.json()); + return this.http.post(properties.adminToolsAPIURL + "/sendMail/", email, CustomOptions.registryOptions()); } contact(properties: EnvProperties, email: Email, recaptcha: string = null):Observable {