updated production pwd
This commit is contained in:
@ -1,38 +1,33 @@
|
|||||||
import React, { Suspense, useState, useEffect } from 'react'
|
import React, { Suspense, useState, useEffect } from "react";
|
||||||
import axios from 'axios';
|
import axios from "axios";
|
||||||
//import Cookies from 'js-cookie';
|
//import Cookies from 'js-cookie';
|
||||||
import Cookies from 'universal-cookie';
|
import Cookies from "universal-cookie";
|
||||||
import {
|
import { Redirect, Route, useLocation, Switch } from "react-router-dom";
|
||||||
Redirect,
|
import { CContainer, CFade } from "@coreui/react";
|
||||||
Route,
|
|
||||||
useLocation,
|
|
||||||
Switch
|
|
||||||
} from 'react-router-dom'
|
|
||||||
import { CContainer, CFade } from '@coreui/react'
|
|
||||||
|
|
||||||
// routes config
|
// routes config
|
||||||
import routes from '../routes'
|
import routes from "../routes";
|
||||||
import Sso from 'src/views/sso';
|
import Sso from "src/views/sso";
|
||||||
|
|
||||||
const loading = ( <
|
const loading = (
|
||||||
div className = "pt-3 text-center" >
|
<div className="pt-3 text-center">
|
||||||
<div className="sk-spinner sk-spinner-pulse"> </div>
|
<div className="sk-spinner sk-spinner-pulse"> </div>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
|
|
||||||
const TheContent = () => {
|
const TheContent = () => {
|
||||||
|
const [SsoSession, setSsoSession] = useState("");
|
||||||
const [SsoSession, setSsoSession] = useState('');
|
const [UserData, setUserData] = useState("");
|
||||||
const [UserData, setUserData] = useState('');
|
const [UserId, setUserId] = useState("");
|
||||||
const [UserId, setUserId] = useState('');
|
|
||||||
const [isDataFetched, setIsDataFetched] = useState(false);
|
const [isDataFetched, setIsDataFetched] = useState(false);
|
||||||
const [isPosted, setPosted] = useState(false);
|
const [isPosted, setPosted] = useState(false);
|
||||||
const [GotUserId, setGotUserId] = useState(false);
|
const [GotUserId, setGotUserId] = useState(false);
|
||||||
|
|
||||||
async function fetchSession() {
|
async function fetchSession() {
|
||||||
|
|
||||||
//setSsoSession('{ "expiration": 468, "client_address": "111.223.144.163", "protocol": "urn:oasis:names:tc:SAML:2.0:protocol", "identity_provider": "https://sso.ts.bizside.biz/idp/shibboleth", "authn_instant": "2021-09-03T08:26:41.248Z", "authncontext_class": "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport", "attributes": [ { "name": "mail", "values": [ "akira.miyata@mobilous.com" ] } ] }')
|
//setSsoSession('{ "expiration": 468, "client_address": "111.223.144.163", "protocol": "urn:oasis:names:tc:SAML:2.0:protocol", "identity_provider": "https://sso.ts.bizside.biz/idp/shibboleth", "authn_instant": "2021-09-03T08:26:41.248Z", "authncontext_class": "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport", "attributes": [ { "name": "mail", "values": [ "akira.miyata@mobilous.com" ] } ] }')
|
||||||
const result = await axios('https://fbssso.bizside.biz/Shibboleth.sso/Session');
|
const result = await axios(
|
||||||
|
"https://fbssso.bizside.biz/Shibboleth.sso/Session"
|
||||||
|
);
|
||||||
if (JSON.stringify(SsoSession) !== JSON.stringify(result.data)) {
|
if (JSON.stringify(SsoSession) !== JSON.stringify(result.data)) {
|
||||||
//console.log(result.data);
|
//console.log(result.data);
|
||||||
setSsoSession(result.data);
|
setSsoSession(result.data);
|
||||||
@ -40,22 +35,22 @@ const TheContent = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchSession()
|
fetchSession();
|
||||||
get_token_from_storage_or_cookie();
|
get_token_from_storage_or_cookie();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
async function postUserData(data) {
|
async function postUserData(data) {
|
||||||
|
|
||||||
setPosted(true);
|
setPosted(true);
|
||||||
|
|
||||||
let axiosConfig = {
|
let axiosConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json;charset=UTF-8',
|
"Content-Type": "application/json;charset=UTF-8",
|
||||||
"Access-Control-Allow-Origin": "*",
|
"Access-Control-Allow-Origin": "*",
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await axios.post('https://fbssso.bizside.biz/csv', data, axiosConfig)
|
const result = await axios
|
||||||
|
.post("https://fbssso.bizside.biz/csv", data, axiosConfig)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log("AXIOS ERROR: ", err);
|
console.log("AXIOS ERROR: ", err);
|
||||||
setPosted(false);
|
setPosted(false);
|
||||||
@ -63,7 +58,6 @@ const TheContent = () => {
|
|||||||
console.log("--- res ----", result);
|
console.log("--- res ----", result);
|
||||||
|
|
||||||
if (result === "OK") {
|
if (result === "OK") {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("res id ", result.data.id);
|
console.log("res id ", result.data.id);
|
||||||
if (data.jsessionid !== result.data.id) {
|
if (data.jsessionid !== result.data.id) {
|
||||||
@ -76,21 +70,27 @@ const TheContent = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function fetchUser() {
|
async function fetchUser() {
|
||||||
if(SsoSession.attributes == null || SsoSession.attributes[0] === undefined) {
|
if (
|
||||||
|
SsoSession.attributes == null ||
|
||||||
|
SsoSession.attributes[0] === undefined
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const user_email = SsoSession.attributes[0].values[0]
|
const user_email = SsoSession.attributes[0].values[0];
|
||||||
//console.log(user_email);
|
//console.log(user_email);
|
||||||
const company_code = "FBS";
|
const company_code = "FBS";
|
||||||
const key = "api"
|
const key = "api";
|
||||||
const pwd = "c558a56c63c44f65956adde8863ecc3558f3e55a465d4338bb2e7d2692866fd8";
|
const pwd =
|
||||||
|
"ae4d70740e7549bda4c118d66e845e450da1af7e918e440eaac16497a9f75292";
|
||||||
|
|
||||||
const result = await axios.get('https://fbssso.bizside.biz/users?email=' + user_email, {
|
const result = await axios
|
||||||
|
.get("https://fbssso.bizside.biz/users?email=" + user_email, {
|
||||||
auth: {
|
auth: {
|
||||||
username: key,
|
username: key,
|
||||||
password: pwd
|
password: pwd,
|
||||||
}
|
},
|
||||||
}).catch((err) => {
|
})
|
||||||
|
.catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@ -103,10 +103,9 @@ const TheContent = () => {
|
|||||||
|
|
||||||
function isCSVPath() {
|
function isCSVPath() {
|
||||||
const url = window.location.href;
|
const url = window.location.href;
|
||||||
if(url.includes('dashboard')) {
|
if (url.includes("dashboard")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,21 +113,22 @@ const TheContent = () => {
|
|||||||
function getCookie(name) {
|
function getCookie(name) {
|
||||||
const value = `; ${document.cookie}`;
|
const value = `; ${document.cookie}`;
|
||||||
const parts = value.split(`; ${name}=`);
|
const parts = value.split(`; ${name}=`);
|
||||||
if (parts.length === 2) return parts.pop().split(';').shift();
|
if (parts.length === 2) return parts.pop().split(";").shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_token_from_storage_or_cookie() {
|
function get_token_from_storage_or_cookie() {
|
||||||
//const cookies = new Cookies();
|
//const cookies = new Cookies();
|
||||||
//console.log(cookies.getAll());
|
//console.log(cookies.getAll());
|
||||||
const shib = getCookie('_shibsession_64656661756c7468747470733a2f2f66627373736f2e62697a736964652e62697a2f73686962626f6c657468')
|
const shib = getCookie(
|
||||||
|
"_shibsession_64656661756c7468747470733a2f2f66627373736f2e62697a736964652e62697a2f73686962626f6c657468"
|
||||||
|
);
|
||||||
console.log(shib);
|
console.log(shib);
|
||||||
if (shib !== undefined) {
|
if (shib !== undefined) {
|
||||||
fetchSession().then(() => {
|
fetchSession().then(() => {
|
||||||
if (SsoSession !== null) {
|
if (SsoSession !== null) {
|
||||||
fetchUser().then(() => {
|
fetchUser().then(() => {
|
||||||
if(UserId === ''){
|
if (UserId === "") {
|
||||||
let id = Math.floor(100000 + Math.random() * 900000)
|
let id = Math.floor(100000 + Math.random() * 900000);
|
||||||
setUserId(id);
|
setUserId(id);
|
||||||
}
|
}
|
||||||
setIsDataFetched(true);
|
setIsDataFetched(true);
|
||||||
@ -149,7 +149,6 @@ const TheContent = () => {
|
|||||||
}
|
}
|
||||||
]`;
|
]`;
|
||||||
|
|
||||||
|
|
||||||
//const json_str = '[{"jsessonid": "' + UserId + '" , "name": "' + _firstname + ' ' +_lastname+ '", "mailadress":" ' + _email + '", "empcode": "' + _empcode + '"}]';
|
//const json_str = '[{"jsessonid": "' + UserId + '" , "name": "' + _firstname + ' ' +_lastname+ '", "mailadress":" ' + _email + '", "empcode": "' + _empcode + '"}]';
|
||||||
if (_empcode !== null && _empcode !== undefined) {
|
if (_empcode !== null && _empcode !== undefined) {
|
||||||
if (isCSVPath()) {
|
if (isCSVPath()) {
|
||||||
@ -166,7 +165,6 @@ const TheContent = () => {
|
|||||||
setIsDataFetched(true);
|
setIsDataFetched(true);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -175,23 +173,29 @@ const TheContent = () => {
|
|||||||
<Suspense fallback={loading}>
|
<Suspense fallback={loading}>
|
||||||
<Switch>
|
<Switch>
|
||||||
{routes.map((route, idx) => {
|
{routes.map((route, idx) => {
|
||||||
return route.component && (
|
return (
|
||||||
|
route.component && (
|
||||||
<Route
|
<Route
|
||||||
key={idx}
|
key={idx}
|
||||||
path={route.path}
|
path={route.path}
|
||||||
exact={route.exact}
|
exact={route.exact}
|
||||||
name={route.name}
|
name={route.name}
|
||||||
render={(props) =>
|
render={(props) =>
|
||||||
isDataFetched ?
|
isDataFetched ? (
|
||||||
get_token_from_storage_or_cookie() !== null ? (
|
get_token_from_storage_or_cookie() !== null ? (
|
||||||
<route.component {...props} userid={UserId} email={UserData.email} gotuserid={GotUserId} />
|
<route.component
|
||||||
|
{...props}
|
||||||
|
userid={UserId}
|
||||||
|
email={UserData.email}
|
||||||
|
gotuserid={GotUserId}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Redirect to={{ pathname: "/sso" }} />
|
<Redirect to={{ pathname: "/sso" }} />
|
||||||
)
|
)
|
||||||
:
|
) : null
|
||||||
null
|
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
<Redirect from="/" to="/dashboard" />
|
<Redirect from="/" to="/dashboard" />
|
||||||
@ -200,6 +204,6 @@ const TheContent = () => {
|
|||||||
</CContainer>
|
</CContainer>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default React.memo(TheContent)
|
export default React.memo(TheContent);
|
||||||
|
|||||||
Reference in New Issue
Block a user