mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-16 18:57:47 -05:00
closer to working
This commit is contained in:
@@ -1,15 +1,39 @@
|
||||
import React, { Component } from "react"
|
||||
import NavigationContainer from "./NavigationContainer"
|
||||
import React, { Component } from "react"
|
||||
import Navigation from "./Navigation"
|
||||
import { Routes, Route } from 'react-router-dom';
|
||||
|
||||
class App extends Component {
|
||||
render() {
|
||||
return(
|
||||
import Restricted from "./Restricted"
|
||||
|
||||
import Login from "../User/Login"
|
||||
import Register from "../User/Register"
|
||||
import Profile from "../User/Profile"
|
||||
import ConfirmEmail from "../User/ConfirmEmail"
|
||||
import WaitConfirmEmail from "../User/WaitConfirmEmail"
|
||||
import SentConfirmEmail from "../User/SentConfirmEmail"
|
||||
import SendResetPassword from "../User/SendResetPassword"
|
||||
import ResetPassword from "../User/ResetPassword"
|
||||
import Terms from "../User/Terms"
|
||||
|
||||
const App = (params) => {
|
||||
const {store} = params;
|
||||
return (
|
||||
<div>
|
||||
<NavigationContainer />
|
||||
{this.props.children}
|
||||
<Navigation/>
|
||||
<Routes>
|
||||
<Route exact path="/" element={ <Restricted><Profile/></Restricted>} />
|
||||
<Route path="/login" element={ <Login/>} />
|
||||
<Route path="/register" element={ <Register/> } />
|
||||
<Route path="/wait-confirm-email" element={ <WaitConfirmEmail/> } />
|
||||
<Route path="/sent-confirm-email" element={ <SentConfirmEmail/> } />
|
||||
<Route path="/send-reset-password" element={ <SendResetPassword/> } />
|
||||
<Route path="/reset-password/:userId/:token" element={ <ResetPassword/> } />
|
||||
<Route path="/confirm-email/:userId/:token" element={ <ConfirmEmail/> } />
|
||||
<Route path="/terms" element={ <Restricted><Terms/></Restricted>} />
|
||||
<Route path="/profile" element={ <Restricted><Profile/></Restricted>} />
|
||||
<Route render={() => (<div>Miss</div>)} />
|
||||
</Routes>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default App
|
||||
|
||||
@@ -1,53 +1,44 @@
|
||||
import React, { Component } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { Menu, Dropdown } from "semantic-ui-react";
|
||||
import React, { useEffect } from "react";
|
||||
import { useSelector, useDispatch } from 'react-redux'
|
||||
import { logoutUser } from "../features/user/userSlice";
|
||||
|
||||
const navStyle = {
|
||||
marginBottom: "30px"
|
||||
};
|
||||
const blankStyle = {
|
||||
marginBottom: "50px"
|
||||
};
|
||||
|
||||
class Navigation extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this._logout = this._logout.bind(this);
|
||||
}
|
||||
const Navigation = (props) => {
|
||||
const dispatch = useDispatch();
|
||||
const { email } = useSelector((state) => state.user);
|
||||
|
||||
_logout = event => {
|
||||
const logout = event => {
|
||||
event.preventDefault();
|
||||
this.props.manualLogout();
|
||||
dispatch(logoutUser({}));
|
||||
};
|
||||
|
||||
render() {
|
||||
var profileLink = process.env.REACT_APP_ACCOUNT_SERVER + "/profile";
|
||||
return (
|
||||
<div>
|
||||
{this.props.user.authenticated ? (
|
||||
<Menu style={navStyle}>
|
||||
<Menu.Item name="systems" header>
|
||||
{process.env.REACT_APP_SITE_NAME}
|
||||
</Menu.Item>
|
||||
<Menu.Menu position="right">
|
||||
{/* <Link to="/update-plans">
|
||||
<Menu.Item name="systems">Update Plans</Menu.Item>
|
||||
</Link> */}
|
||||
<Dropdown item text={this.props.user.email}>
|
||||
<Dropdown.Menu>
|
||||
<Dropdown.Item href={profileLink}>Profile</Dropdown.Item>
|
||||
{/* <Dropdown.Item href={billingLink}>Billing</Dropdown.Item> */}
|
||||
<Dropdown.Item onClick={this._logout}>Logout</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
</Menu.Menu>
|
||||
</Menu>
|
||||
) : (
|
||||
<Menu style={navStyle}>
|
||||
<Menu.Item name="systems" header>
|
||||
OpenMHz
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
var profileLink = process.env.REACT_APP_ACCOUNT_SERVER + "/profile";
|
||||
return (
|
||||
<div>
|
||||
<Menu style={navStyle}>
|
||||
<Menu.Item name="systems" header>
|
||||
{process.env.REACT_APP_SITE_NAME}
|
||||
</Menu.Item>
|
||||
<Menu.Menu position="right">
|
||||
<Dropdown item text={ email }>
|
||||
<Dropdown.Menu>
|
||||
<Dropdown.Item href={profileLink}>Profile</Dropdown.Item>
|
||||
<Dropdown.Item onClick={logout}>Logout</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
</Menu.Menu>
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export default Navigation;
|
||||
|
||||
@@ -1,55 +1,32 @@
|
||||
// in src/restricted.js
|
||||
import React, { Component } from 'react';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import * as types from "../User/user-constants";
|
||||
import axios from "axios";
|
||||
import React, { useEffect} from "react";
|
||||
import { useSelector, useDispatch } from 'react-redux'
|
||||
import { authenticateUser } from "../features/user/userSlice";
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
/**
|
||||
* Higher-order component (HOC) to wrap restricted pages
|
||||
*/
|
||||
const restricted = (BaseComponent, store) => {
|
||||
class Restricted extends Component {
|
||||
componentWillMount() {
|
||||
this.checkAuthentication(this.props);
|
||||
}
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.location !== this.props.location) {
|
||||
this.checkAuthentication(nextProps);
|
||||
}
|
||||
}
|
||||
|
||||
checkAuthentication(params) {
|
||||
const { history } = params;
|
||||
const authenticated = store.getState().user.authenticated;
|
||||
if (!authenticated) {
|
||||
axios
|
||||
.get("/authenticated")
|
||||
.then(response => {
|
||||
if (response.data.success) {
|
||||
const user = response.data.user
|
||||
store.dispatch({
|
||||
type: types.LOGIN_SUCCESS_USER,
|
||||
data: user
|
||||
});
|
||||
} else {
|
||||
history.replace({ pathname: '/login',
|
||||
state: { nextPathname: params.location.pathname } });
|
||||
}
|
||||
})
|
||||
.catch(response => {
|
||||
if (response instanceof Error) {
|
||||
// Something happened during logout that triggered an Error
|
||||
history.replace({ pathname: '/login',
|
||||
state: { nextPathname: params.location.pathname } });
|
||||
console.log("Error", response.message);
|
||||
}
|
||||
});
|
||||
const Restricted = ({children }) => {
|
||||
const { authenticated, hasAuthenticated } = useSelector((state) => state.user);
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(authenticateUser({}));
|
||||
},[]);
|
||||
|
||||
}
|
||||
}
|
||||
render() {
|
||||
return <BaseComponent {...this.props} />;
|
||||
}
|
||||
}
|
||||
return withRouter(Restricted);
|
||||
if (hasAuthenticated) {
|
||||
if (authenticated) {
|
||||
return children;;
|
||||
}
|
||||
else {
|
||||
|
||||
navigate("/list-systems")
|
||||
}
|
||||
}
|
||||
export default restricted
|
||||
return <div/>
|
||||
|
||||
};
|
||||
|
||||
export default Restricted
|
||||
Reference in New Issue
Block a user