From 66e00b75b0648e20be6c3a7f52825c2cd4ee6dbc Mon Sep 17 00:00:00 2001 From: Thierry Joyal Date: Wed, 11 Sep 2013 08:57:55 -0400 Subject: [PATCH] Skip redirect on password module when request is xhr --- lib/modules/password.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/modules/password.js b/lib/modules/password.js index b275746d..e1430a43 100644 --- a/lib/modules/password.js +++ b/lib/modules/password.js @@ -178,7 +178,7 @@ everyModule.submodule('password') .promises(null) .step('respondToLoginSucceed') // TODO Rename to maybeRespondToLoginSucceed ? .description('Execute a HTTP response for a successful login') - .accepts('res user') + .accepts('req res user') .promises(null) .step('respondToLoginFail') .description('Execute a HTTP response for a failed login') @@ -203,9 +203,13 @@ everyModule.submodule('password') _auth.userId = user[this._userPkey]; _auth.loggedIn = !!user; }) - .respondToLoginSucceed( function (res, user) { + .respondToLoginSucceed( function (req, res, user) { if (user) { - this.redirect(res, this.loginSuccessRedirect()); + if (req.xhr) { + res.status(200).send(); + } else { + this.redirect(res, this.loginSuccessRedirect()); + } } }) .respondToLoginFail( function (req, res, errors, login) { @@ -326,7 +330,11 @@ everyModule.submodule('password') return user; }) .respondToRegistrationSucceed( function (req, res, user) { - this.redirect(res, this.registerSuccessRedirect()); + if (req.xhr) { + res.status(200).send(); + } else { + this.redirect(res, this.registerSuccessRedirect()); + } }) .stepseq('registrationFailSteps')