diff options
-rw-r--r-- | js/service/registration.js | 13 | ||||
-rw-r--r-- | js/view/settings.vue | 16 | ||||
-rw-r--r-- | lib/Controller/SettingsController.php | 2 | ||||
-rw-r--r-- | lib/Service/SetupService.php | 11 | ||||
-rw-r--r-- | package-lock.json | 4 |
5 files changed, 41 insertions, 5 deletions
diff --git a/js/service/registration.js b/js/service/registration.js index a6aa230..dddfc26 100644 --- a/js/service/registration.js +++ b/js/service/registration.js @@ -40,3 +40,16 @@ export function tryVerification(code) { throw resp; }) } + +export function disable() { + let url = OC.generateUrl('/apps/twofactor_sms/settings/verification') + + return nc_fetch_json(url, { + method: 'DELETE' + }).then(function (resp) { + if (resp.ok) { + return resp.json(); + } + throw resp; + }) +} diff --git a/js/view/settings.vue b/js/view/settings.vue index b58f7ee..bdf6973 100644 --- a/js/view/settings.vue +++ b/js/view/settings.vue @@ -17,6 +17,7 @@ </p> <p v-if="state === 2"> <l10n text="SMS-based two-factor authentication is enabled for your account."></l10n> + <button @click="disable"><l10n text="Disable"></l10n></button> </p> </div> </div> @@ -27,7 +28,8 @@ import l10n from "view/l10n.vue"; import { getState, startVerification, - tryVerification + tryVerification, + disable } from "service/registration"; export default { @@ -68,6 +70,18 @@ export default { this.loading = false; }) .catch(console.error.bind(this)); + }, + + disable: function() { + this.loading = true; + + disable() + .then(res => { + this.state = res.state; + this.phoneNumber = res.phoneNumber; + this.loading = false; + }) + .catch(console.error.bind(this)); } }, components: { diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 660cb54..3cc4a2a 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -108,7 +108,7 @@ class SettingsController extends Controller { return new JSONResponse(null, Http::STATUS_BAD_REQUEST); } - return new JSONResponse([]); + return new JSONResponse($this->setup->disable($user)); } } diff --git a/lib/Service/SetupService.php b/lib/Service/SetupService.php index eae80be..65a124a 100644 --- a/lib/Service/SetupService.php +++ b/lib/Service/SetupService.php @@ -98,7 +98,7 @@ class SetupService { } $num = $userData[AccountManager::PROPERTY_PHONE]['value']; - + if (is_null($num) || empty($num)) { throw new PhoneNumberMissingException('phone number is empty'); } @@ -146,4 +146,13 @@ class SetupService { 'verified', 'true'); } + public function disable(IUser $user) { + $this->config->deleteUserValue($user->getUID(), Application::APP_NAME, + 'verified'); + $this->config->deleteUserValue($user->getUID(), Application::APP_NAME, + 'verification_code'); + + return $this->getState($user); + } + } diff --git a/package-lock.json b/package-lock.json index 688dac7..ca808fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3538,8 +3538,8 @@ "dev": true, "optional": true, "requires": { - "os-homedir": "1.0.2", - "os-tmpdir": "1.0.2" + "os-homedir": "^1.0.0", + "os-tmpdir": "^1.0.0" } }, "path-is-absolute": { |