Merge pull request #203 from zaach/verify_reset_code_api
add verify reset code to client api
This commit is contained in:
Коммит
c5ca7fc0fa
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче