| Total Complexity | 14 |
| Complexity/F | 1.56 |
| Lines of Code | 74 |
| Function Count | 9 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import {nc_fetch_json} from 'nextcloud_fetch'; |
||
| 2 | |||
| 3 | export function getState (gateway) { |
||
| 4 | let url = OC.generateUrl('/apps/twofactor_gateway/settings/{gateway}/verification', { |
||
|
|
|||
| 5 | gateway: gateway |
||
| 6 | }) |
||
| 7 | |||
| 8 | return nc_fetch_json(url).then(function (resp) { |
||
| 9 | if (resp.ok) { |
||
| 10 | return resp.json().then(json => { |
||
| 11 | json.isAvailable = true |
||
| 12 | return json |
||
| 13 | }) |
||
| 14 | } |
||
| 15 | if (resp.status === 503) { |
||
| 16 | console.info(gateway + ' gateway is not available') |
||
| 17 | return { |
||
| 18 | isAvailable: false |
||
| 19 | } |
||
| 20 | } |
||
| 21 | throw resp |
||
| 22 | }) |
||
| 23 | } |
||
| 24 | |||
| 25 | export function startVerification (gateway, identifier) { |
||
| 26 | let url = OC.generateUrl('/apps/twofactor_gateway/settings/{gateway}/verification/start', { |
||
| 27 | gateway: gateway |
||
| 28 | }) |
||
| 29 | |||
| 30 | return nc_fetch_json(url, { |
||
| 31 | method: 'POST', |
||
| 32 | body: JSON.stringify({ |
||
| 33 | identifier: identifier |
||
| 34 | }) |
||
| 35 | }).then(function (resp) { |
||
| 36 | if (resp.ok) { |
||
| 37 | return resp.json(); |
||
| 38 | } |
||
| 39 | throw resp; |
||
| 40 | }) |
||
| 41 | } |
||
| 42 | |||
| 43 | export function tryVerification (gateway, code) { |
||
| 44 | let url = OC.generateUrl('/apps/twofactor_gateway/settings/{gateway}/verification/finish', { |
||
| 45 | gateway: gateway |
||
| 46 | }) |
||
| 47 | |||
| 48 | return nc_fetch_json(url, { |
||
| 49 | method: 'POST', |
||
| 50 | body: JSON.stringify({ |
||
| 51 | verificationCode: code |
||
| 52 | }) |
||
| 53 | }).then(function (resp) { |
||
| 54 | if (resp.ok) { |
||
| 55 | return resp.json(); |
||
| 56 | } |
||
| 57 | throw resp; |
||
| 58 | }) |
||
| 59 | } |
||
| 60 | |||
| 61 | export function disable (gateway) { |
||
| 62 | let url = OC.generateUrl('/apps/twofactor_gateway/settings/{gateway}/verification', { |
||
| 63 | gateway: gateway |
||
| 64 | }) |
||
| 65 | |||
| 66 | return nc_fetch_json(url, { |
||
| 67 | method: 'DELETE' |
||
| 68 | }).then(function (resp) { |
||
| 69 | if (resp.ok) { |
||
| 70 | return resp.json(); |
||
| 71 | } |
||
| 72 | throw resp; |
||
| 73 | }) |
||
| 74 | } |
||
| 75 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.