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
diff options
context:
space:
mode:
-rw-r--r--js/components/GatewaySettings.vue9
-rw-r--r--js/service/registration.js11
-rw-r--r--lib/Controller/SettingsController.php16
-rw-r--r--lib/Provider/State.php1
4 files changed, 32 insertions, 5 deletions
diff --git a/js/components/GatewaySettings.vue b/js/components/GatewaySettings.vue
index dbbe4d9..119ec0b 100644
--- a/js/components/GatewaySettings.vue
+++ b/js/components/GatewaySettings.vue
@@ -1,5 +1,9 @@
<template>
- <div v-if="loading">
+ <div v-if="!isAvailable">
+ <L10n text="The {displayName} gateway is not configured."
+ :options="{displayName: displayName}" />
+ </div>
+ <div v-else-if="loading">
<span class="icon-loading-small"></span>
</div>
<div v-else>
@@ -57,6 +61,7 @@
return {
loading: true,
state: 0,
+ isAvailable: true,
phoneNumber: '',
confirmationCode: '',
identifier: '',
@@ -66,6 +71,8 @@
mounted: function () {
getState(this.gatewayName)
.then(res => {
+ console.debug('loaded state for gateway ' + this.gatewayName, res);
+ this.isAvailable = res.isAvailable;
this.state = res.state;
this.phoneNumber = res.phoneNumber;
this.loading = false;
diff --git a/js/service/registration.js b/js/service/registration.js
index 16a686c..d65c6a7 100644
--- a/js/service/registration.js
+++ b/js/service/registration.js
@@ -7,7 +7,16 @@ export function getState (gateway) {
return nc_fetch_json(url).then(function (resp) {
if (resp.ok) {
- return resp.json()
+ return resp.json().then(json => {
+ json.isAvailable = true
+ return json
+ })
+ }
+ if (resp.status === 503) {
+ console.info(gateway + ' gateway is not available')
+ return {
+ isAvailable: false
+ }
}
throw resp
})
diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php
index 993db46..eda13e3 100644
--- a/lib/Controller/SettingsController.php
+++ b/lib/Controller/SettingsController.php
@@ -25,6 +25,7 @@
namespace OCA\TwoFactorGateway\Controller;
use OCA\TwoFactorGateway\Exception\VerificationException;
+use OCA\TwoFactorGateway\Service\Gateway\Factory as GatewayFactory;
use OCA\TwoFactorGateway\Service\SetupService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
@@ -40,12 +41,18 @@ class SettingsController extends Controller {
/** @var SetupService */
private $setup;
- public function __construct(IRequest $request, IUserSession $userSession,
- SetupService $setup) {
+ /** @var GatewayFactory */
+ private $gatewayFactory;
+
+ public function __construct(IRequest $request,
+ IUserSession $userSession,
+ SetupService $setup,
+ GatewayFactory $gatewayFactory) {
parent::__construct('twofactor_gateway', $request);
$this->userSession = $userSession;
$this->setup = $setup;
+ $this->gatewayFactory = $gatewayFactory;
}
/**
@@ -58,6 +65,11 @@ class SettingsController extends Controller {
return new JSONResponse(null, Http::STATUS_BAD_REQUEST);
}
+ $gatewayConfig = $this->gatewayFactory->getGateway($gateway)->getConfig();
+ if (!$gatewayConfig->isComplete()) {
+ return new JSONResponse(null, Http::STATUS_SERVICE_UNAVAILABLE);
+ }
+
return new JSONResponse($this->setup->getState($user, $gateway));
}
diff --git a/lib/Provider/State.php b/lib/Provider/State.php
index 2b4ae0b..ae0db6a 100644
--- a/lib/Provider/State.php
+++ b/lib/Provider/State.php
@@ -25,7 +25,6 @@
namespace OCA\TwoFactorGateway\Provider;
use JsonSerializable;
-use OCA\TwoFactorGateway\Service\Gateway\IGateway;
use OCP\IUser;
class State implements JsonSerializable {