Do not expose logout action to route

This commit is contained in:
SleepWalker 2016-05-01 13:31:40 +03:00
parent 6f54971a16
commit 85d409ad30
6 changed files with 26 additions and 26 deletions

View File

@ -1,9 +0,0 @@
import React, { Component } from 'react';
export class Logout extends Component {
static displayName = 'Logout';
render() {
return <span/>;
}
}

View File

@ -1,3 +1,5 @@
import { routeActions } from 'react-router-redux';
import request from 'services/request';
import accounts from 'services/api/accounts';
@ -22,7 +24,10 @@ export function setUser(payload) {
}
export function logout() {
return setUser({isGuest: true});
return (dispatch) => {
dispatch(setUser({isGuest: true}));
dispatch(routeActions.push('/login'));
};
}
export function fetchUserData() {

View File

@ -1,8 +1,8 @@
import React, { Component } from 'react';
import React, { Component, PropTypes } from 'react';
import classNames from 'classnames';
import { Link } from 'react-router';
import { intlShape, FormattedMessage as Message } from 'react-intl';
import { intlShape } from 'react-intl';
import buttons from 'components/ui/buttons.scss';
import buttonGroups from 'components/ui/button-groups.scss';
@ -15,7 +15,8 @@ import { userShape } from 'components/user/User';
export default class LoggedInPanel extends Component {
static displayName = 'LoggedInPanel';
static propTypes = {
user: userShape
user: userShape,
onLogout: PropTypes.func.isRequired
};
static contextTypes = {
@ -31,14 +32,20 @@ export default class LoggedInPanel extends Component {
<span className={styles.userIcon} />
<span className={styles.userName}>{user.username}</span>
</Link>
<Link
to="/logout"
<button
onClick={this.onLogout}
className={classNames(buttons.green, buttonGroups.item)}
title={this.context.intl.formatMessage(messages.logout)}
>
<span className={styles.logoutIcon} />
</Link>
</button>
</div>
);
}
onLogout = (event) => {
event.preventDefault();
this.props.onLogout();
};
}

View File

@ -1,6 +1,5 @@
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router';
import Userbar from 'components/userbar/Userbar';
@ -16,7 +15,7 @@ function RootPage(props) {
Ely.by
</Link>
<div className={styles.userbar}>
<Userbar {...props} />
<Userbar {...props} onLogout={props.logout} />
</div>
</div>
</div>
@ -32,6 +31,11 @@ RootPage.propTypes = {
children: PropTypes.element
};
import { connect } from 'react-redux';
import { logout } from 'components/user/actions';
export default connect((state) => ({
user: state.user
}))(RootPage);
}), {
logout
})(RootPage);

View File

@ -14,7 +14,6 @@ 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';
import Logout from 'components/auth/Logout';
import ChangePassword from 'components/auth/changePassword/ChangePassword';
import ForgotPassword from 'components/auth/forgotPassword/ForgotPassword';
import Finish from 'components/auth/finish/Finish';
@ -41,7 +40,6 @@ export default function routesFactory(store) {
<IndexRoute component={IndexPage} {...onEnter} />
<Route path="oauth" component={OAuthInit} {...onEnter} />
<Route path="logout" component={Logout} {...onEnter} />
<Route path="auth" component={AuthPage}>
<Route path="/login" components={new Login()} {...onEnter} />

View File

@ -104,11 +104,6 @@ export default class AuthFlow {
this.setState(new LoginState());
break;
case '/logout':
this.run('logout');
this.setState(new LoginState());
break;
default:
throw new Error(`Unsupported request: ${path}`);
}