accounts-frontend/src/routes.js

83 lines
3.8 KiB
JavaScript
Raw Normal View History

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';
import AuthPage from 'pages/auth/AuthPage';
2016-05-22 21:26:52 +05:30
import RulesPage from 'pages/rules/RulesPage';
2016-06-03 00:56:09 +05:30
import PageNotFound from 'pages/404/PageNotFound';
2016-05-22 21:26:52 +05:30
import ProfilePage from 'pages/profile/ProfilePage';
import ProfileChangePasswordPage from 'pages/profile/ChangePasswordPage';
2016-05-02 18:43:18 +05:30
import ProfileChangeUsernamePage from 'pages/profile/ChangeUsernamePage';
import ProfileChangeEmailPage from 'pages/profile/ChangeEmailPage';
2016-02-23 11:27:16 +05:30
import OAuthInit from 'components/auth/OAuthInit';
import Register from 'components/auth/register/Register';
import Login from 'components/auth/login/Login';
import Permissions from 'components/auth/permissions/Permissions';
2016-11-06 01:53:56 +05:30
import ChooseAccount from 'components/auth/chooseAccount/ChooseAccount';
import Activation from 'components/auth/activation/Activation';
import ResendActivation from 'components/auth/resendActivation/ResendActivation';
import Password from 'components/auth/password/Password';
2016-08-03 00:29:29 +05:30
import AcceptRules from 'components/auth/acceptRules/AcceptRules';
import ForgotPassword from 'components/auth/forgotPassword/ForgotPassword';
import RecoverPassword from 'components/auth/recoverPassword/RecoverPassword';
import Finish from 'components/auth/finish/Finish';
2016-03-02 02:06:14 +05:30
import authFlow from 'services/authFlow';
2016-03-02 02:06:14 +05:30
export default function routesFactory(store) {
authFlow.setStore(store);
2016-05-14 13:40:08 +05:30
const startAuthFlow = {
onEnter: ({location: {query, pathname: path}, params}, replace, callback) =>
authFlow.handleRequest({path, params, query}, replace, callback)
2016-03-02 02:06:14 +05:30
};
2016-05-14 13:40:08 +05:30
const userOnly = {
2016-06-05 17:46:41 +05:30
onEnter: (nextState, replace) => {
2016-05-14 13:40:08 +05:30
const {user} = store.getState();
if (user.isGuest) {
replace('/');
}
}
};
// TODO: when react-router v3 is out, should update to oauth2(/v1)(/:clientId)
// to oauth2(/:version)(/:clientId) with the help of new route matching options
return (
<Route path="/" component={RootPage}>
2016-05-14 13:40:08 +05:30
<IndexRoute component={IndexPage} {...startAuthFlow} />
2016-05-22 21:26:52 +05:30
<Route path="rules" component={RulesPage} />
<Route path="oauth2(/v1)(/:clientId)" component={OAuthInit} {...startAuthFlow} />
2016-05-14 13:40:08 +05:30
<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 17:46:41 +05:30
<Route path="/activation(/:key)" components={new Activation()} {...startAuthFlow} />
<Route path="/resend-activation" components={new ResendActivation()} {...startAuthFlow} />
<Route path="/oauth/permissions" components={new Permissions()} {...startAuthFlow} />
2016-11-06 01:53:56 +05:30
<Route path="/oauth/choose-account" components={new ChooseAccount()} {...startAuthFlow} />
<Route path="/oauth/finish" component={Finish} {...startAuthFlow} />
2016-08-03 00:29:29 +05:30
<Route path="/accept-rules" components={new AcceptRules()} {...startAuthFlow} />
<Route path="/forgot-password" components={new ForgotPassword()} {...startAuthFlow} />
<Route path="/recover-password(/:key)" components={new RecoverPassword()} {...startAuthFlow} />
</Route>
2016-05-14 13:40:08 +05:30
<Route path="profile" component={ProfilePage} {...userOnly}>
<Route path="change-password" component={ProfileChangePasswordPage} />
2016-05-02 18:43:18 +05:30
<Route path="change-username" component={ProfileChangeUsernamePage} />
<Route path="change-email(/:step)(/:code)" component={ProfileChangeEmailPage} />
</Route>
2016-06-03 00:56:09 +05:30
<Route path="*" component={PageNotFound} />
</Route>
);
}