From 7ed4e545833003261ca077270b60ecee55908600 Mon Sep 17 00:00:00 2001 From: Lucas Schoenfelder <les17@inf.ufpr.br> Date: Fri, 30 Oct 2020 11:01:18 -0300 Subject: [PATCH] added recent changes made in test_google_login --- src/App.js | 2 +- src/Components/Header.js | 32 ++++++++++++++++++++++++ src/Components/LoginContainerFunction.js | 18 +++++++------ 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/App.js b/src/App.js index fc192578..0ba68eb4 100644 --- a/src/App.js +++ b/src/App.js @@ -77,7 +77,7 @@ export default function App(){ },[window.innerWidth,window.innerHeight]) return( - <BrowserRouter> + <BrowserRouter basename="/react"> <Header /> <div style={{backgroundImage: "linear-gradient(to right,#ff7f00,#e81f4f,#673ab7,#00bcd4)", height:"5px"}}></div> <link href="https://fonts.googleapis.com/css?family=Kalam|Pompiere|Roboto&display=swap" rel="stylesheet"/> diff --git a/src/Components/Header.js b/src/Components/Header.js index 361645e4..354cdecc 100644 --- a/src/Components/Header.js +++ b/src/Components/Header.js @@ -43,6 +43,38 @@ export default function Header(props){ const [successfulLoginOpen, handleSuccessfulLogin] = useState(false) const [modalColaborar, setModalColaborar] = useState(false) + let loc = useLocation() + + useEffect(() => { + console.log(loc) + let query = new URLSearchParams(loc.search) + + //POR PARAMETRO + console.log(query.getAll("auth_token")) + if(query.get("auth_token") != undefined) { + let config = { + headers : { + "access-token" : query.get("auth_token"), + "client" : query.get("client_id"), + "uid" : query.get("uid"), + "expiry" : query.get("expiry"), + "token-type" : 'Bearer' + } + } + axios.get(`${apiUrl}/auth/validate_token/`, config).then( + (response) => { + console.log(response.data) + if ( response.headers['access-token'] ) { + sessionStorage.setItem('@portalmec/accessToken', response.headers['access-token']) + } + }, + (err) => { + console.log(err) + } + ) + } + }, [loc]) + const toggleSnackbar = (event, reason) => { if (reason === 'clickaway') { return; diff --git a/src/Components/LoginContainerFunction.js b/src/Components/LoginContainerFunction.js index 31aa61be..9f2aee36 100644 --- a/src/Components/LoginContainerFunction.js +++ b/src/Components/LoginContainerFunction.js @@ -27,6 +27,15 @@ import FormInput from "./FormInput.js" import GoogleLogo from "../img/logo_google.svg" import ValidateUserInput from '../Components/FormValidationFunction.js' import {Link} from 'react-router-dom' +import {apiUrl} from '../env'; + +async function handleGoogleAttempt () { + console.log("handleGoogleAttempt") + let request_url = ( + `${apiUrl}/v1/omniauth/google_oauth2?auth_origin_url=` + window.location.href + '&omniauth_window_type=sameWindow&resource_class=User' + ) + window.location.replace(request_url) +} export default function LoginContainer (props) { const [formEmail, setEmail] = useState( @@ -113,14 +122,7 @@ export default function LoginContainer (props) { <DialogContentDiv> <SocialConnectDiv> - {/*<StyledGoogleLoginButton - clientId="288460085642-k4veg4fo8kddvjer8b055n9da5qtgha7.apps.googleusercontent.com" - onSuccess={ } - onFailure={ } - cookiePolicy={'single_host_origin'} - > - <span style={{textTransform:"none", fontSize:"13px", color : "#666"}}>Usando o Google</span> - </StyledGoogleLoginButton>*/} + <Button onClick={handleGoogleAttempt}>login com google</Button> </SocialConnectDiv> <H3Div> -- GitLab