From a23a7ea370af88bc51627f2a82ff9fe8ed837c73 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Mon, 7 May 2018 10:31:13 +0200 Subject: Finish basic impl Signed-off-by: Christoph Wurst --- js/service/registration.js | 56 ++++++++++++++++++++++++++++++++++++++-------- js/view/settings.vue | 35 ++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 20 deletions(-) (limited to 'js') 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 @@