@@ -64,20 +64,29 @@ module.exports = function(AV) {
6464
6565 /**
6666 * Makes a call to request a sms code for operation verification.
67- * @param {Object } data The mobile phone number string or a JSON
68- * object that contains mobilePhoneNumber,template,op,ttl,name etc.
69- * @return {Promise } A promise that will be resolved with the result
70- * of the function.
67+ * @param {String|Object } data The mobile phone number string or a JSON
68+ * object that contains mobilePhoneNumber,template,sign,op,ttl,name etc.
69+ * @param {String } data.mobilePhoneNumber
70+ * @param {String } [data.template] sms template name
71+ * @param {String } [data.sign] sms signature name
72+ * @param {AuthOptions } [options] AuthOptions plus:
73+ * @param {String } [options.validateToken] a validate token returned by {@link AV.Cloud.verifyCaptcha}
74+ * @return {Promise } A promise that will be resolved if the request succeed
7175 */
72- requestSmsCode : function ( data ) {
76+ requestSmsCode : function ( data , options = { } ) {
7377 if ( _ . isString ( data ) ) {
7478 data = { mobilePhoneNumber : data } ;
7579 }
7680 if ( ! data . mobilePhoneNumber ) {
7781 throw new Error ( 'Missing mobilePhoneNumber.' ) ;
7882 }
83+ if ( options . validateToken ) {
84+ data = _ . extend ( { } , data , {
85+ validate_token : options . validateToken ,
86+ } ) ;
87+ }
7988 var request = AVRequest ( "requestSmsCode" , null , null , 'POST' ,
80- data ) ;
89+ data , options ) ;
8190 return request ;
8291 } ,
8392
@@ -99,6 +108,38 @@ module.exports = function(AV) {
99108 var request = AVRequest ( "verifySmsCode" , code , null , 'POST' ,
100109 params ) ;
101110 return request ;
102- }
111+ } ,
112+
113+ /**
114+ * request a captcha
115+ * @param {Object } [options]
116+ * @param {Number } [options.size=4] length of the captcha, ranged 3-6
117+ * @param {Number } [options.width] width(px) of the captcha, ranged 60-200
118+ * @param {Number } [options.height] height(px) of the captcha, ranged 30-100
119+ * @param {Number } [options.ttl=60] time to live(s), ranged 10-180
120+ * @return {Promise } { captchaToken, url }
121+ */
122+ requestCaptcha ( options ) {
123+ return AVRequest ( 'requestCaptcha' , null , null , 'GET' , options ) . then ( ( {
124+ captcha_url : url ,
125+ captcha_token : captchaToken ,
126+ } ) => ( {
127+ captchaToken,
128+ url,
129+ } ) ) ;
130+ } ,
131+
132+ /**
133+ * verify captcha code
134+ * @param {String } code the code from user input
135+ * @param {String } captchaToken captchaToken returned by {@link AV.Cloud.requestCaptcha}
136+ * @return {Promise.<String> } validateToken if the code is valid
137+ */
138+ verifyCaptcha ( code , captchaToken ) {
139+ return AVRequest ( 'verifyCaptcha' , null , null , 'POST' , {
140+ captcha_code : code ,
141+ captcha_token : captchaToken ,
142+ } ) . then ( ( { validate_token : validateToken } ) => validateToken ) ;
143+ } ,
103144 } ) ;
104145} ;
0 commit comments