Skip to content

Fix enter to submit, and dynamic entities not loading #106

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

Merged
merged 14 commits into from
May 22, 2025
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
1 change: 1 addition & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
AutoLogout: typeof import('./src/components/AutoLogout.vue')['default']
ChatMessage: typeof import('./src/components/ChatMessage.vue')['default']
ChatWidget: typeof import('./src/components/ChatWidget.vue')['default']
ChatWidgetOld: typeof import('./src/components/ChatWidgetOld.vue')['default']
Expand Down
110 changes: 0 additions & 110 deletions public/js/inactivity.js

This file was deleted.

13 changes: 10 additions & 3 deletions server/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,17 @@ export class UserController {
this.oauthInjectedService.requestTokenKey = undefined
this.oauthInjectedService.requestTokenSecret = undefined
session['clientConfig'] = undefined
if(!this.obpExplorerHome) {
console.error(`VITE_OBP_API_EXPLORER_HOST: ${this.obpExplorerHome}`)

if (request.query.redirect) {
response.redirect(request.query.redirect as string)
} else {
if(!this.obpExplorerHome) {
console.error(`VITE_OBP_API_EXPLORER_HOST: ${this.obpExplorerHome}`)
}
response.redirect(this.obpExplorerHome)
}
response.redirect(this.obpExplorerHome)


return response
}

Expand Down
20 changes: 18 additions & 2 deletions server/middlewares/OauthAccessTokenMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,31 @@ export default class OauthAccessTokenMiddleware implements ExpressMiddlewareInte
console.log(`OauthAccessTokenMiddleware.ts use says: clientConfig: ${JSON.stringify(clientConfig)}`)
session['clientConfig'] = clientConfig
console.log('OauthAccessTokenMiddleware.ts use says: Seems OK, redirecting..')

let redirectPage: String

const obpExplorerHome = process.env.VITE_OBP_API_EXPLORER_HOST
if(!obpExplorerHome) {
console.error(`VITE_OBP_API_EXPLORER_HOST: ${obpExplorerHome}`)
}
console.log(`OauthAccessTokenMiddleware.ts use says: Will redirect to: ${obpExplorerHome}`)

if (session['redirectPage']) {
try {
redirectPage = session['redirectPage']

} catch (e) {
console.log('OauthAccessTokenMiddleware.ts use says: Error decoding redirect URI')
redirectPage = obpExplorerHome
}
} else {
redirectPage = obpExplorerHome
}

console.log(`OauthAccessTokenMiddleware.ts use says: Will redirect to: ${redirectPage}`)
console.log('OauthAccessTokenMiddleware.ts use says: Here comes the session:')
console.log(session)

response.redirect(`${obpExplorerHome}`)
response.redirect(redirectPage)
}
}
)
Expand Down
7 changes: 7 additions & 0 deletions server/middlewares/OauthRequestTokenMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ export default class OauthRequestTokenMiddleware implements ExpressMiddlewareInt
console.debug('process.env.VITE_OBP_API_PORTAL_HOST:', process.env.VITE_OBP_API_PORTAL_HOST)
const oauthService = this.oauthInjectedService
const consumer = oauthService.getConsumer()
const redirectPage = request.query.redirect
const session = request.session

if (redirectPage) {
session['redirectPage'] = redirectPage
}

