Skip to content

Commit

Permalink
Merge branch 'master' of github.com:UTSCC09/project-migos
Browse files Browse the repository at this point in the history
  • Loading branch information
MohanVashist1 committed Apr 12, 2020
2 parents a893671 + 367ce94 commit a48c5fe
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 34 deletions.
10 changes: 10 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ class CryptoRequest(BaseModel):
@app.middleware("http")
async def cookie_set(request: Request, call_next):
response = await call_next(request)
for idx, header in enumerate(response.raw_headers):
if header[0].decode("utf-8") == "set-cookie":
cookie = header[1].decode("utf-8")
cookie_arr = cookie.split('=')
if cookie_arr[0] == 'user_auth':
if cookie_arr[1].split(';')[0] == '""':
response.set_cookie("isLoggedIn", False, secure=True)
else:
response.set_cookie("isLoggedIn", True, secure=True)
break
for idx, header in enumerate(response.raw_headers):
if header[0].decode("utf-8") == "set-cookie":
cookie = header[1].decode("utf-8")
Expand Down
1 change: 1 addition & 0 deletions frontend/cryptoviz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"bootswatch": "^4.4.1",
"js-cookie": "^2.2.1",
"react": "^16.13.0",
"react-autosuggest": "^10.0.0",
"react-bootstrap": "^1.0.0",
Expand Down
17 changes: 13 additions & 4 deletions frontend/cryptoviz/src/js/components/AdvancedCharts.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import React from "react";
import Navbar from "./Navbar";
import { TVChartContainer } from "../../components/TVChartContainer/index";
import Loader from "react-loader-spinner";
import Cookie from 'js-cookie';

