Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/twofactor_gateway.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2018-05-07 11:31:13 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2018-05-07 11:31:13 +0300
commita23a7ea370af88bc51627f2a82ff9fe8ed837c73 (patch)
tree13cfe0eb8d21a643431747fe1ef08e70c89d5503 /js
parent677968dc76a12d3347c2fe173eb6020733f77cdc (diff)
Finish basic impl
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'js')
-rw-r--r--js/service/registration.js56
-rw-r--r--js/view/settings.vue35
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: {