Browse Source

allow user to save default options in localStorage

fix https://github.com/lesspass/lesspass/issues/112
fix https://github.com/lesspass/lesspass/issues/72
pull/342/head
Guillaume Vincent 8 years ago
parent
commit
e1516b658a
2 changed files with 28 additions and 9 deletions
  1. +10
    -4
      src/store.js
  2. +18
    -5
      src/views/PasswordGenerator.vue

+ 10
- 4
src/store.js View File

@@ -22,6 +22,7 @@ const defaultPassword = {
length: 12, length: 12,
counter: 1 counter: 1
}; };

function getDefaultPasswordProfile(version, passwordProfile = {}) { function getDefaultPasswordProfile(version, passwordProfile = {}) {
if (version === 1) { if (version === 1) {
return Object.assign({}, defaultPassword, passwordProfile, {version: 1, length: 12}); return Object.assign({}, defaultPassword, passwordProfile, {version: 1, length: 12});
@@ -31,7 +32,7 @@ function getDefaultPasswordProfile(version, passwordProfile = {}) {
} }
} }


const versionLoadedByDefault = 1;
const versionLoadedByDefault = storage.json().version || 1;
const state = { const state = {
authenticated: auth.isAuthenticated(), authenticated: auth.isAuthenticated(),
email: '', email: '',
@@ -67,7 +68,7 @@ const mutations = {
} }
}, },
PASSWORD_CLEAN(state){ PASSWORD_CLEAN(state){
setTimeout(()=> {
setTimeout(() => {
state.passwordStatus = 'CLEAN'; state.passwordStatus = 'CLEAN';
}, 5000); }, 5000);
}, },
@@ -90,6 +91,11 @@ const mutations = {
state.password = getDefaultPasswordProfile(version, state.password); state.password = getDefaultPasswordProfile(version, state.password);
state.version = version; state.version = version;
}, },
SAVE_DEFAULT_OPTIONS: (state) => {
const password = new Password(state.password);
const jsonPassword = password.json();
storage.save({password: jsonPassword, version: jsonPassword.version});
}
}; };


const actions = { const actions = {
@@ -137,11 +143,11 @@ const actions = {
PasswordsAPI.get({id}).then(response => commit('SET_PASSWORD', {password: response.data})); PasswordsAPI.get({id}).then(response => commit('SET_PASSWORD', {password: response.data}));
}, },
DELETE_PASSWORD: ({commit}, {id}) => { DELETE_PASSWORD: ({commit}, {id}) => {
PasswordsAPI.remove({id}).then(()=> {
PasswordsAPI.remove({id}).then(() => {
commit('DELETE_PASSWORD', {id}); commit('DELETE_PASSWORD', {id});
}); });
}, },
LOAD_DEFAULT_PASSWORD: ({commit})=> {
LOAD_DEFAULT_PASSWORD: ({commit}) => {
commit('SET_DEFAULT_PASSWORD'); commit('SET_DEFAULT_PASSWORD');
} }
}; };


+ 18
- 5
src/views/PasswordGenerator.vue View File

@@ -130,10 +130,7 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group" v-if="showOptions">
Options
</div>
<div class="form-group" v-if="showOptions">
<div class="form-group pt-1" v-if="showOptions">
<label class="form-check-inline"> <label class="form-check-inline">
<input class="form-check-input" type="checkbox" id="lowercase" <input class="form-check-input" type="checkbox" id="lowercase"
v-model="password.lowercase"> abc v-model="password.lowercase"> abc
@@ -179,6 +176,14 @@
</div> </div>
</div> </div>
</div> </div>
<div class="form-group" v-if="showOptions">
<button type="button" class="btn btn-secondary btn-sm" v-on:click="saveDefault">
save as default
</button>
<span class="text-success" v-if="optionsSaved">
<i class="fa fa-check" aria-hidden="true"></i>
</span>
</div>
<div class="form-group" v-if="showError"> <div class="form-group" v-if="showError">
<div class="alert alert-danger" role="alert"> <div class="alert alert-danger" role="alert">
site, login and master password fields are mandatory site, login and master password fields are mandatory
@@ -254,7 +259,8 @@
cleanTimeout: null, cleanTimeout: null,
showOptions: false, showOptions: false,
showError: false, showError: false,
generatingPassword: false
generatingPassword: false,
optionsSaved: false,
} }
}, },
watch: { watch: {
@@ -393,6 +399,13 @@
}, },
incrementCounter(){ incrementCounter(){
this.password.counter += 1 this.password.counter += 1
},
saveDefault(){
this.$store.commit('SAVE_DEFAULT_OPTIONS');
this.optionsSaved = true;
setTimeout(() => {
this.optionsSaved = false;
}, 3000);
} }
} }
} }


Loading…
Cancel
Save