2016-01-02 22:24:07 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { Route, IndexRoute } from 'react-router';
|
|
|
|
|
2016-01-03 23:18:42 +02:00
|
|
|
import RootPage from 'pages/root/RootPage';
|
|
|
|
import IndexPage from 'pages/index/IndexPage';
|
2016-01-16 14:06:22 +02:00
|
|
|
import AuthPage from 'pages/auth/AuthPage';
|
|
|
|
|
2016-03-01 22:36:14 +02:00
|
|
|
import { authenticate } from 'components/user/actions';
|
2016-02-26 08:25:47 +02:00
|
|
|
|
2016-02-23 07:57:16 +02:00
|
|
|
import OAuthInit from 'components/auth/OAuthInit';
|
2016-03-13 10:50:09 +02:00
|
|
|
import Register from 'components/auth/register/Register';
|
|
|
|
import Login from 'components/auth/login/Login';
|
|
|
|
import Permissions from 'components/auth/permissions/Permissions';
|
|
|
|
import Activation from 'components/auth/activation/Activation';
|
|
|
|
import Password from 'components/auth/password/Password';
|
2016-02-13 17:28:47 +02:00
|
|
|
import Logout from 'components/auth/Logout';
|
2016-03-16 07:34:18 +02:00
|
|
|
import ChangePassword from 'components/auth/changePassword/ChangePassword';
|
2016-03-13 10:50:09 +02:00
|
|
|
import ForgotPassword from 'components/auth/forgotPassword/ForgotPassword';
|
2016-03-15 08:36:13 +02:00
|
|
|
import Finish from 'components/auth/finish/Finish';
|
2016-01-02 22:24:07 +02:00
|
|
|
|
2016-03-01 22:36:14 +02:00
|
|
|
import authFlow from 'services/authFlow';
|
2016-01-18 07:28:43 +02:00
|
|
|
|
2016-03-01 22:36:14 +02:00
|
|
|
export default function routesFactory(store) {
|
2016-02-26 08:25:47 +02:00
|
|
|
const state = store.getState();
|
|
|
|
if (state.user.token) {
|
|
|
|
// authorizing user if it is possible
|
2016-02-26 20:13:41 +02:00
|
|
|
store.dispatch(authenticate(state.user.token));
|
2016-02-26 08:25:47 +02:00
|
|
|
}
|
|
|
|
|
2016-03-01 22:36:14 +02:00
|
|
|
authFlow.setStore(store);
|
|
|
|
|
|
|
|
const onEnter = {
|
|
|
|
onEnter: ({location}, replace) => authFlow.handleRequest(location.pathname, replace)
|
|
|
|
};
|
|
|
|
|
2016-02-13 17:28:47 +02:00
|
|
|
return (
|
|
|
|
<Route path="/" component={RootPage}>
|
2016-03-13 11:02:24 +02:00
|
|
|
<IndexRoute component={IndexPage} {...onEnter} />
|
2016-03-01 22:36:14 +02:00
|
|
|
|
|
|
|
<Route path="oauth" component={OAuthInit} {...onEnter} />
|
|
|
|
<Route path="logout" component={Logout} {...onEnter} />
|
2016-02-13 17:28:47 +02:00
|
|
|
|
|
|
|
<Route path="auth" component={AuthPage}>
|
2016-03-01 22:36:14 +02:00
|
|
|
<Route path="/login" components={new Login()} {...onEnter} />
|
|
|
|
<Route path="/password" components={new Password()} {...onEnter} />
|
|
|
|
<Route path="/register" components={new Register()} {...onEnter} />
|
|
|
|
<Route path="/activation" components={new Activation()} {...onEnter} />
|
|
|
|
<Route path="/oauth/permissions" components={new Permissions()} {...onEnter} />
|
2016-03-15 08:36:13 +02:00
|
|
|
<Route path="/oauth/finish" component={Finish} {...onEnter} />
|
2016-03-16 07:34:18 +02:00
|
|
|
<Route path="/change-password" components={new ChangePassword()} {...onEnter} />
|
2016-03-01 22:36:14 +02:00
|
|
|
<Route path="/forgot-password" components={new ForgotPassword()} {...onEnter} />
|
2016-02-13 17:28:47 +02:00
|
|
|
</Route>
|
|
|
|
</Route>
|
|
|
|
);
|
|
|
|
}
|