resend validation email
This commit is contained in:
parent
4e2e2c5ba9
commit
9c4eef5912
@ -722,6 +722,39 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
emailPlugin._parseSecret = function (value) {
|
||||||
|
var obj = null;
|
||||||
|
try {
|
||||||
|
obj = JSON.parse(value);
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
if (obj && _.isObject(obj)) {
|
||||||
|
return obj.secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
emailPlugin.resendEmail = function(request, response) {
|
||||||
|
emailPlugin.authorizeRequestWithoutKey(request, function(err, email) {
|
||||||
|
if (err) {
|
||||||
|
return emailPlugin.returnError(err, response);
|
||||||
|
}
|
||||||
|
emailPlugin.db.get(pendingKey(email), function(err, value) {
|
||||||
|
if (err) {
|
||||||
|
logger.error('error retrieving secret for email', email, err);
|
||||||
|
return emailPlugin.returnError(err, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
var secret = emailPlugin._parseSecret(value);
|
||||||
|
|
||||||
|
emailPlugin.sendVerificationEmail(email, secret);
|
||||||
|
return response.json({
|
||||||
|
success: true
|
||||||
|
}).end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks an email as validated
|
* Marks an email as validated
|
||||||
@ -751,14 +784,7 @@
|
|||||||
}, response);
|
}, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
var parsed = null;
|
value = emailPlugin._parseSecret(value);
|
||||||
try {
|
|
||||||
parsed = JSON.parse(value);
|
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
if (parsed && _.isObject(parsed)) {
|
|
||||||
value = parsed.secret;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value !== secret) {
|
if (value !== secret) {
|
||||||
return emailPlugin.returnError(emailPlugin.errors.INVALID_CODE, response);
|
return emailPlugin.returnError(emailPlugin.errors.INVALID_CODE, response);
|
||||||
|
|||||||
@ -406,6 +406,25 @@ describe('emailstore test', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe.only('resend validation email', function () {
|
||||||
|
var email = 'fake@email.com';
|
||||||
|
var secret = '123';
|
||||||
|
beforeEach(function() {
|
||||||
|
request.param.onFirstCall().returns(email);
|
||||||
|
response.json.returnsThis();
|
||||||
|
response.redirect = sinon.stub();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should resend validation email when pending', function () {
|
||||||
|
plugin.authorizeRequestWithoutKey = sinon.stub().callsArgWith(1, null, email);
|
||||||
|
leveldb_stub.get.onFirstCall().callsArgWith(1, null, JSON.stringify({ secret: secret, created: new Date() }));
|
||||||
|
plugin.sendVerificationEmail = sinon.spy();
|
||||||
|
plugin.resendEmail(request, response);
|
||||||
|
plugin.sendVerificationEmail.calledOnce.should.be.true;
|
||||||
|
plugin.sendVerificationEmail.calledWith(email, secret).should.be.true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('removing items', function() {
|
describe('removing items', function() {
|
||||||
var fakeEmail = 'fake@email.com';
|
var fakeEmail = 'fake@email.com';
|
||||||
var fakeKey = 'nameForData';
|
var fakeKey = 'nameForData';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user