2016-01-03 01:54:07 +05:30
|
|
|
import React from 'react';
|
|
|
|
import { Route, IndexRoute } from 'react-router';
|
|
|
|
|
2016-01-04 02:48:42 +05:30
|
|
|
import RootPage from 'pages/root/RootPage';
|
|
|
|
import IndexPage from 'pages/index/IndexPage';
|
2016-01-16 17:36:22 +05:30
|
|
|
import AuthPage from 'pages/auth/AuthPage';
|
|
|
|
|
|
|
|
import Register from 'components/auth/Register';
|
|
|
|
import Login from 'components/auth/Login';
|
|
|
|
import Permissions from 'components/auth/Permissions';
|
|
|
|
import Activation from 'components/auth/Activation';
|
|
|
|
import Password from 'components/auth/Password';
|
2016-02-13 20:58:47 +05:30
|
|
|
import Logout from 'components/auth/Logout';
|
2016-02-26 04:12:20 +05:30
|
|
|
import PasswordChange from 'components/auth/PasswordChange';
|
2016-01-03 01:54:07 +05:30
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
export default function routesFactory(store) {
|
|
|
|
function checkAuth(nextState, replace) {
|
|
|
|
const state = store.getState();
|
|
|
|
|
|
|
|
let forcePath;
|
|
|
|
if (!state.user.isGuest) {
|
|
|
|
if (!state.user.isActive) {
|
|
|
|
forcePath = '/activation';
|
|
|
|
} else {
|
|
|
|
forcePath = '/oauth/permissions';
|
2016-01-18 10:58:43 +05:30
|
|
|
}
|
2016-02-13 20:58:47 +05:30
|
|
|
} else {
|
|
|
|
if (state.user.email || state.user.username) {
|
|
|
|
forcePath = '/password';
|
|
|
|
} else {
|
|
|
|
forcePath = '/login';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (forcePath && state.routing.location.pathname !== forcePath) {
|
|
|
|
replace({pathname: forcePath});
|
|
|
|
}
|
|
|
|
}
|
2016-01-18 10:58:43 +05:30
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
return (
|
|
|
|
<Route path="/" component={RootPage}>
|
|
|
|
<IndexRoute component={IndexPage} onEnter={checkAuth} />
|
|
|
|
|
|
|
|
<Route path="auth" component={AuthPage}>
|
|
|
|
<Route path="/login" components={new Login()} onEnter={checkAuth} />
|
|
|
|
<Route path="/password" components={new Password()} onEnter={checkAuth} />
|
|
|
|
<Route path="/register" components={new Register()} />
|
|
|
|
<Route path="/activation" components={new Activation()} />
|
|
|
|
<Route path="/oauth/permissions" components={new Permissions()} onEnter={checkAuth} />
|
|
|
|
<Route path="/oauth/:id" component={Permissions} />
|
2016-02-26 04:12:20 +05:30
|
|
|
<Route path="/password-change" components={new PasswordChange()} />
|
2016-02-13 20:58:47 +05:30
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path="logout" component={Logout} />
|
|
|
|
</Route>
|
|
|
|
);
|
|
|
|
}
|