# Captcha

## AV. Captcha

#### new Captcha()

Source:
  - captcha.js, line 19

##### Example

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

### Members

#### captchaToken :string

Source:
  - captcha.js, line 31

The captchaToken of the captcha.

##### Type:

- string

#### url :string

Source:
  - captcha.js, line 26

The image url of the captcha

##### Type:

- string

#### validateToken :string

Source:
  - captcha.js, line 36

The validateToken of the captcha.

##### Type:

- string

### Methods

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

Source:
  - captcha.js, line 145

Request a captcha

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---

`options`

<optional>

###### Properties

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`width` | Number | <optional> |  | width(px) of the captcha, ranged 60-200
`height` | Number | <optional> |  | height(px) of the captcha, ranged 30-100
`size` | Number | <optional> | `4` | length of the captcha, ranged 3-6. MasterKey required.
`ttl` | Number | <optional> | `60` | time to live(s), ranged 10-180. MasterKey required.

##### Returns:

Type
  Promise.<AV.Captcha>

#### bind(elementsopt, callbacksopt)

Source:
  - captcha.js, line 74

Bind the captcha to HTMLElements. ONLY AVAILABLE in browsers.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---

`elements`

<optional>

###### Properties

Name | Type | Attributes | Description
--- | --- | --- | ---
`textInput` | String | HTMLInputElement | <optional> | An input element typed text, or the id for the element.
`image` | String | HTMLImageElement | <optional> | An image element, or the id for the element.
`verifyButton` | String | HTMLElement | <optional> | A button element, or the id for the element.

`callbacks`

<optional>

###### Properties

Name | Type | Attributes | Description
--- | --- | --- | ---
`success` | function | <optional> | Success callback will be called if the code is verified. The param `validateCode` can be used for further SMS request.
`error` | function | <optional> | Error callback will be called if something goes wrong, detailed in param `error.message`.

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

Source:
  - captcha.js, line 43

Refresh the captcha

##### Returns:

a new capcha url

Type
  Promise.<string>

#### unbind()

Source:
  - captcha.js, line 128

unbind the captcha from HTMLElements. ONLY AVAILABLE in browsers.

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

Source:
  - captcha.js, line 57

Verify the captcha

##### Parameters:

Name | Type | Description
--- | --- | ---
`code` | String | The code from user input

##### Returns:

validateToken if the code is valid

Type
  Promise.<string>