From 0d6e82a45d3db0c496c6d4cd7d6bb0459f97cead Mon Sep 17 00:00:00 2001 From: diminator Date: Wed, 30 Sep 2015 15:08:45 +0200 Subject: [PATCH] WIP signup/login redirect and redirectAuthenticated --- js/components/ascribe_forms/form_login.js | 21 ++++++++++++++++++++- js/components/ascribe_forms/form_signup.js | 4 ++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/js/components/ascribe_forms/form_login.js b/js/components/ascribe_forms/form_login.js index 79bced6c..dacad32c 100644 --- a/js/components/ascribe_forms/form_login.js +++ b/js/components/ascribe_forms/form_login.js @@ -44,6 +44,10 @@ let LoginForm = React.createClass({ componentDidMount() { UserStore.listen(this.onChange); + let { redirect } = this.getQuery(); + if (redirect !== 'login'){ + this.transitionTo(redirect, null, this.getQuery()); + } }, componentWillUnmount() { @@ -56,6 +60,15 @@ let LoginForm = React.createClass({ // if user is already logged in, redirect him to piece list if(this.state.currentUser && this.state.currentUser.email && this.props.redirectOnLoggedIn) { // FIXME: hack to redirect out of the dispatch cycle + let { redirectAuthenticated } = this.getQuery(); + if ( redirectAuthenticated) { + /* + * redirectAuthenticated contains an arbirary path + * eg pieces/, editions/, collection, settings, ... + * hence transitionTo cannot be used directly + */ + window.location = AppConstants.baseUrl + redirectAuthenticated; + } window.setTimeout(() => this.transitionTo('pieces'), 0); } }, @@ -79,7 +92,13 @@ let LoginForm = React.createClass({ Users on Stack Overflow claim this is a bug in chrome and should be fixed in the future. Until then, we redirect the HARD way, but reloading the whole page using window.location */ - window.location = AppConstants.baseUrl + 'collection'; + let { redirectAuthenticated } = this.getQuery(); + if ( redirectAuthenticated) { + window.location = AppConstants.baseUrl + redirectAuthenticated; + } + else { + window.location = AppConstants.baseUrl + 'collection'; + } } else if(this.props.onLogin) { // In some instances we want to give a callback to an outer container, // to show that the one login action the user triggered actually went through. diff --git a/js/components/ascribe_forms/form_signup.js b/js/components/ascribe_forms/form_signup.js index 790e8e2f..bfcabf1a 100644 --- a/js/components/ascribe_forms/form_signup.js +++ b/js/components/ascribe_forms/form_signup.js @@ -40,6 +40,10 @@ let SignupForm = React.createClass({ componentDidMount() { UserStore.listen(this.onChange); + let { redirect } = this.getQuery(); + if (redirect !== 'signup'){ + this.transitionTo(redirect, null, this.getQuery()); + } }, componentWillUnmount() {