Skip to content

Commit 04ed8ea

Browse files
authored
Merge pull request #106 from nemozak1/develop
Fix enter to submit, and dynamic entities not loading
2 parents 24fb09a + 5f71949 commit 04ed8ea

File tree

13 files changed

+271
-173
lines changed

13 files changed

+271
-173
lines changed

components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {}
77
/* prettier-ignore */
88
declare module 'vue' {
99
export interface GlobalComponents {
10+
AutoLogout: typeof import('./src/components/AutoLogout.vue')['default']
1011
ChatMessage: typeof import('./src/components/ChatMessage.vue')['default']
1112
ChatWidget: typeof import('./src/components/ChatWidget.vue')['default']
1213
ChatWidgetOld: typeof import('./src/components/ChatWidgetOld.vue')['default']

public/js/inactivity.js

Lines changed: 0 additions & 110 deletions
This file was deleted.

server/controllers/UserController.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ export class UserController {
4949
this.oauthInjectedService.requestTokenKey = undefined
5050
this.oauthInjectedService.requestTokenSecret = undefined
5151
session['clientConfig'] = undefined
52-
if(!this.obpExplorerHome) {
53-
console.error(`VITE_OBP_API_EXPLORER_HOST: ${this.obpExplorerHome}`)
52+
53+
if (request.query.redirect) {
54+
response.redirect(request.query.redirect as string)
55+
} else {
56+
if(!this.obpExplorerHome) {
57+
console.error(`VITE_OBP_API_EXPLORER_HOST: ${this.obpExplorerHome}`)
58+
}
59+
response.redirect(this.obpExplorerHome)
5460
}
55-
response.redirect(this.obpExplorerHome)
61+
62+
5663
return response
5764
}
5865

server/middlewares/OauthAccessTokenMiddleware.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,31 @@ export default class OauthAccessTokenMiddleware implements ExpressMiddlewareInte
6464
console.log(`OauthAccessTokenMiddleware.ts use says: clientConfig: ${JSON.stringify(clientConfig)}`)
6565
session['clientConfig'] = clientConfig
6666
console.log('OauthAccessTokenMiddleware.ts use says: Seems OK, redirecting..')
67+
68+
let redirectPage: String
69+
6770
const obpExplorerHome = process.env.VITE_OBP_API_EXPLORER_HOST
6871
if(!obpExplorerHome) {
6972
console.error(`VITE_OBP_API_EXPLORER_HOST: ${obpExplorerHome}`)
7073
}
71-
console.log(`OauthAccessTokenMiddleware.ts use says: Will redirect to: ${obpExplorerHome}`)
74+
75+
if (session['redirectPage']) {
76+
try {
77+
redirectPage = session['redirectPage']
78+
79+
} catch (e) {
80+
console.log('OauthAccessTokenMiddleware.ts use says: Error decoding redirect URI')
81+
redirectPage = obpExplorerHome
82+
}
83+
} else {
84+
redirectPage = obpExplorerHome
85+
}
86+
87+
console.log(`OauthAccessTokenMiddleware.ts use says: Will redirect to: ${redirectPage}`)
7288
console.log('OauthAccessTokenMiddleware.ts use says: Here comes the session:')
7389
console.log(session)
7490

75-
response.redirect(`${obpExplorerHome}`)
91+
response.redirect(redirectPage)
7692
}
7793
}
7894
)

