Merge pull request #203 from zaach/verify_reset_code_api

add verify reset code to client api
This commit is contained in:
ckarlof 2013-09-25 17:22:48 -07:00
Родитель dc71fc2282 0f936854de
Коммит c5ca7fc0fa
2 изменённых файлов: 34 добавлений и 14 удалений

Просмотреть файл

@ -568,19 +568,30 @@ Client.prototype.reforgotPassword = function (callback) {
}
}
Client.prototype.resetPassword = function (code, password, callback) {
// this will generate a new wrapKb on the server
var wrapKb = '0000000000000000000000000000000000000000000000000000000000000000'
var p = this.setupCredentials(this.email, password)
Client.prototype.verifyPasswordResetCode = function (code, callback) {
var p = this.api.passwordForgotVerifyCode(this.forgotPasswordToken, code)
.then(
function () {
return this.api.passwordForgotVerifyCode(this.forgotPasswordToken, code)
function (result) {
this.accountResetToken = result.accountResetToken
}.bind(this)
)
if (callback) {
p.done(callback.bind(null, null), callback)
}
else {
return p
}
}
Client.prototype.resetPassword = function (newPassword, callback) {
if (!this.accountResetToken) {
throw new Error("call verifyPasswordResetCode before calling resetPassword");
}
// this will generate a new wrapKb on the server
var wrapKb = '0000000000000000000000000000000000000000000000000000000000000000'
var p = this.setupCredentials(this.email, newPassword)
.then(
function (json) {
return tokens.AccountResetToken.fromHex(json.accountResetToken)
}
tokens.AccountResetToken.fromHex.bind(null, this.accountResetToken)
)
.then(
function (accountResetToken) {

Просмотреть файл

@ -197,7 +197,8 @@ function main() {
)
.then(
function (code) {
return client.resetPassword(code, newPassword)
t.throws(function() { client.resetPassword(newPassword); })
return resetPassword(client, code, newPassword)
}
)
.then(
@ -285,7 +286,7 @@ function main() {
)
.then(
function () {
return client.resetPassword('wrongcode', 'password')
return resetPassword(client, 'wrongcode', 'password')
}
)
.then(
@ -299,7 +300,7 @@ function main() {
)
.then(
function () {
return client.resetPassword('wrongcode', 'password')
return resetPassword(client, 'wrongcode', 'password')
}
)
.then(
@ -313,7 +314,7 @@ function main() {
)
.then(
function () {
return client.resetPassword('wrongcode', 'password')
return resetPassword(client, 'wrongcode', 'password')
}
)
.then(
@ -327,7 +328,7 @@ function main() {
)
.then(
function () {
return client.resetPassword('wrongcode', 'password')
return resetPassword(client, 'wrongcode', 'password')
}
)
.then(
@ -452,3 +453,11 @@ function waitLoop() {
}
waitLoop()
function resetPassword(client, code, newPassword) {
return client.verifyPasswordResetCode(code)
.then(function() {
return client.resetPassword(newPassword)
})
}