diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/service/registration.js | 56 | ||||
-rw-r--r-- | js/view/settings.vue | 35 |
2 files changed, 71 insertions, 20 deletions
diff --git a/js/service/registration.js b/js/service/registration.js index be9f019..eee2dd4 100644 --- a/js/service/registration.js +++ b/js/service/registration.js @@ -1,17 +1,55 @@ import $ from 'jquery'; +import fetch from 'nextcloud_fetch'; + +export function getState() { + let url = OC.generateUrl('/apps/twofactor_sms/settings/verification') + + return fetch(url, { + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + } + }).then(function (resp) { + if (resp.ok) { + return resp.json(); + } + throw resp; + }) +} export function startVerification() { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve(); - }, 2000); + let url = OC.generateUrl('/apps/twofactor_sms/settings/verification/start') + + return fetch(url, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + } + }).then(function (resp) { + if (resp.ok) { + return resp.json(); + } + throw resp; }) } -export function tryVerification() { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve(); - }, 2000); +export function tryVerification(code) { + let url = OC.generateUrl('/apps/twofactor_sms/settings/verification/finish') + + return fetch(url, { + method: 'POST', + body: JSON.stringify({ + verificationCode: code + }), + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + } + }).then(function (resp) { + if (resp.ok) { + return resp.json(); + } + throw resp; }) } diff --git a/js/view/settings.vue b/js/view/settings.vue index 5992105..b58f7ee 100644 --- a/js/view/settings.vue +++ b/js/view/settings.vue @@ -24,37 +24,50 @@ <script> import l10n from "view/l10n.vue"; -import { startVerification, tryVerification } from "service/registration"; +import { + getState, + startVerification, + tryVerification +} from "service/registration"; export default { data() { return { - loading: false, + loading: true, state: 0, phoneNumber: "12344556", confirmationCode: "" }; }, + mounted: function() { + getState() + .then(res => { + this.state = res.state; + this.phoneNumber = res.phoneNumber; + this.loading = false; + }) + .catch(console.error.bind(this)); + }, methods: { enable: function() { this.loading = true; - startVerification().then( - function() { + startVerification() + .then(res => { this.state = 1; + this.phoneNumber = res.phoneNumber; this.loading = false; - }.bind(this) - ); + }) + .catch(console.error.bind(this)); }, confirm: function() { this.loading = true; - console.error(this.confirmationCode); - tryVerification().then( - function() { + tryVerification(this.confirmationCode) + .then(res => { this.state = 2; this.loading = false; - }.bind(this) - ); + }) + .catch(console.error.bind(this)); } }, components: { |