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 3 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
21 changes: 21 additions & 0 deletions src/aai/aai.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
case 'local':
// DiscoJuice.UI.setScreen(opts.localauth);
// jQuery('input#login').focus();
var expires = new Date();
expires.setTime(expires.getTime() + 1 * 24 * 60 * 60 * 1000);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add docs

var cookieString = "dsRedirectUrl=" + getCookie('dsRedirectUrl') + ";expires=" + expires.toUTCString() + ";path=/";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is working without it, I will remove it, thank you

document.cookie = cookieString;

window.location = window.location.origin + (namespace === '' ? namespace : '/' + namespace) + "/login?redirectUrl=" + window.location.href;
break;
//case 'saml':
Expand All @@ -97,6 +102,22 @@
};
}

function getCookie(name) {
var cookies = document.cookie.split(';');

for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
// Check if this cookie has the specified name
if (cookie.startsWith(name + '=')) {
// Extract and return the cookie value
return cookie.substring(name.length + 1);
}
}

// Return null if the cookie with the specified name is not found
return null;
}

if (!window.aai) {
window.aai = new AAI();
}
Expand Down
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
30 changes: 19 additions & 11 deletions src/app/shared/log-in/methods/password/log-in-password.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { map } from 'rxjs/operators';
import {map} from 'rxjs/operators';
import { Component, Inject, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

Expand Down 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