server/middlewares/OauthRequestTokenMiddleware.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ export default class OauthRequestTokenMiddleware implements ExpressMiddlewareInt
3939
console.debug('process.env.VITE_OBP_API_PORTAL_HOST:', process.env.VITE_OBP_API_PORTAL_HOST)
4040
const oauthService = this.oauthInjectedService
4141
const consumer = oauthService.getConsumer()
42+
const redirectPage = request.query.redirect
43+
const session = request.session
44+
45+
if (redirectPage) {
46+
session['redirectPage'] = redirectPage
47+
}
48+
4249
consumer.getOAuthRequestToken((error: any, oauthTokenKey: string, oauthTokenSecret: string) => {
4350
if (error) {
4451
const errorStr = JSON.stringify(error)

src/assets/inactivity-timer.js

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/components/AutoLogout.vue

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
<script setup lang="ts">
2+
import { ElNotification, NotificationHandle } from 'element-plus';
3+
import { ref, computed, h, onMounted, onBeforeUnmount } from 'vue';
4+
5+
// Props can be defined with defineProps
6+
const props = defineProps({
7+
// Define your props here
8+
});
9+
10+
// Types of events that will reset the timeout
11+
const events = ['click', 'mousemove', 'keydown', 'keypress', 'mousedown', 'scroll', 'load'];
12+
13+
// Set timers
14+
let warningTimeout: NodeJS.Timeout;
15+
let logoutTimeout: NodeJS.Timeout;
16+
17+
let logoutTime: number;
18+
let countdownInterval: NodeJS.Timeout;
19+
20+
// Add these variables at the top of your script
21+
let defaultWarningDelay = 1000 * 270; // 4.5 minutes by default
22+
let defaultLogoutDelay = 1000 * 300; // 5 minutes by default
23+
24+
25+
// Methods
26+
function setTimers(warningDelay = defaultWarningDelay, logoutDelay = defaultLogoutDelay) {
27+
logoutTime = Date.now() + logoutDelay;
28+
29+
warningTimeout = setTimeout(warningMessage, warningDelay); // 4 seconds for development, change later
30+
logoutTimeout = setTimeout(logout, logoutDelay); // 15 seconds for development, change later
31+
}
32+
33+
let warningNotification: NotificationHandle;
34+
35+
async function getOBPSuggestedTimeout() {
36+
const obpApiHost = import.meta.env.VITE_OBP_API_HOST;
37+
let timeoutInSeconds: number;
38+
// Fetch the suggested timeout from the OBP API
39+
40+
const response = await fetch(`${obpApiHost}/obp/v5.1.0/ui/suggested-session-timeout`);
41+
const json = await response.json();
42+
if(json.timeout_in_seconds) {
43+
timeoutInSeconds = json.timeout_in_seconds;
44+
console.log(`Suggested value ${timeoutInSeconds} is used`);
45+
} else {
46+
timeoutInSeconds = 5 * 60 + 1; // Set default value to 301 seconds
47+
console.log(`Default value ${timeoutInSeconds} is used`);
48+
}
49+
50+
return timeoutInSeconds;
51+
}
52+
53+
function resetTimeout() {
54+
// Logic to reset the timeout
55+
clearTimeout(warningTimeout);
56+
clearTimeout(logoutTimeout);
57+
clearInterval(countdownInterval);
58+
59+
60+
if (warningNotification) {
61+
warningNotification.close();
62+
}
63+
64+
setTimers();
65+
}
66+
67+
function warningMessage() {
68+
// Logic to show warning message
69+
console.log('Warning: You will be logged out soon');
70+
71+
let secondsLeft = ref(Math.ceil((logoutTime - Date.now()) / 1000));
72+
// Update the countdown every second
73+
countdownInterval = setInterval(() => {
74+
secondsLeft.value = Math.ceil((logoutTime - Date.now()) / 1000);
75+
76+
// If time's up or almost up, clear the interval
77+
if (secondsLeft.value <= 0) {
78+
clearInterval(countdownInterval);
79+
return;
80+
}
81+
82+
83+
}, 1000);
84+
85+
warningNotification = ElNotification({
86+
title: 'Inactivity Warning',
87+
message: () => h('p', null, [
88+
h('span', null, 'You will be logged out in'),
89+
h('strong', { style: 'color: red' }, ` ${secondsLeft.value} `),
90+
h('span', null, 'seconds.'),
91+
])
92+
,
93+
type: 'warning',
94+
duration: 0,
95+
position: 'top-left',
96+
showClose: false,
97+
})
98+
}
99+
100+
function logout() {
101+
// Logic to log out the user
102+
console.log('Logging out...');
103+
document.getElementById("logoff")?.click(); // If the ID of the logout button changes, this will not work
104+
}
105+
106+
// Lifecycle hooks
107+
onMounted(() => {
108+
events.forEach(event => {
109+
window.addEventListener(event, resetTimeout);
110+
})
111+
112+
setTimers();
113+
114+
// Update with API suggested values when available
115+
getOBPSuggestedTimeout().then(timeoutInSeconds => {
116+
// Convert to milliseconds
117+
const logoutDelay = timeoutInSeconds * 1000;
118+
// Set warning to appear 30 seconds before logout
119+
const warningDelay = Math.max(logoutDelay - 30000, 0);
120+
121+
// Update the defaults
122+
defaultWarningDelay = warningDelay;
123+
defaultLogoutDelay = logoutDelay;
124+
125+
// Reset timers with new values
126+
resetTimeout();
127+
}).catch(error => {
128+
console.error("Failed to get suggested timeout:", error);
129+
// Continue with defaults
130+
});
131+
});
132+
133+
onBeforeUnmount(() => {
134+
// Cleanup code before component is unmounted
135+
clearTimeout(warningTimeout);
136+
clearTimeout(logoutTimeout);
137+
clearInterval(countdownInterval);
138+
events.forEach(event => {
139+
window.removeEventListener(event, resetTimeout);
140+
});
141+
});
142+
143+
144+
145+
146+
</script>
147+
148+
<style scoped>
149+
/* Your component styles here */
150+
</style>
151+
152+
153+
<template>
154+
<div>
155+
<!-- Your component content here -->
156+
</div>
157+
</template>

0 commit comments

Comments
 (0)