# Captcha

#### new Captcha()

Source:
  - captcha.js, line 24

##### Example

    AV.Captcha.request({
      size: 6,
      ttl: 30,
    }).then(captcha => {
      captcha.bind({
        textInput: 'code', // the id for textInput
        image: 'captcha',
        verifyButton: 'verify',
      }, {
        success: (validateCode) => {}, // next step
        fail: (error) => {}, // present error.message to user
      });
    });

### Methods

#### (static) request() → {Promise.<AV.Captcha>}

Source:
  - captcha.js, line 121

Request a captcha

##### Returns:

Type
  Promise.<AV.Captcha>

#### bind()

Source:
  - captcha.js, line 59

Bind the captcha to HTMLElements. ONLY available in browser.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`elements.textInput` | String | HTMLInputElement | <optional> | An input element typed text, or the id for the element.
`elements.image` | String | HTMLInputElement | <optional> | An image element, or the id for the element.
`elements.verifyButton` | String | HTMLInputElement | <optional> | A button element, or the id for the element.
`callbacks.success` | function | <optional> | success callback will be called if the code is verified. The param `validateCode` can be used for further SMS request.
`callbacks.fail` | function | <optional> | fail callback will be called if something goes wrong, detailed in param `error.message`.

#### refresh() → {Promise.<string>}

Source:
  - captcha.js, line 32

Refresh the captcha

##### Returns:

a new capcha url

Type
  Promise.<string>

#### unbind()

Source:
  - captcha.js, line 109

unbind the captcha to HTMLElements. ONLY available in browser.

#### verify() → {Promise.<string>}

Source:
  - captcha.js, line 45

Verify the captcha

##### Returns:

validateToken if the code is valid

Type
  Promise.<string>