Passed
Pull Request — master (#500)
by Vitor
04:08
created

registration.js ➔ disable   A

Complexity

Conditions 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 14
c 0
b 0
f 0
rs 9.95
cc 3
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', {
0 ignored issues
show
Bug introduced by
The variable OC seems to be never declared. If this is a global, consider adding a /** global: OC */ comment.

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.

Loading history...
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', {
0 ignored issues
show
Bug introduced by
The variable OC seems to be never declared. If this is a global, consider adding a /** global: OC */ comment.

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.

Loading history...
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', {
0 ignored issues
show
Bug introduced by
The variable OC seems to be never declared. If this is a global, consider adding a /** global: OC */ comment.

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.

Loading history...
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', {
0 ignored issues
show
Bug introduced by
The variable OC seems to be never declared. If this is a global, consider adding a /** global: OC */ comment.

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.

Loading history...
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