From: Adam Dullage Date: Fri, 14 Oct 2022 12:20:58 +0000 (+0100) Subject: Implemented TOTP in frontend X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=3b96faea0bb872fa979a96de0aa9a9a239aa8242;p=flatnotes.git Implemented TOTP in frontend --- diff --git a/flatnotes/src/components/App.js b/flatnotes/src/components/App.js index fb7087f..ececa96 100644 --- a/flatnotes/src/components/App.js +++ b/flatnotes/src/components/App.js @@ -47,9 +47,16 @@ export default { methods: { loadConfig: function() { let parent = this; - api.get("/api/config").then(function(response) { - parent.authType = constants.authTypes[response.data.authType]; - }); + api + .get("/api/config") + .then(function(response) { + parent.authType = response.data.authType; + }) + .catch(function(error) { + if (!error.handled) { + parent.unhandledServerErrorToast(); + } + }); }, route: function() { diff --git a/flatnotes/src/components/Login.vue b/flatnotes/src/components/Login.vue index 11a3f68..c34b887 100644 --- a/flatnotes/src/components/Login.vue +++ b/flatnotes/src/components/Login.vue @@ -1,55 +1,77 @@ @@ -67,13 +89,14 @@ export default { }, props: { - authType: { type: Number, default: null }, + authType: { type: String, default: null }, }, data: function () { return { usernameInput: null, passwordInput: null, + totpInput: null, rememberMeInput: false, }; }, @@ -97,7 +120,10 @@ export default { api .post("/api/token", { username: this.usernameInput, - password: this.passwordInput, + password: + this.authType == constants.authTypes.totp + ? this.passwordInput + this.totpInput + : this.passwordInput, }) .then(function (response) { sessionStorage.setItem("token", response.data.access_token); @@ -114,7 +140,7 @@ export default { typeof error.response !== "undefined" && [400, 422].includes(error.response.status) ) { - parent.$bvToast.toast("Incorrect Username or Password ✘", { + parent.$bvToast.toast("Incorrect login credentials ✘", { variant: "danger", noCloseButton: true, toaster: "b-toaster-bottom-right", @@ -126,12 +152,14 @@ export default { .finally(function () { parent.usernameInput = null; parent.passwordInput = null; + parent.totpInput = null; parent.rememberMeInput = false; }); }, }, created: function () { + this.constants = constants; this.skipIfNoneAuthType(); }, }; diff --git a/flatnotes/src/components/SearchInput.vue b/flatnotes/src/components/SearchInput.vue index dec533a..8c49657 100644 --- a/flatnotes/src/components/SearchInput.vue +++ b/flatnotes/src/components/SearchInput.vue @@ -4,6 +4,7 @@