Browse Source

Fix saving multiple profiles with same sites

Fixes: https://github.com/lesspass/lesspass/issues/279
pull/342/head
Guillaume Vincent 7 years ago
parent
commit
ead22087c6
3 changed files with 21 additions and 18 deletions
  1. +2
    -6
      src/components/Menu.vue
  2. +11
    -10
      src/store/actions.js
  3. +8
    -2
      src/store/index.js

+ 2
- 6
src/components/Menu.vue View File

@@ -45,7 +45,7 @@
</div> </div>
</template> </template>
<script type="text/ecmascript-6"> <script type="text/ecmascript-6">
import {mapState, mapGetters} from 'vuex';
import {mapGetters} from 'vuex';


export default { export default {
data() { data() {
@@ -55,7 +55,7 @@
}, },
methods: { methods: {
fullReload() { fullReload() {
this.$store.dispatch('savePassword', {password: this.defaultPassword});
this.$store.dispatch('savePassword', {password: this.$store.state.defaultPassword});
this.$router.push({name: 'home'}); this.$router.push({name: 'home'});
}, },
logout() { logout() {
@@ -71,10 +71,6 @@
} }
}, },
computed: { computed: {
...mapState([
'password',
'defaultPassword'
]),
...mapGetters([ ...mapGetters([
'isAuthenticated', 'isAuthenticated',
'isGuest' 'isGuest'


+ 11
- 10
src/store/actions.js View File

@@ -67,17 +67,18 @@ export const getPasswords = ({ commit, state }) => {
}; };


export const saveOrUpdatePassword = ({ commit, state }) => { export const saveOrUpdatePassword = ({ commit, state }) => {
if (state.password && typeof state.password.id === "undefined") {
const site = state.password.site;
const login = state.password.login;
if (site || login) {
Password.create(state.password, state).then(response => {
savePassword({ commit }, { password: response.data });
getPasswords({ commit, state });
});
}
const site = state.password.site;
const login = state.password.login;
const existingPassword = state.passwords.find(password => {
return password.site === site && password.login === login;
});
if (existingPassword) {
const newPassword = Object.assign({}, existingPassword, state.password);
Password.update(newPassword, state).then(() => {
getPasswords({ commit, state });
});
} else { } else {
Password.update(state.password, state).then(() => {
Password.create(state.password, state).then(() => {
getPasswords({ commit, state }); getPasswords({ commit, state });
}); });
} }


+ 8
- 2
src/store/index.js View File

@@ -10,8 +10,9 @@ Vue.use(Vuex);


const state = { const state = {
authenticated: false, authenticated: false,
password: defaultPassword,
password: Object.assign({}, defaultPassword),
passwords: [], passwords: [],
message: "",
defaultPassword: defaultPassword, defaultPassword: defaultPassword,
showOptions: false, showOptions: false,
token: null, token: null,
@@ -23,5 +24,10 @@ export default new Vuex.Store({
getters, getters,
actions, actions,
mutations, mutations,
plugins: [createPersistedState({ key: "lesspass" })]
plugins: [
createPersistedState({
key: "lesspass",
paths: ["token", "baseURL", "authenticated", "defaultPassword"]
})
]
}); });

Loading…
Cancel
Save