Browse Source

Open options if different from default options

https://github.com/lesspass/lesspass/issues/187
pull/342/head
Guillaume Vincent 7 years ago
parent
commit
02ec6b6167
5 changed files with 57 additions and 14 deletions
  1. +15
    -0
      src/store/defaultPassword.js
  2. +11
    -0
      src/store/getters.js
  3. +1
    -12
      src/store/index.js
  4. +1
    -2
      src/views/PasswordGenerator.vue
  5. +29
    -0
      test/store.getters.js

+ 15
- 0
src/store/defaultPassword.js View File

@@ -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
};

+ 11
- 0
src/store/getters.js View File

@@ -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;
};

+ 1
- 12
src/store/index.js View File

@@ -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,


+ 1
- 2
src/views/PasswordGenerator.vue View File

@@ -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;
}


+ 29
- 0
test/store.getters.js View File

@@ -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
}
}));
});

Loading…
Cancel
Save