2021-04-13 05:42:40 -07:00
|
|
|
import React, {useState, useContext} from 'react';
|
2021-04-05 03:41:07 -07:00
|
|
|
import { useHistory,BrowserRouter, Route, NavLink, Switch,withRouter } from 'react-router-dom';
|
2021-03-17 18:44:15 -07:00
|
|
|
import Register from './Register';
|
|
|
|
import Login from './Login';
|
|
|
|
import Footer from './Footer';
|
2021-03-28 11:24:21 -07:00
|
|
|
import styled, {css} from 'styled-components';
|
2021-04-05 03:41:07 -07:00
|
|
|
import {Button} from './miscellaneous/Styles';
|
|
|
|
import UserContext from "../context/UserContext";
|
|
|
|
import {logout} from "./NavBar"
|
2021-04-13 05:42:40 -07:00
|
|
|
import { GoogleLogin } from 'react-google-login';
|
|
|
|
import Axios from "axios";
|
2021-04-13 06:00:37 -07:00
|
|
|
import { Device} from './miscellaneous/Responsive';
|
2021-03-17 18:44:15 -07:00
|
|
|
|
2021-03-26 11:23:37 -07:00
|
|
|
const BaseApp = styled.div`
|
|
|
|
display: flex;
|
|
|
|
color: white;
|
|
|
|
height:100vh;
|
2021-04-13 06:00:37 -07:00
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
@media ${Device.laptop} {
|
|
|
|
flex-direction: row;
|
|
|
|
}
|
2021-03-26 11:23:37 -07:00
|
|
|
|
|
|
|
`;
|
|
|
|
|
2021-03-26 11:24:56 -07:00
|
|
|
const AppSide = styled.div`
|
|
|
|
background-color: #66bfbf;
|
2021-04-13 05:42:40 -07:00
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(auto-fit, 300px);
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
2021-04-13 06:00:37 -07:00
|
|
|
height: 100vh;
|
|
|
|
width: 100vw;
|
|
|
|
|
|
|
|
@media ${Device.laptop} {
|
|
|
|
width: 50%;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-11 21:53:48 -07:00
|
|
|
|
2021-03-27 11:22:22 -07:00
|
|
|
`;
|
|
|
|
const AppForm = styled.div`
|
|
|
|
|
|
|
|
background-color: #ffffff;
|
|
|
|
padding: 25px 40px;
|
2021-04-13 06:00:37 -07:00
|
|
|
height: 100vh;
|
|
|
|
width: 100vw;
|
|
|
|
|
|
|
|
@media ${Device.laptop} {
|
|
|
|
width: 50%;
|
|
|
|
overflow:auto
|
|
|
|
}
|
2021-03-27 11:22:22 -07:00
|
|
|
|
|
|
|
`;
|
2021-03-28 11:24:21 -07:00
|
|
|
const PageSwitcherContainer = styled.div`
|
2021-03-27 11:22:22 -07:00
|
|
|
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
margin-bottom: 10%;
|
|
|
|
|
|
|
|
`;
|
|
|
|
const BannerHeading = styled.h1`
|
|
|
|
|
|
|
|
position: relative;
|
|
|
|
text-align: center;
|
|
|
|
font-family: Ubuntu;
|
|
|
|
font-size: 5rem;
|
|
|
|
font-weight: bold;
|
|
|
|
color: #ffffff;
|
|
|
|
text-decoration: none;
|
|
|
|
text-transform: lowercase;
|
|
|
|
`;
|
|
|
|
const PlaneContainer = styled.div`
|
|
|
|
|
|
|
|
width:100px;
|
|
|
|
display:flex;
|
|
|
|
margin-bottom: 50px;
|
|
|
|
align-content: flex-start;
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
|
|
|
`;
|
|
|
|
const TextContainer = styled.p`
|
|
|
|
|
2021-03-26 11:23:37 -07:00
|
|
|
width: 50%;
|
|
|
|
background-color: #66bfbf;
|
|
|
|
display:flex;
|
|
|
|
flex-direction: column;
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
|
|
|
`;
|
|
|
|
|
2021-03-27 11:22:22 -07:00
|
|
|
const BannerText = styled.p`
|
2021-04-05 03:41:07 -07:00
|
|
|
|
|
|
|
color:${props => props.colour ? props.colour : "white"};
|
2021-03-27 11:22:22 -07:00
|
|
|
font-size: 1.25em;
|
|
|
|
font-style:italic;
|
|
|
|
|
|
|
|
|
|
|
|
`;
|
|
|
|
const SkyContainer = styled.div`
|
|
|
|
margin-top: 600px;
|
|
|
|
width: 100%;
|
|
|
|
background-size: 100%;
|
|
|
|
`;
|
|
|
|
const PageSwitcher = styled(NavLink)`
|
|
|
|
background-color: #4C5D72;
|
|
|
|
color: white;
|
|
|
|
padding: 10px 25px;
|
|
|
|
cursor: pointer;
|
|
|
|
font-size: .9em;
|
|
|
|
border: none;
|
|
|
|
outline: none;
|
|
|
|
display: inline-block;
|
2021-03-28 11:24:21 -07:00
|
|
|
text-decoration: none !important;
|
2021-03-27 11:22:22 -07:00
|
|
|
|
2021-03-28 11:24:21 -07:00
|
|
|
&.active{
|
2021-03-27 11:22:22 -07:00
|
|
|
background-color: #66bfbf;
|
|
|
|
color: white;
|
2021-03-28 11:24:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
&:first-child {
|
|
|
|
border-top-left-radius: 25px;
|
|
|
|
border-bottom-left-radius: 25px;
|
|
|
|
|
|
|
|
}
|
|
|
|
&:last-child {
|
|
|
|
border-top-right-radius: 25px;
|
|
|
|
border-bottom-right-radius: 25px;
|
|
|
|
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const FormLink = styled(NavLink)`
|
2021-03-27 11:22:22 -07:00
|
|
|
|
2021-03-28 11:24:21 -07:00
|
|
|
color: #707C8B;
|
|
|
|
text-decoration: none !important;
|
|
|
|
display: inline-block;
|
|
|
|
font-size: 1.7em;
|
|
|
|
margin: 0 10px;
|
|
|
|
padding-bottom: 5px;
|
|
|
|
border: none;
|
|
|
|
|
|
|
|
&:first-child {
|
|
|
|
margin-left: 0;
|
|
|
|
}
|
|
|
|
&:last-child{
|
|
|
|
color: #707c8b;
|
|
|
|
}
|
|
|
|
&.active{
|
|
|
|
border-bottom: 1px solid #199087;
|
|
|
|
}
|
2021-03-27 11:22:22 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-26 11:24:56 -07:00
|
|
|
`;
|
2021-03-17 18:44:15 -07:00
|
|
|
|
2021-03-28 11:24:21 -07:00
|
|
|
const FormTitle = styled.div`
|
|
|
|
color: #000000;
|
|
|
|
font-weight: 300;
|
|
|
|
margin-bottom: 50px;
|
|
|
|
|
|
|
|
`;
|
2021-04-13 05:42:40 -07:00
|
|
|
const responseSuccessGoogle = (response) => {
|
|
|
|
|
|
|
|
Axios({
|
|
|
|
method: 'POST',
|
|
|
|
url: "http://localhost:5000/users/googlelogin",
|
|
|
|
data: { idToken: response.tokenId }
|
|
|
|
}).then(response => {
|
|
|
|
console.log(response);
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
const responseFailGoogle = (response) => {
|
|
|
|
console.log(response)
|
|
|
|
|
|
|
|
}
|
2021-04-11 21:53:48 -07:00
|
|
|
const LogInContainer = () => {
|
2021-04-05 03:41:07 -07:00
|
|
|
const { userData, setUserData } = useContext(UserContext);
|
2021-04-13 05:42:40 -07:00
|
|
|
const [error, setError] = useState();
|
|
|
|
const [hasLogged, setHasLogged] = useState(false);
|
2021-04-05 03:41:07 -07:00
|
|
|
const history = useHistory();
|
2021-04-13 05:42:40 -07:00
|
|
|
const responsePassGoogle = async (response) => {
|
|
|
|
try{
|
|
|
|
const idToken = response.tokenId;
|
|
|
|
console.log("id token" + idToken);
|
|
|
|
const googleres = await Axios.post(
|
2021-04-15 09:25:00 -07:00
|
|
|
"https://server-locaft.herokuapp.com/users/googlelogin",{
|
2021-04-13 05:42:40 -07:00
|
|
|
idToken: idToken
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
setUserData({
|
|
|
|
token: googleres.data.token,
|
|
|
|
user: googleres.data.user
|
|
|
|
});
|
|
|
|
localStorage.setItem("auth-token",googleres.data.token);
|
|
|
|
setHasLogged(true);
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
err.response.data.msg && setError(err.response.data.msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2021-03-17 18:44:15 -07:00
|
|
|
return (
|
2021-03-28 11:24:21 -07:00
|
|
|
<BaseApp>
|
2021-04-15 09:17:31 -07:00
|
|
|
<meta name="google-signin-client_id" content={`${process.env.REACT_APP_CLIENT_ID}.apps.googleusercontent.com`} />
|
2021-03-28 11:24:21 -07:00
|
|
|
<AppSide>
|
2021-04-13 05:42:40 -07:00
|
|
|
{!hasLogged ? (
|
|
|
|
<GoogleLogin
|
|
|
|
clientId= {process.env.REACT_APP_CLIENT_ID}
|
|
|
|
buttonText="Login with Google"
|
|
|
|
onSuccess={responsePassGoogle}
|
|
|
|
onFailure={responseFailGoogle}
|
|
|
|
cookiePolicy={'single_host_origin'}
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
): (
|
|
|
|
<React.Fragment>
|
|
|
|
<p> username: {userData.user.username}</p>
|
|
|
|
<p> email: {userData.user.email}</p>
|
|
|
|
<p> pricing: {userData.user.pricing}</p>
|
|
|
|
</React.Fragment>
|
|
|
|
|
|
|
|
) }
|
2021-03-28 11:24:21 -07:00
|
|
|
</AppSide>
|
|
|
|
<AppForm>
|
2021-04-05 03:41:07 -07:00
|
|
|
{!userData.user ? (
|
|
|
|
<BrowserRouter basename="user">
|
2021-03-28 11:24:21 -07:00
|
|
|
<PageSwitcherContainer>
|
|
|
|
<PageSwitcher to="/login" >Sign In</PageSwitcher>
|
|
|
|
<PageSwitcher to="/register" >Sign Up</PageSwitcher>
|
|
|
|
</PageSwitcherContainer>
|
|
|
|
<FormTitle>
|
|
|
|
<FormLink to="/login" >Sign In</FormLink> or <FormLink to="/register">Sign Up</FormLink>
|
|
|
|
</FormTitle>
|
2021-03-17 18:44:15 -07:00
|
|
|
<Switch>
|
|
|
|
<Route path="/register" component={Register} />
|
|
|
|
<Route path="/login" component={Login} />
|
|
|
|
</Switch>
|
2021-04-05 03:41:07 -07:00
|
|
|
</BrowserRouter>
|
|
|
|
) : (
|
2021-03-17 18:44:15 -07:00
|
|
|
|
2021-04-05 03:41:07 -07:00
|
|
|
<React.Fragment>
|
|
|
|
<BannerText colour="black">Log in successful.</BannerText>
|
|
|
|
<Button
|
|
|
|
type="submit"
|
|
|
|
radiuscolor="#009578"
|
|
|
|
textcolor="#009578"
|
|
|
|
hovercolor="#009578"
|
|
|
|
hovertextcolor="white"
|
|
|
|
onClick={() => { history.push("/")}}
|
2021-04-11 21:53:48 -07:00
|
|
|
|
|
|
|
>home</Button>
|
2021-04-05 03:41:07 -07:00
|
|
|
|
|
|
|
<Button
|
|
|
|
type="submit"
|
|
|
|
radiuscolor="#009578"
|
|
|
|
textcolor="#009578"
|
|
|
|
hovercolor="#009578"
|
|
|
|
hovertextcolor="white"
|
|
|
|
onClick={() => {logout(setUserData); history.push("/")}}
|
2021-04-11 21:53:48 -07:00
|
|
|
|
|
|
|
>Logout</Button>
|
|
|
|
|
2021-04-05 03:41:07 -07:00
|
|
|
</React.Fragment>
|
|
|
|
|
2021-04-11 21:53:48 -07:00
|
|
|
|
2021-04-05 03:41:07 -07:00
|
|
|
)}
|
|
|
|
|
|
|
|
|
2021-04-11 21:53:48 -07:00
|
|
|
|
2021-03-17 18:44:15 -07:00
|
|
|
|
2021-03-28 11:24:21 -07:00
|
|
|
</AppForm>
|
2021-03-17 18:44:15 -07:00
|
|
|
|
2021-03-28 11:24:21 -07:00
|
|
|
</BaseApp>
|
2021-03-17 18:44:15 -07:00
|
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default withRouter(LogInContainer);
|
|
|
|
|