Update backend and frontend with middleware functionality

This commit is contained in:
Noe 2023-11-14 12:30:57 +01:00
parent dd19222728
commit 62b0efb67f
7 changed files with 46 additions and 59 deletions

View File

@ -18,9 +18,11 @@ public static class Program
public static void Main(String[] args)
{
//Db.CreateFakeRelations();
Watchdog.NotifyReady();
Db.Init();
var builder = WebApplication.CreateBuilder(args);
string vpnServerIp = "194.182.190.208";
//string vpnServerIp = "127.0.0.1";
WebsocketManager.Factory = new ConnectionFactory { HostName = vpnServerIp};

View File

@ -34,9 +34,10 @@ public class Session : Relation<String, Int64>
private static String CreateToken()
{
var token = new Byte[24];
Random.Shared.NextBytes(token);
return Convert.ToBase64String(token).Replace("/","");
//var token = new Byte[24];
//Random.Shared.NextBytes(token);
//return Convert.ToBase64String(token).Replace("/","");
return Guid.NewGuid().ToString("N");
}
}

View File

@ -190,7 +190,7 @@ public static class WebsocketManager
Console.WriteLine("Create new empty list for installation id " + installationId);
InstallationConnections[installationId] = new InstallationInfo
{
Status = -2
Status = -1
};
}

View File

@ -140,6 +140,7 @@ function App() {
locale={language}
defaultLocale="en"
>
<WebSocketContextProvider>
<CssBaseline />
<Routes>
<Route
@ -149,12 +150,10 @@ function App() {
<Route
path="/"
element={
<WebSocketContextProvider>
<SidebarLayout
language={language}
onSelectLanguage={setLanguage}
/>
</WebSocketContextProvider>
}
>
<Route
@ -173,6 +172,7 @@ function App() {
<Route path="ResetPassword" element={<ResetPassword />}></Route>
</Route>
</Routes>
</WebSocketContextProvider>
</IntlProvider>
</ThemeProvider>
);

View File

@ -17,7 +17,6 @@ interface installationSearchProps {
function InstallationSearch(props: installationSearchProps) {
const theme = useTheme();
const [searchTerm, setSearchTerm] = useState('');
const searchParams = new URLSearchParams(location.search);
const installationId = parseInt(searchParams.get('installation'));

View File

@ -9,6 +9,8 @@ import {
import axiosConfig from 'src/Resources/axiosConfig';
import { I_Folder, I_Installation } from 'src/interfaces/InstallationTypes';
import { TokenContext } from './tokenContext';
import routes from '../Resources/routes.json';
import { useNavigate } from 'react-router-dom';
interface I_InstallationContextProviderProps {
installations: I_Installation[];
@ -59,7 +61,7 @@ const InstallationsContextProvider = ({
const [loading, setLoading] = useState(false);
const [error, setError] = useState(false);
const [updated, setUpdated] = useState(false);
const navigate = useNavigate();
const tokencontext = useContext(TokenContext);
const { removeToken } = tokencontext;
@ -73,6 +75,7 @@ const InstallationsContextProvider = ({
.catch((err: AxiosError) => {
if (err.response && err.response.status == 401) {
removeToken();
navigate(routes.login);
}
});
}, []);
@ -86,6 +89,7 @@ const InstallationsContextProvider = ({
.catch((err) => {
if (err.response && err.response.status == 401) {
removeToken();
navigate(routes.login);
}
});
}, []);
@ -104,6 +108,7 @@ const InstallationsContextProvider = ({
setError(true);
if (error.response && error.response.status == 401) {
removeToken();
navigate(routes.login);
}
});
},
@ -134,6 +139,7 @@ const InstallationsContextProvider = ({
setError(true);
if (error.response && error.response.status == 401) {
removeToken();
navigate(routes.login);
}
});
},
@ -164,6 +170,7 @@ const InstallationsContextProvider = ({
setError(true);
if (error.response && error.response.status == 401) {
removeToken();
navigate(routes.login);
}
});
},
@ -183,6 +190,7 @@ const InstallationsContextProvider = ({
setError(true);
if (error.response && error.response.status == 401) {
removeToken();
navigate(routes.login);
}
});
}, []);
@ -206,6 +214,7 @@ const InstallationsContextProvider = ({
setError(true);
if (error.response && error.response.status == 401) {
removeToken();
navigate(routes.login);
}
});
}, []);
@ -229,6 +238,7 @@ const InstallationsContextProvider = ({
setError(true);
if (error.response && error.response.status == 401) {
removeToken();
navigate(routes.login);
}
});
}, []);

View File

@ -54,7 +54,7 @@ const WebSocketContextProvider = ({ children }: { children: ReactNode }) => {
const installation_id = message.id;
const status = message.status;
//console.log('Message from server ', installation_id, status);
console.log('Message from server ', installation_id, status);
setInstallationStatus((prevStatus) => {
// Create a new object by spreading the previous state
@ -89,34 +89,9 @@ const WebSocketContextProvider = ({ children }: { children: ReactNode }) => {
let status;
if (!installationStatus.hasOwnProperty(installationId)) {
status = -2;
} else {
let i = 0;
//If at least one status value shows an error, then show error
for (i; i < installationStatus[installationId].length; i++) {
if (installationStatus[installationId][i] === 2) {
status = 2;
return status;
}
if (installationStatus[installationId][i] === 1) {
status = 1;
return status;
}
}
if (installationStatus[installationId][0] == -1) {
let i = 0;
for (i; i < installationStatus[installationId].length; i++) {
if (installationStatus[installationId][i] != -1) {
break;
}
}
if (i === installationStatus[installationId].length) {
status = -1;
}
} else {
status = installationStatus[installationId][0];
}
}
return status;
};