Skip to content

Commit ff060b7

Browse files
committed
Merge pull request #5 from avoscloud/0.3.7
0.3.7
2 parents 41fe510 + 11f4916 commit ff060b7

File tree

4 files changed

+230
-3
lines changed

4 files changed

+230
-3
lines changed

lib/av.js

Lines changed: 170 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,12 @@
15841584
route !== "push" &&
15851585
route !== "search/select" &&
15861586
route !== "requestPasswordReset" &&
1587+
route !== "requestEmailVerify" &&
1588+
route !== "requestMobilePhoneVerify" &&
1589+
route !== "requestLoginSmsCode" &&
1590+
route !== "verifyMobilePhone" &&
1591+
route !== "requestSmsCode" &&
1592+
route !== "verifySmsCode" &&
15871593
route !== "users" &&
15881594
route !== "qiniu" &&
15891595
route !== "statuses" &&
@@ -6837,6 +6843,8 @@
68376843
var serverAttrs = model.parse(resp, status, xhr);
68386844
model._finishFetch(serverAttrs);
68396845
model._handleSaveResult(true);
6846+
if(!serverAttrs.smsCode)
6847+
delete model.attributes['smsCode'];
68406848
return model;
68416849
})._thenRunCallbacks(options, this);
68426850
},
@@ -6963,6 +6971,26 @@
69636971
return this.get("username");
69646972
},
69656973

