@@ -71,20 +71,29 @@ module.exports = function(AV) {
7171
7272 /**
7373 * Makes a call to request a sms code for operation verification.
74- * @param {Object } data The mobile phone number string or a JSON
75- * object that contains mobilePhoneNumber,template,op,ttl,name etc.
76- * @return {Promise } A promise that will be resolved with the result
77- * of the function.
74+ * @param {String|Object } data The mobile phone number string or a JSON
75+ * object that contains mobilePhoneNumber,template,sign,op,ttl,name etc.
76+ * @param {String } data.mobilePhoneNumber
77+ * @param {String } [data.template] sms template name
78+ * @param {String } [data.sign] sms signature name
79+ * @param {AuthOptions } [options] AuthOptions plus:
80+ * @param {String } [options.validateToken] a validate token returned by {@link AV.Cloud.verifyCaptcha}
81+ * @return {Promise } A promise that will be resolved if the request succeed
7882 */
79- requestSmsCode ( data ) {
83+ requestSmsCode ( data , options = { } ) {
8084 if ( _ . isString ( data ) ) {
8185 data = { mobilePhoneNumber : data } ;
8286 }
8387 if ( ! data . mobilePhoneNumber ) {
8488 throw new Error ( 'Missing mobilePhoneNumber.' ) ;
8589 }
90+ if ( options . validateToken ) {
91+ data = _ . extend ( { } , data , {
92+ validate_token : options . validateToken ,
93+ } ) ;
94+ }
8695 return _request ( "requestSmsCode" , null , null , 'POST' ,
87- data ) ;
96+ data , options ) ;
8897 } ,
8998
9099 /**
@@ -104,6 +113,38 @@ module.exports = function(AV) {
104113
105114 return _request ( "verifySmsCode" , code , null , 'POST' ,
106115 params ) ;
107- }
116+ } ,
117+
118+ /**
119+ * request a captcha
120+ * @param {Object } [options]
121+ * @param {Number } [options.size=4] length of the captcha, ranged 3-6
122+ * @param {Number } [options.width] width(px) of the captcha, ranged 60-200
123+ * @param {Number } [options.height] height(px) of the captcha, ranged 30-100
124+ * @param {Number } [options.ttl=60] time to live(s), ranged 10-180
125+ * @return {Promise } { captchaToken, url }
126+ */
127+ requestCaptcha ( options ) {
128+ return _request ( 'requestCaptcha' , null , null , 'GET' , options ) . then ( ( {
129+ captcha_url : url ,
130+ captcha_token : captchaToken ,
131+ } ) => ( {
132+ captchaToken,
133+ url,
134+ } ) ) ;
135+ } ,
136+
137+ /**
138+ * verify captcha code
139+ * @param {String } code the code from user input
140+ * @param {String } captchaToken captchaToken returned by {@link AV.Cloud.requestCaptcha}
141+ * @return {Promise.<String> } validateToken if the code is valid
142+ */
143+ verifyCaptcha ( code , captchaToken ) {
144+ return _request ( 'verifyCaptcha' , null , null , 'POST' , {
145+ captcha_code : code ,
146+ captcha_token : captchaToken ,
147+ } ) . then ( ( { validate_token : validateToken } ) => validateToken ) ;
148+ } ,
108149 } ) ;
109150} ;
0 commit comments