From eeca52d3ffe99cf77b6fc582c836691d7163a07a Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Tue, 27 Oct 2020 12:31:45 +0200 Subject: [PATCH] Prevent login requests to be sent multiple times from the oauth2 dialog --- .../src/app/ui/auth/login/login.component.ts | 43 ++++++++++++++++--- .../ui/dmp/overview/dmp-overview.component.ts | 6 ++- .../ui/user-profile/user-profile.component.ts | 6 ++- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/dmp-frontend/src/app/ui/auth/login/login.component.ts b/dmp-frontend/src/app/ui/auth/login/login.component.ts index 12b6c3e50..b535fe898 100644 --- a/dmp-frontend/src/app/ui/auth/login/login.component.ts +++ b/dmp-frontend/src/app/ui/auth/login/login.component.ts @@ -40,6 +40,7 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn private orcidUser: OrcidUser; private zenodoToken: ZenodoToken; private accessToken: string; + private oauthLock: boolean; //public cofigurableProviders: ConfigurableProvider[]; constructor( @@ -77,7 +78,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn this.oauth2DialogService.login(this.getLinkedInUrl()).pipe(takeUntil(this._destroyed)) .subscribe(result => { if (result !== undefined) { - this.linkedInLoginUser(result.oauthCode, result.oauthState); + if (!this.oauthLock) { + this.linkedInLoginUser(result.oauthCode, result.oauthState); + this.oauthLock = true; + } + } else { + this.oauthLock = false; } }); } @@ -89,7 +95,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn this.oauth2DialogService.login(url).pipe(takeUntil(this._destroyed)) .subscribe(result => { if (result !== undefined) { - this.twitterLoginUser(result.oauthToken, result.oauthVerifier); + if (!this.oauthLock) { + this.twitterLoginUser(result.oauthToken, result.oauthVerifier); + this.oauthLock = true; + } + } else { + this.oauthLock = false; } }); } @@ -102,7 +113,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn this.oauth2DialogService.login(this.getB2AccessUrl()).pipe(takeUntil(this._destroyed)) .subscribe(result => { if (result !== undefined) { - this.b2AccessLoginUser(result.oauthCode); + if (!this.oauthLock) { + this.b2AccessLoginUser(result.oauthCode); + this.oauthLock = true; + } + } else { + this.oauthLock = false; } }); } @@ -112,7 +128,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn this.oauth2DialogService.login(this.getORCIDUrl()).pipe(takeUntil(this._destroyed)) .subscribe(result => { if (result !== undefined) { - this.orcidLoginUser(result.oauthCode); + if (!this.oauthLock) { + this.orcidLoginUser(result.oauthCode); + this.oauthLock = true; + } + } else { + this.oauthLock = false; } }); } @@ -122,7 +143,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn this.oauth2DialogService.login(this.getOpenAireUrl()).pipe(takeUntil(this._destroyed)) .subscribe(result => { if (result !== undefined) { - this.openaireLoginUser(result.oauthCode, result.oauthState); + if (!this.oauthLock) { + this.openaireLoginUser(result.oauthCode, result.oauthState); + this.oauthLock = true; + } + } else { + this.oauthLock = false; } }); } @@ -136,7 +162,12 @@ export class LoginComponent extends BaseComponent implements OnInit, AfterViewIn this.oauth2DialogService.login(this.getZenodoUrl()).pipe(takeUntil(this._destroyed)) .subscribe(result => { if (result !== undefined) { - this.zenodoLoginUser(result.oauthCode); + if (!this.oauthLock) { + this.zenodoLoginUser(result.oauthCode); + this.oauthLock = true; + } + } else { + this.oauthLock = false; } }); } diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts index d73534e18..b52007e21 100644 --- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts +++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.ts @@ -68,6 +68,7 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { textMessage: any; versions: VersionListingModel[]; version: VersionListingModel; + private oauthLock: boolean; @ViewChild('doi', { static: false }) doi: ElementRef; @@ -528,14 +529,17 @@ export class DmpOverviewComponent extends BaseComponent implements OnInit { .pipe(takeUntil(this._destroyed)) .subscribe(result => { if (result !== undefined) { - if (result.oauthCode !== undefined && result.oauthCode !== null) { + if (result.oauthCode !== undefined && result.oauthCode !== null && !this.oauthLock) { this.userService.registerDOIToken(result.oauthCode, this.configurationService.app + 'oauth2') .pipe(takeUntil(this._destroyed)) .subscribe(() => { this.hasDOIToken = true; this.showConfirmationDOIDialog(dmp); }); + this.oauthLock = true; } + } else { + this.oauthLock = false; } }); } diff --git a/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts b/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts index f135f11e6..727bada0e 100644 --- a/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts +++ b/dmp-frontend/src/app/ui/user-profile/user-profile.component.ts @@ -49,6 +49,7 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes zenodoEmail: String; roleOrganizationEnum = RoleOrganizationType; authProviderEnum = AuthProvider; + private oauthLock: boolean; organisationsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = { filterFn: this.filterOrganisations.bind(this), @@ -238,11 +239,14 @@ export class UserProfileComponent extends BaseComponent implements OnInit, OnDes .pipe(takeUntil(this._destroyed)) .subscribe(result => { if (result !== undefined) { - if (result.oauthCode !== undefined && result.oauthCode !== null) { + if (result.oauthCode !== undefined && result.oauthCode !== null && !this.oauthLock) { this.userService.registerDOIToken(result.oauthCode, this.configurationService.app + 'oauth2') .pipe(takeUntil(this._destroyed)) .subscribe(() => this.router.navigate(['/reload']).then(() => this.router.navigate(['/profile']))); + this.oauthLock = true; } + } else { + this.oauthLock = false; } }); }