Change email handling and logout function

This commit is contained in:
Dane Everitt 2018-06-16 14:30:20 -07:00
parent ca0c35bf82
commit fce394f6bd
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
6 changed files with 18 additions and 42 deletions

View file

@ -23,7 +23,7 @@
</a>
</li>
<li>
<a :href="this.route('auth.logout')">
<a :href="this.route('auth.logout')" v-on:click.prevent="doLogout">
<log-out-icon aria-label="Sign out"/>
</a>
</li>
@ -37,6 +37,12 @@
export default {
name: 'navigation',
components: { LogOutIcon, ServerIcon, SettingsIcon, UserIcon }
components: { LogOutIcon, ServerIcon, SettingsIcon, UserIcon },
methods: {
doLogout: function () {
this.$store.commit('auth/logout');
return window.location = this.route('auth.logout');
},
}
};
</script>

View file

@ -16,12 +16,6 @@
v-model="password"
>
</div>
<div class="mt-6">
<label for="grid-password-confirm" class="input-label">Confirm password</label>
<input id="grid-password-confirm" name="password_confirmation" type="password" class="input" required
v-model="confirm"
>
</div>
<div class="mt-6 text-right">
<button class="btn btn-blue btn-sm text-right" type="submit">Save</button>
</div>
@ -31,6 +25,7 @@
</template>
<script>
import _ from 'lodash';
import { mapState, mapActions } from 'vuex';
export default {
@ -39,7 +34,6 @@
return {
email: '',
password: '',
confirm: '',
};
},
computed: {
@ -56,11 +50,11 @@
this.clearFlashes();
this.updateEmail({
email: this.$data.email,
password: this.$data.password,
confirm: this.$data.confirm,
password: this.$data.password
})
.then(() => {
this.success('Your email address has been updated.');
this.$data.password = '';
})
.catch(error => {
if (!error.response) {

View file

@ -1,4 +1,5 @@
import User from './../../models/user';
const route = require('./../../../../../vendor/tightenco/ziggy/src/js/route').default;
export default {
@ -56,37 +57,17 @@ export default {
});
},
/**
* Log a user out of the Panel.
*
* @param commit
* @returns {Promise<any>}
*/
logout: function ({commit}) {
return new Promise((resolve, reject) => {
window.axios.get(route('auth.logout'))
.then(() => {
commit('logout');
return resolve();
})
.catch(reject);
})
},
/**
* Update a user's email address on the Panel and store the updated result in Vuex.
*
* @param commit
* @param {String} email
* @param {String} password
* @param {String} confirm
* @return {Promise<any>}
*/
updateEmail: function ({commit}, {email, password, confirm}) {
updateEmail: function ({commit}, {email, password}) {
return new Promise((resolve, reject) => {
window.axios.put(route('api.client.account.update-email'), {
email, password, password_confirmation: confirm
})
window.axios.put(route('api.client.account.update-email'), {email, password})
.then(response => {
// If there is a 302 redirect or some other odd behavior (basically, response that isnt
// in JSON format) throw an error and don't try to continue with the login.