Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ufal/fe-download-bitstream-back-to-item #423

Merged
merged 6 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ export class ClarinBitstreamDownloadPageComponent implements OnInit {
// bitstreamURL = 'http://localhost:8080/server/api/core/bitstreams/d9a41f84-a470-495a-8821-20e0a18e9276/content';
if ((isAuthorized || isAuthorizedByClarin) && isLoggedIn && isNotEmpty(fileLink)) {
this.downloadStatus.next(RequestEntryState.Success);
this.hardRedirectService.redirect(fileLink);
window.location.replace(fileLink);
} else if ((isAuthorized || isAuthorizedByClarin) && !isLoggedIn) {
this.downloadStatus.next(RequestEntryState.Success);
this.hardRedirectService.redirect(bitstreamURL);
window.location.replace(bitstreamURL);
} else if (!(isAuthorized || isAuthorizedByClarin) && isLoggedIn &&
this.downloadStatus.value === RequestEntryState.Error) {
// this.downloadStatus is `ERROR` - no CLARIN exception is thrown up
Expand Down
28 changes: 18 additions & 10 deletions src/app/shared/log-in/methods/password/log-in-password.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class LogInPasswordComponent implements OnInit {

// Load `dspace.ui.url` into `baseUrl` property.
await this.assignBaseUrl();
this.toggleDiscojuiceLogin();
void this.setUpRedirectUrl();
}

Expand All @@ -155,13 +156,14 @@ export class LogInPasswordComponent implements OnInit {
}

// Store the `redirectUrl` value from the url and then remove that value from url.
if (isNotEmpty(this.route.snapshot.queryParams?.redirectUrl)) {
// Overwrite `this.redirectUrl` only if it's not stored in the authService `redirectUrl` property.
if (isEmpty(this.redirectUrl)) {
this.redirectUrl = this.route.snapshot.queryParams?.redirectUrl;
}
} else {
// Pop up discojuice login e.g. when the token is expired or the user is trying to download restricted bitstream.
// Overwrite `this.redirectUrl` only if it's not stored in the authService `redirectUrl` property.
if (isEmpty(this.redirectUrl)) {
this.redirectUrl = this.route.snapshot.queryParams?.redirectUrl;
}
}

private toggleDiscojuiceLogin() {
if (isEmpty(this.route.snapshot.queryParams?.redirectUrl)) {
this.popUpDiscoJuiceLogin();
}
}
Expand Down Expand Up @@ -191,10 +193,16 @@ export class LogInPasswordComponent implements OnInit {
email.trim();
password.trim();

// Local authentication redirects to /login page and the user should be redirected to the page from where
// was the login initiated.
if (!this.isStandalonePage || isNotEmpty(this.redirectUrl)) {
this.authService.setRedirectUrl(this.redirectUrl.replace(this.baseUrl, ''));
// Create a URLSearchParams object
const urlParams = new URLSearchParams(this.redirectUrl.split('?')[1]);
// Get the value of the 'redirectUrl' parameter
let redirectUrl = urlParams.get('redirectUrl');
if (isEmpty(redirectUrl)) {
redirectUrl = this.redirectUrl;
}

this.authService.setRedirectUrl(redirectUrl.replace(this.baseUrl, ''));
} else {
this.authService.setRedirectUrlIfNotSet('/');
}
Expand Down
Loading