diff --git a/src/App.js b/src/App.js index 3a5eb07c..45daee7b 100644 --- a/src/App.js +++ b/src/App.js @@ -21,6 +21,7 @@ import Faq from './components/Faq'; import FindCurator from './components/FindCurator'; import AuthContainerDefault from './components/AuthContainerDefault'; import EmploymentSystem from './components/EmploymentSystem'; +import KpiId from './components/KPIID'; const InternalLogin = () => { return ( @@ -68,6 +69,7 @@ class App extends Component { + { return await getCurrentUser(); }; +/** + * Exchange KPI ID ticket for sessionId and token + * @param {string} ticketId + * @returns {Promise} + */ +export const exchangeKpiIdTicket = async (ticketId) => { + if (!ticketId) { + console.warn('Ticket ID is required'); + return null; + } + + const response = await fetch(`${ApplicationConfiguration.ApiEndpoint}auth/kpi-id?ticketId=${encodeURIComponent(ticketId)}`, { + method: 'GET', + cache: 'no-cache', + headers: { + 'Accept': 'application/json', + }, + }); + + if (response.status !== 200) { + + console.warn(`Failed to exchange ticketId: ${ticketId}`); + + return null; + } + + const credentialsCollection = await response.json(); + + if (!credentialsCollection || credentialsCollection.length === 0) { + return null; + } + + // Assuming the first user in the response should be used + const credentials = credentialsCollection[0]; + + await storeCredentials(credentials.sessionId, credentials.access_token); + + return await getCurrentUser(); +}; + /** * Logout from Campus API * @returns {Promise} @@ -256,13 +296,7 @@ const toUrlEncode = (obj) => { * @returns {Promise} */ export const getBulletinBoardForCurrentUser = async (page, size) => { - const response = await callApi(`Board/All?page=${page}&size=${size}`, 'GET'); - - if (response.status < 200 || response.status >= 300) { - return null; - } - - return await response.json(); + return null; }; /** diff --git a/src/components/Bb/BbList.js b/src/components/Bb/BbList.js index 22b7ebc9..cb96c2c3 100644 --- a/src/components/Bb/BbList.js +++ b/src/components/Bb/BbList.js @@ -22,6 +22,7 @@ class BbList extends React.Component { 1, this.state.pageSize, ); + if (!!response) { this.setState({ items: response.data, diff --git a/src/components/Faq.js b/src/components/Faq.js index a00667fa..67156899 100644 --- a/src/components/Faq.js +++ b/src/components/Faq.js @@ -1,5 +1,4 @@ import React, { Component } from 'react'; -// import { Link } from 'react-router-dom'; class Faq extends Component { render() { diff --git a/src/components/KPIID.js b/src/components/KPIID.js new file mode 100644 index 00000000..feff171b --- /dev/null +++ b/src/components/KPIID.js @@ -0,0 +1,60 @@ +import React from 'react'; +import { Redirect } from 'react-router-dom'; +import * as campus from '../CampusClient'; + +class KpiId extends React.Component { + state = { + modal: false, + redirect: null + }; + + constructor(props) { + super(props); + } + + componentDidMount = async () => { + try { + const params = new URLSearchParams(this.props.location.search); + const ticketId = params.get('ticketId'); + + if (!ticketId) { + this.setState({ error: 'Ticket ID is missing' }); + return; + } + + const currentUser = await campus.exchangeKpiIdTicket(ticketId); + + if (!!currentUser) { + this.setState({ redirect: '/home' }); + } else { + this.setState({ error: 'Failed to authenticate using KPI ID' }); + } + } catch (error) { + console.error('Error during KPI ID authentication:', error); + this.setState({ error: 'An unexpected error occurred' }); + } + }; + + render() { + if (!!this.state.redirect) { + return ; + } + + return ( +
+
+
+

KPI ID

+ {this.state.error ? ( +
{this.state.error}
+ ) : ( +

Authorizing...

+ )} +
+
+
+ ); + } +} + +export default KpiId; \ No newline at end of file diff --git a/src/components/Login.js b/src/components/Login.js index 6a898153..cfce367c 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -10,70 +10,76 @@ class Login extends React.Component { }; componentDidMount = async () => { - let currentUser = await campus.getCurrentUser(true); + try { + const currentUser = await campus.getCurrentUser(true); - if (!!currentUser) { - this.setState({redirect: '/home'}); + if (!!currentUser) { + this.setState({ redirect: '/home' }); + } else { + this.setState({ error: 'Failed to authenticate using KPI ID' }); + } + } catch (error) { + console.error('Error during KPI ID authentication:', error); + this.setState({ error: 'An unexpected error occurred' }); } }; render() { - if (!!this.state.redirect) { return ; } return (
-
-
-
+
+
+

-
-
-
- +
+
+
+ {' '} Електроний кампус{' '} -

Авторизацiя у системi

-
{this.props.children}
+

Авторизацiя у системi

+
{this.props.children}
-
+
{!this.props.isExternal ? <> -
-
-
-
-
-
-
-
-
- -