2016-01-02 22:24:07 +02:00
|
|
|
import React from 'react';
|
2016-06-04 12:17:06 +03:00
|
|
|
import { Route, IndexRoute } from 'react-router';
|
2016-01-02 22:24:07 +02:00
|
|
|
|
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-05-01 20:50:55 +03:00
|
|
|
|
2016-05-22 18:56:52 +03:00
|
|
|
import RulesPage from 'pages/rules/RulesPage';
|
2016-06-02 22:26:09 +03:00
|
|
|
import PageNotFound from 'pages/404/PageNotFound';
|
2016-05-22 18:56:52 +03:00
|
|
|
|
2016-04-17 12:35:04 +03:00
|
|
|
import ProfilePage from 'pages/profile/ProfilePage';
|
2016-05-01 20:50:55 +03:00
|
|
|
import ProfileChangePasswordPage from 'pages/profile/ChangePasswordPage';
|
2016-05-02 16:13:18 +03:00
|
|
|
import ProfileChangeUsernamePage from 'pages/profile/ChangeUsernamePage';
|
2016-05-22 17:56:39 +03:00
|
|
|
import ProfileChangeEmailPage from 'pages/profile/ChangeEmailPage';
|
2016-01-16 14:06:22 +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';
|
2016-05-22 21:58:43 +03:00
|
|
|
import ResendActivation from 'components/auth/resendActivation/ResendActivation';
|
2016-03-13 10:50:09 +02:00
|
|
|
import Password from 'components/auth/password/Password';
|
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-05-14 23:53:58 +03:00
|
|
|
import RecoverPassword from 'components/auth/recoverPassword/RecoverPassword';
|
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) {
|
|
|
|
authFlow.setStore(store);
|
|
|
|
|
2016-05-14 11:10:08 +03:00
|
|
|
const startAuthFlow = {
|
2016-06-02 20:46:49 +03:00
|
|
|
onEnter: ({location}, replace, callback) => authFlow.handleRequest(location.pathname, replace, callback)
|
2016-03-01 22:36:14 +02:00
|
|
|
};
|
|
|
|
|
2016-05-14 11:10:08 +03:00
|
|
|
const userOnly = {
|
2016-06-05 15:16:41 +03:00
|
|
|
onEnter: (nextState, replace) => {
|
2016-05-14 11:10:08 +03:00
|
|
|
const {user} = store.getState();
|
|
|
|
|
|
|
|
if (user.isGuest) {
|
|
|
|
replace('/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-13 17:28:47 +02:00
|
|
|
return (
|
|
|
|
<Route path="/" component={RootPage}>
|
2016-05-14 11:10:08 +03:00
|
|
|
<IndexRoute component={IndexPage} {...startAuthFlow} />
|
|
|
|
|
2016-05-22 18:56:52 +03:00
|
|
|
<Route path="rules" component={RulesPage} />
|
|
|
|
|
2016-05-14 11:10:08 +03:00
|
|
|
<Route path="oauth" component={OAuthInit} {...startAuthFlow} />
|
|
|
|
|
2016-05-14 15:38:00 +03:00
|
|
|
<Route path="auth" component={AuthPage}>
|
|
|
|
<Route path="/login" components={new Login()} {...startAuthFlow} />
|
|
|
|
<Route path="/password" components={new Password()} {...startAuthFlow} />
|
|
|
|
<Route path="/register" components={new Register()} {...startAuthFlow} />
|
2016-06-05 15:16:41 +03:00
|
|
|
<Route path="/activation(/:key)" components={new Activation()} {...startAuthFlow} />
|
2016-05-22 21:58:43 +03:00
|
|
|
<Route path="/resend-activation" components={new ResendActivation()} {...startAuthFlow} />
|
2016-05-14 15:38:00 +03:00
|
|
|
<Route path="/oauth/permissions" components={new Permissions()} {...startAuthFlow} />
|
|
|
|
<Route path="/oauth/finish" component={Finish} {...startAuthFlow} />
|
|
|
|
<Route path="/change-password" components={new ChangePassword()} {...startAuthFlow} />
|
|
|
|
<Route path="/forgot-password" components={new ForgotPassword()} {...startAuthFlow} />
|
2016-05-14 23:53:58 +03:00
|
|
|
<Route path="/recover-password(/:key)" components={new RecoverPassword()} {...startAuthFlow} />
|
2016-02-13 17:28:47 +02:00
|
|
|
</Route>
|
2016-04-17 12:35:04 +03:00
|
|
|
|
2016-05-14 11:10:08 +03:00
|
|
|
<Route path="profile" component={ProfilePage} {...userOnly}>
|
2016-05-01 20:50:55 +03:00
|
|
|
<Route path="change-password" component={ProfileChangePasswordPage} />
|
2016-05-02 16:13:18 +03:00
|
|
|
<Route path="change-username" component={ProfileChangeUsernamePage} />
|
2016-05-20 08:14:14 +03:00
|
|
|
<Route path="change-email(/:step)(/:code)" component={ProfileChangeEmailPage} />
|
2016-04-17 12:35:04 +03:00
|
|
|
</Route>
|
2016-06-02 22:26:09 +03:00
|
|
|
|
|
|
|
<Route path="*" component={PageNotFound} />
|
2016-02-13 17:28:47 +02:00
|
|
|
</Route>
|
|
|
|
);
|
|
|
|
}
|