6974+
/**
6975+
* Returns get("mobilePhoneNumber").
6976+
* @return {String}
6977+
* @see AV.Object#get
6978+
*/
6979+
getMobilePhoneNumber: function(){
6980+
return this.get("mobilePhoneNumber");
6981+
},
6982+
6983+
/**
6984+
* Calls set("mobilePhoneNumber", phoneNumber, options) and returns the result.
6985+
* @param {String} mobilePhoneNumber
6986+
* @param {Object} options A Backbone-style options object.
6987+
* @return {Boolean}
6988+
* @see AV.Object.set
6989+
*/
6990+
setMobilePhoneNumber: function(phone, options) {
6991+
return this.set("mobilePhoneNumber", phone, options);
6992+
},
6993+
69666994
/**
69676995
* Calls set("username", username, options) and returns the result.
69686996
* @param {String} username
@@ -7078,6 +7106,47 @@
70787106
return user.logIn(options);
70797107
},
70807108

7109+
/**
7110+
* Logs in a user with a mobile phone number and sms code sent by
7111+
* AV.User.requestLoginSmsCode.On success, this
7112+
* saves the session to disk, so you can retrieve the currently logged in
7113+
* user using <code>current</code>.
7114+
*
7115+
* <p>Calls options.success or options.error on completion.</p>
7116+
*
7117+
* @param {String} mobilePhone The user's mobilePhoneNumber
7118+
* @param {String} smsCode The sms code sent by AV.User.requestLoginSmsCode
7119+
* @param {Object} options A Backbone-style options object.
7120+
* @return {AV.Promise} A promise that is fulfilled with the user when
7121+
* the login completes.
7122+
* @see AV.User#logIn
7123+
*/
7124+
logInWithMobilePhoneSmsCode: function(mobilePhone, smsCode, options){
7125+
var user = AV.Object._create("_User");
7126+
user._finishFetch({ mobilePhoneNumber: mobilePhone, smsCode: smsCode });
7127+
return user.logIn(options);
7128+
},
7129+
7130+
/**
7131+
* Logs in a user with a mobile phone number and password. On success, this
7132+
* saves the session to disk, so you can retrieve the currently logged in
7133+
* user using <code>current</code>.
7134+
*
7135+
* <p>Calls options.success or options.error on completion.</p>
7136+
*
7137+
* @param {String} mobilePhone The user's mobilePhoneNumber
7138+
* @param {String} password The password to log in with.
7139+
* @param {Object} options A Backbone-style options object.
7140+
* @return {AV.Promise} A promise that is fulfilled with the user when
7141+
* the login completes.
7142+
* @see AV.User#logIn
7143+
*/
7144+
logInWithMobilePhone: function(mobilePhone, password, options){
7145+
var user = AV.Object._create("_User");
7146+
user._finishFetch({ mobilePhoneNumber: mobilePhone, password: password });
7147+
return user.logIn(options);
7148+
},
7149+
70817150
/**
70827151
* Logs out the currently logged in user session. This will remove the
70837152
* session from disk, log out of linked services, and future calls to
@@ -7142,6 +7211,74 @@
71427211
return request._thenRunCallbacks(options);
71437212
},
71447213

7214+
/**
7215+
* Requests a verify email to be sent to the specified email address
7216+
* associated with the user account. This email allows the user to securely
7217+
* verify their email address on the AV site.
7218+
*
7219+
* <p>Calls options.success or options.error on completion.</p>
7220+
*
7221+
* @param {String} email The email address associated with the user that
7222+
* doesn't verify their email address.
7223+
* @param {Object} options A Backbone-style options object.
7224+
*/
7225+
requestEmailVerfiyInBackground: function(email, options) {
7226+
var json = { email: email };
7227+
var request = AV._request("requestEmailVerify", null, null, "POST",
7228+
json);
7229+
return request._thenRunCallbacks(options);
7230+
},
7231+
7232+
/**
7233+
* Requests a verify sms code to be sent to the specified mobile phone
7234+
* number associated with the user account. This sms code allows the user to
7235+
* verify their mobile phone number by calling AV.User.verifyMobilePhone
7236+
*
7237+
* <p>Calls options.success or options.error on completion.</p>
7238+
*
7239+
* @param {String} mobilePhone The mobile phone number associated with the
7240+
* user that doesn't verify their mobile phone number.
7241+
* @param {Object} options A Backbone-style options object.
7242+
*/
7243+
requestMobilePhoneVerify: function(mobilePhone, options){
7244+
var json = { mobilePhoneNumber: mobilePhone };
7245+
var request = AV._request("requestMobilePhoneVerify", null, null, "POST",
7246+
json);
7247+
return request._thenRunCallbacks(options);
7248+
},
7249+
7250+
/**
7251+
* Makes a call to verify sms code that sent by AV.User.Cloud.requestSmsCode
7252+
* If verify successfully,the user mobilePhoneVerified attribute will be true.
7253+
* @param {String} code The sms code sent by AV.User.Cloud.requestSmsCode
7254+
* @param {Object} options A Backbone-style options object
7255+
* @return {AV.Promise} A promise that will be resolved with the result
7256+
* of the function.
7257+
*/
7258+
verifyMobilePhone: function(code, options){
7259+
var request = AV._request("verifyMobilePhone", null, code, "POST",
7260+
null);
7261+
return request._thenRunCallbacks(options);
7262+
},
7263+
7264+
/**
7265+
* Requests a logIn sms code to be sent to the specified mobile phone
7266+
* number associated with the user account. This sms code allows the user to
7267+
* login by AV.User.logInWithMobilePhoneSmsCode function.
7268+
*
7269+
* <p>Calls options.success or options.error on completion.</p>
7270+
*
7271+
* @param {String} mobilePhone The mobile phone number associated with the
7272+
* user that want to login by AV.User.logInWithMobilePhoneSmsCode
7273+
* @param {Object} options A Backbone-style options object.
7274+
*/
7275+
requestLoginSmsCode: function(mobilePhone, options){
7276+
var json = { mobilePhoneNumber: mobilePhone };
7277+
var request = AV._request("requestLoginSmsCode", null, null, "POST",
7278+
json);
7279+
return request._thenRunCallbacks(options);
7280+
},
7281+
71457282
/**
71467283
* Retrieves the currently logged in AVUser with a valid session,
71477284
* either from memory or localStorage, if necessary.
@@ -8658,7 +8795,39 @@
86588795
return request.then(function(resp) {
86598796
return AV._decode(null, resp).result;
86608797
})._thenRunCallbacks(options);
8661-
}
8798+
},
8799+
8800+
/**
8801+
* Makes a call to request a sms code for operation verification.
8802+
* @param {Object} data The mobile phone number string or a JSON object contains mobilePhoneNumber,op,ttl,name etc.
8803+
* @param {Object} options A Backbone-style options object
8804+
* @return {AV.Promise} A promise that will be resolved with the result
8805+
* of the function.
8806+
*/
8807+
requestSmsCode: function(data, options){
8808+
if(typeof data === 'string')
8809+
data = { mobilePhoneNumber: data };
8810+
if(!data.mobilePhoneNumber)
8811+
throw "Missing mobilePhoneNumber.";
8812+
var request = AV._request("requestSmsCode", null, null, 'POST',
8813+
data);
8814+
return request._thenRunCallbacks(options);
8815+
},
8816+
8817+
/**
8818+
* Makes a call to verify sms code that sent by AV.Cloud.requestSmsCode
8819+
* @param {String} code The sms code sent by AV.Cloud.requestSmsCode
8820+
* @param {Object} options A Backbone-style options object
8821+
* @return {AV.Promise} A promise that will be resolved with the result
8822+
* of the function.
8823+
*/
8824+
verifySmsCode: function(code, options){
8825+
if(!code)
8826+
throw "Missing sms code.";
8827+
var request = AV._request("verifySmsCode", code, null, 'POST',
8828+
null);
8829+
return request._thenRunCallbacks(options);
8830+
},
86628831
});
86638832
}(this));
86648833

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "avoscloud-sdk",
3-
"version": "0.3.5",
3+
"version": "0.3.7",
44
"main": "./lib/av.js",
55
"description": "AVOSCloud JavaScript SDK.",
66
"dependencies": {

tests/sms.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
describe("sms", function() {
2+
3+
describe("#verifyUserMobilePhone", function(){
4+
this.timeout(10000);
5+
it("should be verified", function(done){
6+
var user = new AV.User();
7+
user.set("username", "dennis");
8+
user.set("password", "123456");
9+
user.setMobilePhoneNumber('18668012283');
10+
11+
user.signUp(null, {
12+
success: function(user) {
13+
AV.User.requestMobilePhoneVerify('18668012283').then(function(){
14+
AV.User.logInWithMobilePhone('18668012283',
15+
'123456').then(function(user){
16+
console.dir(user);
17+
expect(user.get('mobilePhoneVerified')).to.be(false);
18+
AV.User.requestLoginSmsCode('18668012283').then(function(){
19+
throw "Unverfied.";
20+
}, function(err){
21+
user.destroy().then(function(){
22+
done();
23+
});
24+
});
25+
}, function(err){
26+
throw err;
27+
});
28+
29+
},function(err){
30+
throw err;
31+
});
32+
},
33+
error: function(user, error) {
34+
throw error;
35+
}
36+
});
37+
});
38+
});
39+
40+
describe("#requestSmsCode", function(){
41+
it("should send sms code.", function(done){
42+
AV.Cloud.requestSmsCode('18668012283').then(function(){
43+
AV.Cloud.requestSmsCode({
44+
mobilePhoneNumber: '18668012283',
45+
name: '测试啊',
46+
op: '测试操作',
47+
ttl: 5
48+
}).then(function(){
49+
done();
50+
}, function(err){
51+
throw err;
52+
});
53+
}, function(err){
54+
throw err;
55+
});
56+
});
57+
});
58+
});

tests/test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
if (!expr) throw new Error(msg || 'failed');
3939
}
4040
</script>
41-
4241
<script src="file.js"></script>
4342
<script src="error.js"></script>
4443
<script src="object.js"></script>
@@ -50,6 +49,7 @@
5049
<script src="master_key.js"></script>
5150

5251
<script src="status.js"></script>
52+
<script src="sms.js"></script>
5353
<script>
5454
onload = function(){
5555
mocha.checkLeaks();

0 commit comments

Comments
 (0)