forked from CenterForOpenScience/angular-osf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthenticated-identity.component.ts
More file actions
92 lines (77 loc) · 3.48 KB
/
authenticated-identity.component.ts
File metadata and controls
92 lines (77 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { createDispatchMap, select } from '@ngxs/store';
import { TranslatePipe } from '@ngx-translate/core';
import { Button } from 'primeng/button';
import { Tooltip } from 'primeng/tooltip';
import { finalize } from 'rxjs';
import { NgOptimizedImage } from '@angular/common';
import { ChangeDetectionStrategy, Component, computed, inject, OnInit } from '@angular/core';
import { ENVIRONMENT } from '@core/provider/environment.provider';
import { AuthService } from '@core/services/auth.service';
import { ExternalIdentityStatus } from '@osf/shared/enums/external-identity-status.enum';
import { CustomConfirmationService } from '@osf/shared/services/custom-confirmation.service';
import { LoaderService } from '@osf/shared/services/loader.service';
import { ToastService } from '@osf/shared/services/toast.service';
import {
AccountSettingsSelectors,
DeleteExternalIdentity,
GetExternalIdentities,
} from '../../../account-settings/store';
import { ProfileSettingsTabOption } from '../../enums';
@Component({
selector: 'osf-authenticated-identity',
imports: [NgOptimizedImage, Button, Tooltip, TranslatePipe],
templateUrl: './authenticated-identity.component.html',
styleUrl: './authenticated-identity.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AuthenticatedIdentityComponent implements OnInit {
private readonly authService = inject(AuthService);
private readonly environment = inject(ENVIRONMENT);
private readonly customConfirmationService = inject(CustomConfirmationService);
private readonly toastService = inject(ToastService);
private readonly loaderService = inject(LoaderService);
private readonly ORCID_PROVIDER = 'ORCID';
ngOnInit() {
this.actions.getExternalIdentities();
}
readonly actions = createDispatchMap({
deleteExternalIdentity: DeleteExternalIdentity,
getExternalIdentities: GetExternalIdentities,
});
readonly externalIdentities = select(AccountSettingsSelectors.getExternalIdentities);
readonly orcidUrl = computed(() => {
return this.existingOrcid() ? `https://orcid.org/${this.existingOrcid()}` : null;
});
readonly existingOrcid = computed(
(): string | undefined =>
this.externalIdentities()?.find((i) => i.id === 'ORCID' && i.status === ExternalIdentityStatus.VERIFIED)
?.externalId
);
disconnectOrcid(): void {
this.customConfirmationService.confirmDelete({
headerKey: 'settings.accountSettings.connectedIdentities.deleteDialog.header',
messageParams: { name: this.ORCID_PROVIDER },
messageKey: 'settings.accountSettings.connectedIdentities.deleteDialog.message',
onConfirm: () => {
this.loaderService.show();
this.actions
.deleteExternalIdentity(this.ORCID_PROVIDER)
.pipe(finalize(() => this.loaderService.hide()))
.subscribe(() => this.toastService.showSuccess('settings.accountSettings.connectedIdentities.successDelete'));
},
});
}
connectOrcid(): void {
const webUrl = this.environment.webUrl;
const casUrl = this.environment.casUrl;
const finalDestination = new URL(`${webUrl}/settings/profile`);
finalDestination.searchParams.set('tab', ProfileSettingsTabOption.Social.toString());
const casLoginUrl = new URL(`${casUrl}/login`);
casLoginUrl.search = new URLSearchParams({
redirectOrcid: 'true',
service: `${webUrl}/login`,
next: encodeURIComponent(finalDestination.toString()),
}).toString();
this.authService.logout(casLoginUrl.toString());
}
}