mirror of
https://github.com/UniversityOfHelsinkiCS/ohtuilmo.git
synced 2026-10-12 19:03:41 +03:00
Added admin check to admin page
This commit is contained in:
+2
-1
@@ -75,7 +75,8 @@ class App extends Component {
|
||||
<Switch>
|
||||
<Route path={process.env.PUBLIC_URL + '/login'} render={() => (
|
||||
this.props.user ?
|
||||
<Redirect to={process.env.PUBLIC_URL + '/register'} /> :
|
||||
(this.props.user.admin? <Redirect to={process.env.PUBLIC_URL + '/administration'} /> : <Redirect to={process.env.PUBLIC_URL + '/register'} />)
|
||||
:
|
||||
<LoginPage />
|
||||
)} />
|
||||
<Route exact path={process.env.PUBLIC_URL + '/'} render={() => <Redirect to={process.env.PUBLIC_URL + '/login'} />} />
|
||||
|
||||
@@ -3,6 +3,25 @@ import { connect } from 'react-redux'
|
||||
import './TopicFormPage.css'
|
||||
|
||||
class AdminPage extends React.Component {
|
||||
componentWillMount() {
|
||||
try {
|
||||
if (window.localStorage.getItem('loggedInUser') === null) {
|
||||
window.location.replace(process.env.PUBLIC_URL + '/')
|
||||
} else {
|
||||
const token = JSON.parse(window.localStorage.getItem('loggedInUser'))
|
||||
if (!token.user.admin || token === undefined || token === null) {
|
||||
window.location.replace(process.env.PUBLIC_URL + '/')
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('error happened', e.response)
|
||||
this.props.setError('Some error happened')
|
||||
setTimeout(() => {
|
||||
this.props.clearNotifications()
|
||||
}, 3000)
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="admin-page-container">
|
||||
|
||||
Reference in New Issue
Block a user