Sfoglia il codice sorgente

WIP. change password almost working

pull/1/head
Jonathan Cobb 4 anni fa
parent
commit
194dbc0054
3 ha cambiato i file con 80 aggiunte e 5 eliminazioni
  1. +10
    -0
      src/_services/user.service.js
  2. +35
    -3
      src/_store/users.module.js
  3. +35
    -2
      src/account/profile/ChangePasswordPage.vue

+ 10
- 0
src/_services/user.service.js Vedi File

@@ -19,6 +19,8 @@ export const userService = {
createUser,
updateUser,
deleteUser,
changePassword,
adminChangePassword,
approveAction,
denyAction,
sendAuthenticatorCode,
@@ -160,6 +162,14 @@ function deleteUser(userId, messages, errors) {
return fetch(`${config.apiUrl}/users/${userId}`, util.deleteWithAuth()).then(util.handleCrudResponse(messages, errors));
}

function changePassword(request, messages, errors) {
return fetch(`${config.apiUrl}/me/changePassword`, util.postWithAuth(request)).then(util.handleCrudResponse(messages, errors));
}

function adminChangePassword(userId, request, messages, errors) {
return fetch(`${config.apiUrl}/users/${userId}/changePassword`, util.postWithAuth(request)).then(util.handleCrudResponse(messages, errors));
}

function handleAuthResponse(messages, errors) {
return function (response) {
return response.text().then(text => {


+ 35
- 3
src/_store/users.module.js Vedi File

@@ -4,7 +4,7 @@ import { util } from '../_helpers';

const state = {
loading: {
users: false, user: false, creating: false, updating: false, deleting: false,
users: false, user: false, creating: false, updating: false, deleting: false, changingPassword: false,
policy: false, updatingPolicy: false, addPolicyContact: false, removePolicyContact: false,
listSshKeys: false, addSshKey: false, removeSshKey: false
},
@@ -15,7 +15,8 @@ const state = {
contact: null,
authenticator: {},
sshKey: null,
sshKeys: []
sshKeys: [],
changePasswordResponse: null
};

export const CONTACT_TYPE_AUTHENTICATOR = 'authenticator';
@@ -166,9 +167,28 @@ const actions = {
userService.deleteUser(userId, messages, errors)
.then(
id => commit('deleteSuccess', id),
error => commit('deleteFailure', { id, error: error.toString() })
error => commit('deleteFailure', { userId, error: error.toString() })
);
},

changePassword({ commit }, {request, messages, errors}) {
commit('changePasswordRequest', request);
userService.changePasswordUser(request, messages, errors)
.then(
response => commit('changePasswordSuccess', response),
error => commit('changePasswordFailure', { error: error.toString() })
);
},

adminChangePassword({ commit }, {userId, request, messages, errors}) {
commit('changePasswordRequest', userId);
userService.adminChangePassword(userId, request, messages, errors)
.then(
id => commit('changePasswordSuccess', id),
error => commit('changePasswordFailure', { error: error.toString() })
);
}

};

const mutations = {
@@ -339,6 +359,18 @@ const mutations = {
deleteFailure(state, { id, error }) {
state.loading.deleting = false;
state.errors.deleteUser = error;
},

changePasswordRequest(state, id) {
state.loading.changingPassword = true;
},
changePasswordSuccess(state, response) {
state.loading.changingPassword = false;
state.changePasswordResponse = response;
},
changePasswordFailure(state, { error }) {
state.loading.deleting = false;
state.errors.changePassword = error;
}
};



+ 35
- 2
src/account/profile/ChangePasswordPage.vue Vedi File

@@ -66,7 +66,7 @@
}
},
computed: {
...mapState('users', ['user', 'policy']),
...mapState('users', ['user', 'policy', 'changePasswordResponse']),
...mapState('system', ['messages']),
requiredExternalAuthContacts () {
const contacts = [];
@@ -88,7 +88,7 @@
}
},
methods: {
...mapActions('users', ['getPolicyByUserId', 'changePassword']),
...mapActions('users', ['getUserById', 'getPolicyByUserId', 'changePassword', 'adminChangePassword']),
...mapGetters('users', ['loading']),
authenticatorRequired (p) {
if (p && p.accountContacts && p.accountContacts.length > 0) {
@@ -104,6 +104,32 @@
changePass (e) {
this.submitted = true;
this.errors.clear();
// todo: validate that newPassword and newPasswordConfirm match
if (this.me) {
this.changePassword({
request: {
oldPassword: this.currentPassword,
newPassword: this.newPassword,
totpToken: this.totpToken
},
messages: this.messages,
errors: this.errors
});
} else if (this.currentUser.admin) {
this.adminChangePassword({
userId: this.userId,
request: {
oldPassword: this.currentPassword,
newPassword: this.newPassword,
totpToken: this.totpToken
},
messages: this.messages,
errors: this.errors
});
} else {
// should never happen
console.warn('Not current user and not admin, API call would fail anyway, not sending');
}
console.log('changePass called');
}
},
@@ -140,6 +166,13 @@
this.getUserById({userId: this.userId, messages: this.messages, errors: this.errors});
this.getPolicyByUserId({userId: this.userId, messages: this.messages, errors: this.errors});
}
},
watch: {
changePasswordResponse (r) {
if (r) {
console.log('watch.changePasswordResponse: received '+JSON.stringify(r));
}
}
}
};
</script>

Caricamento…
Annulla
Salva