From 02ec6b61675f751fb5e63f08fa8a4582b0601f7c Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Fri, 21 Apr 2017 18:12:36 +0200 Subject: [PATCH] Open options if different from default options https://github.com/lesspass/lesspass/issues/187 --- src/store/defaultPassword.js | 15 +++++++++++++++ src/store/getters.js | 11 +++++++++++ src/store/index.js | 13 +------------ src/views/PasswordGenerator.vue | 3 +-- test/store.getters.js | 29 +++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 src/store/defaultPassword.js diff --git a/src/store/defaultPassword.js b/src/store/defaultPassword.js new file mode 100644 index 0000000..79f0e1e --- /dev/null +++ b/src/store/defaultPassword.js @@ -0,0 +1,15 @@ +export const defaultOptions = { + uppercase: true, + lowercase: true, + numbers: true, + symbols: true, + length: 16, + counter: 1, + version: 2 +}; + +export default { + login: '', + site: '', + ...defaultOptions +}; diff --git a/src/store/getters.js b/src/store/getters.js index f0eb1dd..f73fa99 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -1,3 +1,5 @@ +import {defaultOptions} from './defaultPassword'; + export const passwords = state => state.passwords; export const password = state => state.password; @@ -22,3 +24,12 @@ export const version = state => { export const passwordURL = state => { return `${state.baseURL}/#/?login=${state.password.login}&site=${state.password.site}&uppercase=${state.password.uppercase}&lowercase=${state.password.lowercase}&numbers=${state.password.numbers}&symbols=${state.password.symbols}&length=${state.password.length}&counter=${state.password.counter}&version=${state.password.version}`; }; + +export const optionsDifferentFromDefault = state => { + for(let key in defaultOptions){ + if (defaultOptions[key] !== state.password[key]) { + return true; + } + } + return false; +}; diff --git a/src/store/index.js b/src/store/index.js index 28cb96d..b5be9df 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -4,21 +4,10 @@ import * as actions from './actions' import * as getters from './getters' import mutations from './mutations' import createPersistedState from 'vuex-persistedstate'; +import defaultPassword from './defaultPassword'; Vue.use(Vuex); -const defaultPassword = { - login: '', - site: '', - uppercase: true, - lowercase: true, - numbers: true, - symbols: true, - length: 16, - counter: 1, - version: 2 -}; - const state = { authenticated: false, password: defaultPassword, diff --git a/src/views/PasswordGenerator.vue b/src/views/PasswordGenerator.vue index a1b9fc3..5d6c0e7 100644 --- a/src/views/PasswordGenerator.vue +++ b/src/views/PasswordGenerator.vue @@ -186,7 +186,7 @@ fingerprint: '', generatedPassword: '', cleanTimeout: null, - showOptions: false, + showOptions: this.$store.getters.optionsDifferentFromDefault, generatingPassword: false } }, @@ -247,7 +247,6 @@ const masterPassword = this.masterPassword; if (!site && !login || !masterPassword) { - this.showOptions = false; message.error(this.$t('SiteLoginMasterPasswordMandatory', 'Site, login, and master password fields are mandatory.')); return; } diff --git a/test/store.getters.js b/test/store.getters.js index 5fa4fd9..8b377a8 100644 --- a/test/store.getters.js +++ b/test/store.getters.js @@ -58,3 +58,32 @@ test('message', t => { t.is(message.text, state.message.text); t.is(message.status, state.message.status); }); + +test('optionsDifferentFromDefault', t => { + t.false(getters.optionsDifferentFromDefault({ + password: { + login: "test@example.org", + site: "example.org", + uppercase: true, + lowercase: true, + numbers: true, + symbols: true, + length: 16, + counter: 1, + version: 2 + } + })); + t.true(getters.optionsDifferentFromDefault({ + password: { + login: "test@example.org", + site: "example.org", + uppercase: true, + lowercase: true, + numbers: true, + symbols: false, + length: 32, + counter: 1, + version: 1 + } + })); +});