function AdvancedLandingPage({ match }) {
return (
<div>
<Navbar />
<TVChartContainer tickerId={match.params.ticker}></TVChartContainer>
</div>
<>
{(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true' && authState.isAuthenticated) ||
((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ?
<div>
<Navbar />
<TVChartContainer tickerId={match.params.ticker}></TVChartContainer>
</div> :
<div style={{ textAlign: "center", marginTop: "20em" }}>
<Loader type="ThreeDots" color="#2BAD60" />
</div>}
</>
);
}

Expand Down
12 changes: 4 additions & 8 deletions frontend/cryptoviz/src/js/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ import { useInterval } from "../common";
import { getCurrUser } from "../api";
import { reducer } from "../reducer";
import "../../style/App.css";
import Cookie from 'js-cookie';
import {
GET_USER_SUCCESS,
GET_USER_FAILURE,
ERROR_CLOSE,
APPLICATION_MOUNTED,
ERROR_CLOSE
} from "../constants/auth";
import AdvancedLandingPage from "./AdvancedCharts";
export const AuthContext = createContext();

const initialState = {
applicationMounted: false,
isAuthenticated: false,
user: {},
error: "",
Expand All @@ -34,17 +33,14 @@ function App() {

useEffect(() => {
getUserInfo();
dispatch({
type: APPLICATION_MOUNTED,
});
}, []);

useInterval(() => {
getUserInfo();
}, 500);
}, 1000);

const getUserInfo = () => {
if (!state.applicationMounted || state.isAuthenticated) {
if (Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true') {
getCurrUser()
.then((res) => {
dispatch({
Expand Down
4 changes: 3 additions & 1 deletion frontend/cryptoviz/src/js/components/Credits.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import "../../style/main.css";
import Navbar from "./Navbar";
import { AuthContext } from "./App";
import Loader from "react-loader-spinner";
import Cookie from 'js-cookie';

function Credits() {

const { state: authState } = useContext(AuthContext);

return (
<div>
{authState.applicationMounted && ((authState.isAuthenticated && Object.keys(authState.user).length > 0) || (!authState.isAuthenticated && Object.keys(authState.user).length === 0)) ?
{(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true' && authState.isAuthenticated) ||
((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ?
<div>
<Navbar />
<div className="container-fluid">
Expand Down
8 changes: 4 additions & 4 deletions frontend/cryptoviz/src/js/components/CryptoLanding.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useHistory } from "react-router-dom";
import Loader from "react-loader-spinner";
import { AuthContext } from "./App";
import { updateUser } from "../api";
import Cookie from 'js-cookie';
import { UPDATE_USER_SUCCESS, UPDATE_USER_FAILURE } from "../constants/auth";

const d = new Date();
Expand Down Expand Up @@ -143,7 +144,7 @@ function CryptoLanding({ match }) {
};

const displayWatchList = () => {
if (Object.keys(authState.user).length > 0) {
if (authState.isAuthenticated) {
if (
authState.user.watchlist.includes(
match.params.ticker.replace("USDT", "")
Expand Down Expand Up @@ -202,9 +203,8 @@ function CryptoLanding({ match }) {

return (
<div>
{authState.applicationMounted &&
((authState.isAuthenticated && Object.keys(authState.user).length > 0) ||
(!authState.isAuthenticated && Object.keys(authState.user).length === 0)) ? (
{(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true' && authState.isAuthenticated) ||
((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ? (
<div>
<Navbar />
<div style={{ textAlign: "center", marginTop: "4em" }}>
Expand Down
4 changes: 3 additions & 1 deletion frontend/cryptoviz/src/js/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import Table from './Table';
import Navbar from "./Navbar";
import { AuthContext } from "./App";
import Loader from "react-loader-spinner";
import Cookie from 'js-cookie';

function Home() {

const { state: authState } = useContext(AuthContext);

return (
<div>
{authState.applicationMounted && ((authState.isAuthenticated && Object.keys(authState.user).length > 0) || (!authState.isAuthenticated && Object.keys(authState.user).length === 0)) ?
{(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true' && authState.isAuthenticated) ||
((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ?
<div>
<Navbar />
<div>
Expand Down
4 changes: 3 additions & 1 deletion frontend/cryptoviz/src/js/components/InvalidPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import React, { useContext } from "react";
import Navbar from "./Navbar";
import { AuthContext } from "./App";
import Loader from "react-loader-spinner";
import Cookie from 'js-cookie';

function InvalidPage() {

const { state: authState } = useContext(AuthContext);

return (
<div>
{authState.applicationMounted && ((authState.isAuthenticated && Object.keys(authState.user).length > 0) || (!authState.isAuthenticated && Object.keys(authState.user).length === 0)) ?
{(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true' && authState.isAuthenticated) ||
((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ?
<div>
<Navbar />
<div style={{ textAlign: "center" }}>
Expand Down
5 changes: 3 additions & 2 deletions frontend/cryptoviz/src/js/components/SignIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Navbar from "./Navbar";
import { login } from '../api';
import { AuthContext } from "./App";
import Loader from "react-loader-spinner";
import Cookie from 'js-cookie';

function SignIn() {

Expand All @@ -24,7 +25,7 @@ function SignIn() {
}, 500);

const checkSignedIn = () => {
if(authState.applicationMounted && authState.isAuthenticated) {
if(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true') {
history.push('/');
}
};
Expand All @@ -49,7 +50,7 @@ function SignIn() {

return (
<div>
{authState.applicationMounted && !authState.isAuthenticated && Object.keys(authState.user).length === 0 ?
{((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ?
<div>
<Navbar />
<form style={{ width: "45%", margin: "auto", marginTop: "15vh" }} onSubmit={signIn}>
Expand Down
5 changes: 3 additions & 2 deletions frontend/cryptoviz/src/js/components/SignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { REGISTER_FAILURE, REGISTER_SUCCESS, LOGIN_SUCCESS, LOGIN_FAILURE } from
import Navbar from "./Navbar";
import { AuthContext } from "./App";
import { register, login } from '../api';
import Cookie from 'js-cookie';
import Loader from "react-loader-spinner";

function SignUp() {
Expand All @@ -26,7 +27,7 @@ function SignUp() {
}, 500);

const checkSignedIn = () => {
if(authState.applicationMounted && authState.isAuthenticated) {
if(Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true') {
history.push('/');
}
};
Expand Down Expand Up @@ -64,7 +65,7 @@ function SignUp() {

return (
<div>
{authState.applicationMounted && !authState.isAuthenticated && Object.keys(authState.user).length === 0 ?
{((!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') && !authState.isAuthenticated) ?
<div>
<Navbar />
<form style={{ width: "45%", margin: "4em auto" }} onSubmit={signUp}>
Expand Down
4 changes: 2 additions & 2 deletions frontend/cryptoviz/src/js/components/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function Table({ isGainer }) {
);
}
count += 6;
if (Object.keys(authState.user).length > 0) {
if (authState.isAuthenticated) {
if (authState.user.watchlist.includes(data[i].symbol)) {
cells.push(
<td key={count}>
Expand Down Expand Up @@ -235,7 +235,7 @@ function Table({ isGainer }) {
<th scope="col"><h5>Price</h5></th>
<th scope="col"><h5>Volume</h5></th>
<th scope="col"><h5>%</h5></th>
{Object.keys(authState.user).length > 0 && <th scope="col"><h5>Action</h5></th>}
{authState.isAuthenticated && <th scope="col"><h5>Action</h5></th>}
</tr>
</thead>
<tbody>{createTable(list)}</tbody>
Expand Down
5 changes: 3 additions & 2 deletions frontend/cryptoviz/src/js/components/Watchlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { updateUser } from '../api';
import { AuthContext } from "./App";
import Navbar from "./Navbar";
import Loader from "react-loader-spinner";
import Cookie from 'js-cookie';

function Watchlist() {

Expand All @@ -30,7 +31,7 @@ function Watchlist() {
}, 500);

const checkSignedIn = () => {
if(authState.applicationMounted && !authState.isAuthenticated) {
if(!Cookie.get('isLoggedIn') || Cookie.get('isLoggedIn').toLocaleLowerCase() === 'false') {
history.push('/');
}
};
Expand Down Expand Up @@ -124,7 +125,7 @@ function Watchlist() {

return (
<div>
{authState.applicationMounted && authState.isAuthenticated && Object.keys(authState.user).length > 0 ?
{Cookie.get('isLoggedIn') && Cookie.get('isLoggedIn').toLocaleLowerCase() === 'true' && authState.isAuthenticated ?
<div>
<Navbar />
<div style={{ textAlign: "center" }}>
Expand Down
1 change: 0 additions & 1 deletion frontend/cryptoviz/src/js/constants/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ export const LOGOUT_SUCCESS = "LOGOUT_SUCCESS";
export const LOGOUT_FAILURE = "LOGOUT_FAILURE";
export const UPDATE_USER_SUCCESS = "UPDATE_USER_SUCCESS";
export const UPDATE_USER_FAILURE = "UPDATE_USER_FAILURE";
export const APPLICATION_MOUNTED = "APPLICATION_MOUNTED";
export const ERROR_CLOSE = "ERROR_CLOSE";
7 changes: 1 addition & 6 deletions frontend/cryptoviz/src/js/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import * as authConstants from "./constants/auth";

export const reducer = (state, action) => {
switch (action.type) {
case authConstants.APPLICATION_MOUNTED:
return {
...state,
applicationMounted: true,
};
case authConstants.UPDATE_USER_FAILURE:
case authConstants.LOGOUT_FAILURE:
case authConstants.LOGIN_FAILURE:
Expand Down Expand Up @@ -37,7 +32,7 @@ export const reducer = (state, action) => {
case authConstants.LOGIN_SUCCESS:
return {
...state,
isAuthenticated: true,
// isAuthenticated: true,
error: "",
};
case authConstants.LOGOUT_SUCCESS:
Expand Down

0 comments on commit a48c5fe

Please sign in to comment.