Fixes: https://github.com/lesspass/lesspass/issues/279pull/342/head
@@ -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' | ||||
@@ -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 }); | ||||
}); | }); | ||||
} | } | ||||
@@ -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"] | |||||
}) | |||||
] | |||||
}); | }); |