-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updating the versions and installing the basic packages we'll be using * Updated the versions * Configured eslint rules and applied to front-end files * Added Login check * Code cleanup. Should no longer pretend you're not logged in after refreshing on the browser * More code cleanup. Installed BC Sans font. Installed bootstrap
- Loading branch information
1 parent
782b70c
commit 48cecf7
Showing
21 changed files
with
393 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ build/ | |
package-lock.json | ||
.env | ||
.DS_Store | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/generated/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es6: true, | ||
}, | ||
extends: [ | ||
'plugin:react/recommended', | ||
'airbnb', | ||
], | ||
globals: { | ||
Atomics: 'readonly', | ||
SharedArrayBuffer: 'readonly', | ||
}, | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
ecmaVersion: 2018, | ||
sourceType: 'module', | ||
}, | ||
plugins: [ | ||
'react', | ||
'@typescript-eslint', | ||
], | ||
rules: { | ||
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], | ||
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }] | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react'; | ||
import CONFIG from './config'; | ||
|
||
const Login = () => { | ||
let url = `${CONFIG.KEYCLOAK.URL}/realms/${CONFIG.KEYCLOAK.REALM}`; | ||
url += '/protocol/openid-connect/auth?response_type=token'; | ||
url += `&client_id=${CONFIG.KEYCLOAK.CLIENT_ID}`; | ||
url += `&redirect_uri=${window.location.href}`; | ||
|
||
return ( | ||
<div id="login"> | ||
<div id="header"> | ||
<div id="header-wrapper" className="login-zeva-page-header-text">Zero Emission Vehicle Reporting System</div> | ||
</div> | ||
<div className="login-zeva-page"> | ||
<div className="login-zeva-brand" /> | ||
<div className="card-zeva"> | ||
<div className="buttons-section"> | ||
<div className="oidc"> | ||
<a href={`${url}&kc_idp_hint=bceid`} id="link-bceid" className="oidc"> | ||
<span className="text"> Login with </span> | ||
<span className="display-name"> BCeID </span> | ||
</a> | ||
</div> | ||
<div className="oidc"> | ||
<a href={`${url}&kc_idp_hint=idir`} id="link-idir" className="oidc"> | ||
<span className="text">Login with</span> | ||
<span className="display-name"> IDIR </span> | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Login; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,55 @@ | ||
import React, {Component} from 'react'; | ||
import {hot} from 'react-hot-loader/root'; | ||
import './css/App.scss'; | ||
import {withRouter} from "react-router"; | ||
import {withKeycloak} from "react-keycloak"; | ||
import React from 'react'; | ||
import { hot } from 'react-hot-loader/root'; | ||
import { withRouter } from 'react-router'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class PageLayout extends Component { | ||
const PageLayout = (props) => { | ||
const { children, keycloak } = props; | ||
|
||
render() { | ||
return ( | ||
<div> | ||
{this.props.keycloak.authenticated && <> | ||
<span>Authenticated</span> | ||
<strong>Authenticated</strong> | ||
Active Roles | ||
return ( | ||
<div> | ||
{keycloak.authenticated && ( | ||
<div> | ||
<strong>Authenticated</strong> | ||
<ul> | ||
{this.props.keycloak.realmAccess.roles.map(role => (<li>{role}</li>))} | ||
{keycloak.realmAccess.roles.map((role) => ( | ||
<li>{role}</li> | ||
))} | ||
</ul> | ||
</> | ||
} | ||
{this.props.keycloak.authenticated || <div> | ||
</div> | ||
)} | ||
{keycloak.authenticated || ( | ||
<div> | ||
<span>Not Authenticated</span> | ||
<button onClick={() => this.props.keycloak.login()}>Login</button> | ||
</div>} | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
} | ||
<button | ||
onClick={() => keycloak.login()} | ||
type="button" | ||
> | ||
Login | ||
</button> | ||
</div> | ||
)} | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
PageLayout.defaultProps = { | ||
children: [], | ||
}; | ||
|
||
export default hot(withRouter(withKeycloak(PageLayout))); | ||
PageLayout.propTypes = { | ||
children: PropTypes.oneOfType([ | ||
PropTypes.arrayOf(PropTypes.node), | ||
PropTypes.node, | ||
]), | ||
keycloak: PropTypes.shape({ | ||
authenticated: PropTypes.bool, | ||
login: PropTypes.func, | ||
realmAccess: PropTypes.shape({ | ||
roles: PropTypes.arrayOf(PropTypes.string), | ||
}), | ||
}).isRequired, | ||
}; | ||
|
||
export default hot(withRouter(PageLayout)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,49 @@ | ||
import React, { Component } from 'react'; | ||
import Keycloak from 'keycloak-js'; | ||
import {KeycloakProvider} from 'react-keycloak'; | ||
import Router from "./router"; | ||
import React from "react"; | ||
|
||
// Setup Keycloak instance as needed | ||
const keycloak = new Keycloak({ | ||
url: 'http://localhost:8888/auth', | ||
realm: 'zeva', | ||
clientId: 'zeva-app' | ||
|
||
import CONFIG from './config'; | ||
import Login from './Login'; | ||
import Router from './router'; | ||
|
||
class App extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
authenticated: false, | ||
keycloak: null, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
const keycloak = Keycloak({ | ||
clientId: CONFIG.KEYCLOAK.CLIENT_ID, | ||
realm: CONFIG.KEYCLOAK.REALM, | ||
url: CONFIG.KEYCLOAK.URL, | ||
}); | ||
|
||
keycloak.init({ onLoad: 'check-sso', checkLoginIframe: false, promiseType: 'native' }).then((authenticated) => { | ||
this.setState({ | ||
keycloak, | ||
authenticated, | ||
}); | ||
}); | ||
} | ||
); | ||
|
||
const App = () => ( | ||
<KeycloakProvider keycloak={keycloak} initConfig={{promiseType: 'native'}}> | ||
<Router/> | ||
</KeycloakProvider> | ||
); | ||
render() { | ||
const { authenticated, keycloak } = this.state; | ||
|
||
if (!keycloak) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
if (keycloak && !authenticated) { | ||
return <Login />; | ||
} | ||
|
||
return ( | ||
<Router keycloak={keycloak} /> | ||
); | ||
} | ||
} | ||
|
||
export default App; |
Oops, something went wrong.