-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from Canadian-Geospatial-Platform/rebase/feat…
…ure/login Rebase/feature/login
- Loading branch information
Showing
19 changed files
with
897 additions
and
562 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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,3 @@ | ||
.sign-in{ | ||
padding-top: 10rem; | ||
} |
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,15 @@ | ||
import './dispatchsignin.scss' | ||
import React, { useEffect } from "react"; | ||
import { requireLogin } from '../utils/authorization'; | ||
|
||
export default function DispatchSignIn(): JSX.Element { | ||
useEffect(() => { | ||
const fetchData = async () => { | ||
await requireLogin(window.location.origin + '/receivesignin', window.location.origin); | ||
} | ||
fetchData() | ||
}, [requireLogin]); | ||
|
||
|
||
return <h1 className="sign-in">Please wait while you are being redirected to the sign-in page.</h1>; | ||
} |
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,36 @@ | ||
.dropdown ul { | ||
right: 0; | ||
top: auto; | ||
position: absolute; | ||
margin-top: 0.5rem; | ||
border-style: solid; | ||
border-width: 0.1rem; | ||
box-shadow: 0.1rem 0.1rem; | ||
width: 10rem; | ||
background-color: white; | ||
padding: 0; | ||
} | ||
|
||
.dropdown ul li{ | ||
color: black; | ||
list-style-type: none; | ||
z-index: 1000; | ||
} | ||
|
||
#loginWidget .userIcon{ | ||
color: white; | ||
background-color: blue; | ||
border-radius: 100%; | ||
border-style: solid; | ||
border-width: 0.1rem; | ||
border-color: black; | ||
} | ||
|
||
#loginButton { | ||
background-color: blue; | ||
border-radius: 0.25rem; | ||
color: white; | ||
padding: 0.55em 1em; | ||
} | ||
|
||
.no-click {pointer-events: none;} |
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,41 @@ | ||
import './headerwidget.scss'; | ||
import React, { useEffect, useState } from "react"; | ||
import { getIdToken, requireLogin, logout } from '../utils/authorization'; | ||
import { parseJwt } from '../utils/parse-jwt'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export default function HeaderWidget(): JSX.Element { | ||
const { t } = useTranslation(); | ||
const fetchData = async () => { | ||
await requireLogin(window.location.origin + '/receivesignin', window.location.href); | ||
} | ||
|
||
const [loggedIn, set_loggedIn] = useState(false); | ||
const [showMenu, set_showMenu] = useState(false); | ||
const [loggedInMessage, set_loggedInMessage] = useState("Logged In!"); | ||
let loginButton; | ||
|
||
if (!loggedIn) { | ||
loginButton = <button id="loginButton" type="button" className="button button-primary" onClick={fetchData}>{t('nav.login')}</button> | ||
} else { | ||
loginButton = <div id="loginWidget" className="dropdown"><button className="userIcon" onClick={() => {set_showMenu(!showMenu)}} style={{ | ||
"padding": '0.55em 1em', | ||
}}>{loggedInMessage.charAt(0)}</button>{showMenu ? <ul><li><button className="no-click">{loggedInMessage}</button></li><li><button onClick={logout}>{t('nav.logout')}</button></li></ul> : ""}</div> | ||
} | ||
|
||
useEffect(() => { | ||
let token = getIdToken() | ||
if (token != null) { | ||
set_loggedIn(true) | ||
set_loggedInMessage(parseJwt(token).name) | ||
} | ||
}, [getIdToken()]); | ||
|
||
|
||
|
||
return (<div> | ||
{loginButton} | ||
</div>); | ||
} | ||
|
||
// mardi 4 juillet 16h15 |
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,3 @@ | ||
.receivesignin { | ||
padding-top: 10rem; | ||
} |
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,25 @@ | ||
import './receivesignin.scss' | ||
import React, { useEffect } from "react"; | ||
import { signIn } from '../utils/authorization'; | ||
export default function ReceiveSignIn(): JSX.Element { | ||
useEffect(() => { | ||
const params = new Proxy(new URLSearchParams(window.location.search), { | ||
get: (searchParams, prop: string) => searchParams.get(prop), | ||
}) as URLSearchParams & {state: string | null, code: string | null} ; | ||
let stateOrNull = params.state; | ||
let state = stateOrNull?stateOrNull:'/'; | ||
let code = params.code; | ||
const executeSignIn = async (code: string | null, state: string) => { | ||
if(code == null) | ||
{ | ||
console.error("code is null in receivesignin.") | ||
return; | ||
} | ||
await signIn(code, 'http://localhost:8080/receivesignin', state); | ||
} | ||
executeSignIn(code, state) | ||
|
||
}, []); | ||
|
||
return <h1 className="receivesignin">Signing in... Please wait while you are being redirected.</h1>; | ||
} |
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,27 @@ | ||
import './dispatch/dispatchsignin.scss' | ||
import React, { useEffect, useState } from "react"; | ||
import { getAccessToken, requireLogin } from './utils/authorization'; | ||
|
||
export default function SamplePageRequiringSignIn(): JSX.Element { | ||
const [token, set_token] = useState<null|string>(null); | ||
const onClickFunction = () => { | ||
let x = getAccessToken() | ||
console.log("on click function callled!", getAccessToken()) | ||
if (x) {set_token(x)} | ||
} | ||
useEffect(() => { | ||
const fetchData = async () => { | ||
await requireLogin(window.location.origin + '/receivesignin', window.location.href); | ||
} | ||
fetchData() | ||
}, [requireLogin]); | ||
|
||
let TokenHtml = <button onClick={onClickFunction}>Click here to display the authorization token.</button> | ||
|
||
if (token) {TokenHtml = <p>The athorization token is: {token}</p>} | ||
|
||
return <div> | ||
<h1 className="sign-in">Welcome to the test page. This page should require login on load. and redirect the user to the sign-in page.</h1> | ||
{TokenHtml} | ||
</div> | ||
} |
Oops, something went wrong.