added user api

This commit is contained in:
2021-08-17 20:28:03 +05:30
parent 5c70a5c39c
commit 6e5c8ea47b
10 changed files with 100 additions and 74 deletions

View File

@ -3,83 +3,109 @@ import axios from 'axios';
//import Cookies from 'js-cookie';
import Cookies from 'universal-cookie';
import {
Redirect,
Route,
Switch
Redirect,
Route,
Switch
} from 'react-router-dom'
import { CContainer, CFade } from '@coreui/react'
// routes config
import routes from '../routes'
const loading = (
<div className="pt-3 text-center">
<div className="sk-spinner sk-spinner-pulse"></div>
</div>
const loading = ( <
div className = "pt-3 text-center" >
<div className = "sk-spinner sk-spinner-pulse" > </div>
</div>
)
const TheContent = () => {
const [SsoSession, setSsoSession] = useState('');
const [SsoSession, setSsoSession] = useState('');
const [UserData, setUserData] = useState('');
async function fetchSession() {
// You can await here
const result = await axios('https://fsbsso.sumasen.net/Shibboleth.sso/Session');
setSsoSession(result.data);
}
async function fetchSession() {
function get_token_from_storage_or_cookie() {
const cookies = new Cookies();
const shib = cookies.get('_shibsession_64656661756c7468747470733a2f2f66736273736f2e73756d6173656e2e6e65742f73686962626f6c657468')
if(shib !== undefined) {
fetchSession().then(() => {
if(SsoSession.includes('Session Expiration')){
return true;
// You can await here
const result = await axios('https://fsbsso.sumasen.net/Shibboleth.sso/Session');
setSsoSession(result.data);
}
async function fetchUser() {
const user_email = JSON.parse(SsoSession);
const company_code = "FBS";
const key = "api"
const pwd = "c558a56c63c44f65956adde8863ecc3558f3e55a465d4338bb2e7d2692866fd8";
// You can await here
const result = await axios.get('https://api.ts.bizside.biz/api/v7/' + company_code + '/users?email=' + user_email, {
auth: {
username: key,
password: pwd
}
});
setUserData(result);
}
else{
return null;
function get_token_from_storage_or_cookie() {
localStorage.setItem('state', 'off');
// const data = '{ "expiration": 479, "client_address": "123.231.121.140", "protocol": "urn:oasis:names:tc:SAML:2.0:protocol", "identity_provider": "https://sso.ts.bizside.biz/idp/shibboleth", "authn_instant": "2021-08-16T11:29:41.254Z", "authncontext_class": "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport", "attributes": [ { "name": "mail", "values": [ "akira.miyata@mobilous.com" ] } ] }'
// const jdata = JSON.parse(data);
// const user_email = jdata.attributes[0].values[0]
// //console.log(jdata.attributes[0].values[0]);
//return true;
const cookies = new Cookies();
const shib = cookies.get('_shibsession_64656661756c7468747470733a2f2f66736273736f2e73756d6173656e2e6e65742f73686962626f6c657468')
if (shib !== undefined) {
fetchSession().then(() => {
if (SsoSession.includes('Session Expiration')) {
fetchUser().then(() => {
console.log(UserData);
});
return true;
}
});
} else {
return null;
}
}
}
return (
<main className="c-main">
<CContainer fluid>
<Suspense fallback={loading}>
<Switch>
{routes.map((route, idx) => {
return route.component && (
<Route
key={idx}
path={route.path}
exact={route.exact}
name={route.name}
render={props =>
get_token_from_storage_or_cookie() !== null
? (
<route.component {...props} />
) : (
<Redirect to={{ pathname: "/sso" }} />
)
}
// render={props => (
// <CFade>
// <route.component {...props} />
// </CFade>
// )}
/>
)
})}
<Redirect from="/" to="/dashboard" />
</Switch>
</Suspense>
</CContainer>
</main>
)
return (
<main className = "c-main">
<CContainer fluid >
<Suspense fallback = { loading }>
<Switch > {
routes.map((route, idx) => {
return route.component && (
<Route key = { idx }
path = { route.path }
exact = { route.exact }
name = { route.name }
render = {
props =>
get_token_from_storage_or_cookie() !== null ?
( <route.component {...props }/>
) : ( <Redirect to = {
{ pathname: "/sso" }
}
/>
)
}
/>
)
})
}
<Redirect
from = "/"
to = "/dashboard" / >
</Switch> </Suspense >
</CContainer> </main >
)
}
export default React.memo(TheContent)