consumer.getOAuthRequestToken((error: any, oauthTokenKey: string, oauthTokenSecret: string) => {
if (error) {
const errorStr = JSON.stringify(error)
Expand Down
36 changes: 0 additions & 36 deletions src/assets/inactivity-timer.js

This file was deleted.

157 changes: 157 additions & 0 deletions src/components/AutoLogout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<script setup lang="ts">
import { ElNotification, NotificationHandle } from 'element-plus';
import { ref, computed, h, onMounted, onBeforeUnmount } from 'vue';

// Props can be defined with defineProps
const props = defineProps({
// Define your props here
});

// Types of events that will reset the timeout
const events = ['click', 'mousemove', 'keydown', 'keypress', 'mousedown', 'scroll', 'load'];

// Set timers
let warningTimeout: NodeJS.Timeout;
let logoutTimeout: NodeJS.Timeout;

let logoutTime: number;
let countdownInterval: NodeJS.Timeout;

// Add these variables at the top of your script
let defaultWarningDelay = 1000 * 270; // 4.5 minutes by default
let defaultLogoutDelay = 1000 * 300; // 5 minutes by default


// Methods
function setTimers(warningDelay = defaultWarningDelay, logoutDelay = defaultLogoutDelay) {
logoutTime = Date.now() + logoutDelay;

warningTimeout = setTimeout(warningMessage, warningDelay); // 4 seconds for development, change later
logoutTimeout = setTimeout(logout, logoutDelay); // 15 seconds for development, change later
}

let warningNotification: NotificationHandle;

async function getOBPSuggestedTimeout() {
const obpApiHost = import.meta.env.VITE_OBP_API_HOST;
let timeoutInSeconds: number;
// Fetch the suggested timeout from the OBP API

const response = await fetch(`${obpApiHost}/obp/v5.1.0/ui/suggested-session-timeout`);
const json = await response.json();
if(json.timeout_in_seconds) {
timeoutInSeconds = json.timeout_in_seconds;
console.log(`Suggested value ${timeoutInSeconds} is used`);
} else {
timeoutInSeconds = 5 * 60 + 1; // Set default value to 301 seconds
console.log(`Default value ${timeoutInSeconds} is used`);
}

return timeoutInSeconds;
}

function resetTimeout() {
// Logic to reset the timeout
clearTimeout(warningTimeout);
clearTimeout(logoutTimeout);
clearInterval(countdownInterval);


if (warningNotification) {
warningNotification.close();
}

setTimers();
}

function warningMessage() {
// Logic to show warning message
console.log('Warning: You will be logged out soon');

let secondsLeft = ref(Math.ceil((logoutTime - Date.now()) / 1000));
// Update the countdown every second
countdownInterval = setInterval(() => {
secondsLeft.value = Math.ceil((logoutTime - Date.now()) / 1000);

// If time's up or almost up, clear the interval
if (secondsLeft.value <= 0) {
clearInterval(countdownInterval);
return;
}


}, 1000);

warningNotification = ElNotification({
title: 'Inactivity Warning',
message: () => h('p', null, [
h('span', null, 'You will be logged out in'),
h('strong', { style: 'color: red' }, ` ${secondsLeft.value} `),
h('span', null, 'seconds.'),
])
,
type: 'warning',
duration: 0,
position: 'top-left',
showClose: false,
})
}

function logout() {
// Logic to log out the user
console.log('Logging out...');
document.getElementById("logoff")?.click(); // If the ID of the logout button changes, this will not work
}

// Lifecycle hooks
onMounted(() => {
events.forEach(event => {
window.addEventListener(event, resetTimeout);
})

setTimers();

// Update with API suggested values when available
getOBPSuggestedTimeout().then(timeoutInSeconds => {
// Convert to milliseconds
const logoutDelay = timeoutInSeconds * 1000;
// Set warning to appear 30 seconds before logout
const warningDelay = Math.max(logoutDelay - 30000, 0);

// Update the defaults
defaultWarningDelay = warningDelay;
defaultLogoutDelay = logoutDelay;

// Reset timers with new values
resetTimeout();
}).catch(error => {
console.error("Failed to get suggested timeout:", error);
// Continue with defaults
});
});

onBeforeUnmount(() => {
// Cleanup code before component is unmounted
clearTimeout(warningTimeout);
clearTimeout(logoutTimeout);
clearInterval(countdownInterval);
events.forEach(event => {
window.removeEventListener(event, resetTimeout);
});
});




</script>

<style scoped>
/* Your component styles here */
</style>


<template>
<div>
<!-- Your component content here -->
</div>
</template>
Loading