From 761138dbf674b690f5615c37a4297c9d9778d633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Thu, 25 Jun 2015 11:49:45 +0200 Subject: [PATCH] add redirect to login page if user is logged in --- js/components/login_container.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/js/components/login_container.js b/js/components/login_container.js index 8c149d8c..ba8abd29 100644 --- a/js/components/login_container.js +++ b/js/components/login_container.js @@ -6,6 +6,8 @@ import Router from 'react-router'; import GlobalNotificationModel from '../models/global_notification_model'; import GlobalNotificationActions from '../actions/global_notification_actions'; +import UserStore from '../stores/user_store'; + import Form from './ascribe_forms/form'; import Property from './ascribe_forms/property'; @@ -15,6 +17,25 @@ import apiUrls from '../constants/api_urls'; let LoginContainer = React.createClass({ mixins: [Router.Navigation], + getInitialState() { + return UserStore.getState(); + }, + + componentDidMount() { + UserStore.listen(this.onChange); + }, + + componentWillUnmount() { + UserStore.unlisten(this.onChange); + }, + + onChange(state) { + this.setState(state); + if(this.state.currentUser && this.state.currentUser.email) { + this.transitionTo('pieces'); + } + }, + render() { return (
@@ -31,15 +52,12 @@ let LoginContainer = React.createClass({ let LoginForm = React.createClass({ - mixins: [Router.Navigation], - - handleSuccess(){ let notification = new GlobalNotificationModel('Login successsful', 'success', 10000); GlobalNotificationActions.appendGlobalNotification(notification); /*Taken from http://stackoverflow.com/a/14916411 */ - /* + /* We actually have to trick the Browser into showing the "save password" dialog as Chrome expects the login page to be reloaded after the login. Users on Stack Overflow claim this is a bug in chrome and should be fixed in the future.