Merge pull request #1120 from PradnyaBaviskar/lb-issue-416
Fix "User.confirm" to always call afterRemote hook Close #1120
This commit is contained in:
commit
3c43eccac7
|
@ -567,7 +567,7 @@ module.exports = function(User) {
|
||||||
accepts: [
|
accepts: [
|
||||||
{arg: 'uid', type: 'string', required: true},
|
{arg: 'uid', type: 'string', required: true},
|
||||||
{arg: 'token', type: 'string', required: true},
|
{arg: 'token', type: 'string', required: true},
|
||||||
{arg: 'redirect', type: 'string', required: true}
|
{arg: 'redirect', type: 'string'}
|
||||||
],
|
],
|
||||||
http: {verb: 'get', path: '/confirm'}
|
http: {verb: 'get', path: '/confirm'}
|
||||||
}
|
}
|
||||||
|
@ -586,21 +586,14 @@ module.exports = function(User) {
|
||||||
|
|
||||||
UserModel.on('attached', function() {
|
UserModel.on('attached', function() {
|
||||||
UserModel.afterRemote('confirm', function(ctx, inst, next) {
|
UserModel.afterRemote('confirm', function(ctx, inst, next) {
|
||||||
if (ctx.req) {
|
if (ctx.args.redirect !== undefined) {
|
||||||
// replacement for deprecated req.param()
|
if (!ctx.res) {
|
||||||
var params = ctx.req.params;
|
return next(new Error('The transport does not support HTTP redirects.'));
|
||||||
var body = ctx.req.body;
|
}
|
||||||
var query = ctx.req.query;
|
ctx.res.location(ctx.args.redirect);
|
||||||
var redirectUrl =
|
ctx.res.status(302);
|
||||||
params && params.redirect !== undefined ? params.redirect :
|
|
||||||
body && body.redirect !== undefined ? body.redirect :
|
|
||||||
query && query.redirect !== undefined ? query.redirect :
|
|
||||||
undefined;
|
|
||||||
|
|
||||||
ctx.res.redirect(redirectUrl);
|
|
||||||
} else {
|
|
||||||
next(new Error('transport unsupported'));
|
|
||||||
}
|
}
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
"nodemailer-stub-transport": "~0.1.4",
|
"nodemailer-stub-transport": "~0.1.4",
|
||||||
"serve-favicon": "^2.1.6",
|
"serve-favicon": "^2.1.6",
|
||||||
"stable": "^0.1.5",
|
"stable": "^0.1.5",
|
||||||
"strong-remoting": "^2.11.0",
|
"strong-remoting": "^2.13.2",
|
||||||
"uid2": "0.0.3",
|
"uid2": "0.0.3",
|
||||||
"underscore.string": "~2.3.3"
|
"underscore.string": "~2.3.3"
|
||||||
},
|
},
|
||||||
|
|
|
@ -865,6 +865,28 @@ describe('User', function() {
|
||||||
}, done);
|
}, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should report 302 when redirect url is set', function(done) {
|
||||||
|
testConfirm(function(result, done) {
|
||||||
|
request(app)
|
||||||
|
.get('/users/confirm?uid=' + (result.uid) +
|
||||||
|
'&token=' + encodeURIComponent(result.token) +
|
||||||
|
'&redirect=http://foo.com/bar')
|
||||||
|
.expect(302)
|
||||||
|
.expect('Location', 'http://foo.com/bar')
|
||||||
|
.end(done);
|
||||||
|
}, done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should report 204 when redirect url is not set', function(done) {
|
||||||
|
testConfirm(function(result, done) {
|
||||||
|
request(app)
|
||||||
|
.get('/users/confirm?uid=' + (result.uid) +
|
||||||
|
'&token=' + encodeURIComponent(result.token))
|
||||||
|
.expect(204)
|
||||||
|
.end(done);
|
||||||
|
}, done);
|
||||||
|
});
|
||||||
|
|
||||||
it('Report error for invalid user id during verification', function(done) {
|
it('Report error for invalid user id during verification', function(done) {
|
||||||
testConfirm(function(result, done) {
|
testConfirm(function(result, done) {
|
||||||
request(app)
|
request(app)
|
||||||
|
|
Loading…
Reference in New Issue