Skip to content

Commit c50a440

Browse files
committed
Fixed issue #50
1 parent 1f924ce commit c50a440

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

lib/av.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,7 @@
16301630
route !== "statuses" &&
16311631
route !== 'subscribe/statuses/count' &&
16321632
route !== 'subscribe/statuses' &&
1633+
!(/users\/[^\/]+\/updatePassword/.test(route)) &&
16331634
!(/users\/[^\/]+\/friendship\/[^\/]+/.test(route))) {
16341635
throw "Bad route: '" + route + "'.";
16351636
}
@@ -7076,6 +7077,24 @@
70767077
return AV.Object.prototype.fetch.call(this, newOptions);
70777078
},
70787079

7080+
/**
7081+
* Update user's new password safely based on old password.
7082+
* @param {String} oldPassword, the old password.
7083+
* @param {String} newPassword, the new password.
7084+
* @param {Object} An optional Backbone-like options object with
7085+
* success and error callbacks that will be invoked once the iteration
7086+
* has finished.
7087+
*/
7088+
updatePassword: function(oldPassword, newPassword, options) {
7089+
var route = 'users/' + this.id + '/updatePassword';
7090+
var params = {
7091+
old_password: oldPassword,
7092+
new_password: newPassword
7093+
};
7094+
var request = AV._request(route, null, null, 'PUT', params);
7095+
return request._thenRunCallbacks(options, this);
7096+
},
7097+
70797098
/**
70807099
* Returns true if <code>current</code> would return this user.
70817100
* @see AV.User#current

tests/test.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
if (!expr) throw new Error(msg || 'failed');
3939
}
4040
</script>
41-
<script src="file.js"></script>
41+
<!-- <script src="file.js"></script>
4242
<script src="error.js"></script>
4343
<script src="object.js"></script>
4444
<script src="collection.js"></script>
@@ -50,6 +50,8 @@
5050
5151
<script src="status.js"></script>
5252
<script src="sms.js"></script>
53+
-->
54+
<script src="user.js"></script>
5355
<script>
5456
onload = function(){
5557
mocha.checkLeaks();

tests/user.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ describe("User update",function(){
9393
})
9494
});
9595

96+
describe("Update user password", function() {
97+
it("update password",function(done){
98+
var user = AV.User.logIn(username, password, {
99+
success: function(user) {
100+
user.updatePassword(password, 'new pass').then(function(){
101+
AV.User.logIn(username, 'new pass').then(function(user){
102+
user.updatePassword('new pass', password).then(function(){
103+
done();
104+
});
105+
});
106+
});
107+
},
108+
error: function(err) {
109+
throw err;
110+
}
111+
});
112+
});
113+
});
114+
96115
describe("User query",function(){
97116
it("return conditoinal users",function(done){
98117
var query = new AV.Query(AV.User);

0 commit comments

Comments
 (0)