GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Change password form in Settings - Account by Jakoma02 · Pull Request #5089 · learningequality/studio

Change password form in Settings - Account #5089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
MisRob merged 3 commits into learningequality:unstable from Jakoma02:migrate-change-password-form
Jun 23, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

Change password form in Settings - Account #5089

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
1cf8bc6
Migrate change password form
Jakoma02 May 31, 2025
80c68f2
Do not show validation errors on open
Jakoma02 Jun 6, 2025
a7c375a
Cleanup test suite
MisRob Jun 23, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

82 changes: 44 additions & 38 deletions 82 contentcuration/contentcuration/frontend/settings/pages/Account/ChangePasswordForm.vue
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@
:title="$tr('changePasswordHeader')"
:submitText="$tr('saveChangesAction')"
:cancelText="$tr('cancelAction')"
@submit="submitPassword"
@submit="submit"
@cancel="dialog = false"
>
<!-- inline style here avoids scrollbar on validations -->
<VForm
ref="form"
style="height: 196px"
>
<PasswordField
<form ref="form">
<KTextbox
v-model="password"
:additionalRules="passwordValidationRules"
type="password"
:label="$tr('newPasswordLabel')"
:invalid="errors.password"
:invalidText="$tr('passwordValidationMessage')"
:showInvalidText="true"
/>
<PasswordField
<KTextbox
v-model="confirmation"
type="password"
:label="$tr('confirmNewPasswordLabel')"
:additionalRules="passwordConfirmRules"
:invalid="errors.confirmation"
:invalidText="$tr('formInvalidText')"
:showInvalidText="true"
/>
</VForm>
</form>
</KModal>

</template>
Expand All @@ -32,23 +34,33 @@
<script>

import { mapActions } from 'vuex';
import PasswordField from 'shared/views/form/PasswordField';
import { generateFormMixin } from 'shared/mixins';

const formMixin = generateFormMixin({
password: {
required: true,
// eslint-disable-next-line no-unused-vars
validator: (value, _vm) => {
return value.length >= 8;
},
},
confirmation: {
required: true,
validator: (value, vm) => {
return value === vm.password;
},
},
});

export default {
name: 'ChangePasswordForm',
components: { PasswordField },
mixins: [formMixin],
props: {
value: {
type: Boolean,
default: false,
},
},
data() {
return {
password: '',
confirmation: '',
};
},
computed: {
dialog: {
get() {
Expand All @@ -58,36 +70,30 @@
this.$emit('input', value);
},
},
passwordValidationRules() {
return [value => (value.length >= 8 ? true : this.$tr('passwordValidationMessage'))];
},
passwordConfirmRules() {
return [value => (this.password === value ? true : this.$tr('formInvalidText'))];
},
},
watch: {
value(value) {
// Reset values on open
if (value) {
this.password = '';
this.confirmation = '';
this.reset();
}
},
},
methods: {
...mapActions(['showSnackbar']),
...mapActions('settings', ['updateUserPassword']),
submitPassword() {
if (this.$refs.form.validate()) {
return this.updateUserPassword(this.password)
.then(() => {
this.dialog = false;
this.showSnackbar({ text: this.$tr('paswordChangeSuccess') });
})
.catch(() => {
this.showSnackbar({ text: this.$tr('passwordChangeFailed') });
});
}

// This is called from formMixin
// eslint-disable-next-line kolibri/vue-no-unused-methods, vue/no-unused-properties
onSubmit() {
return this.updateUserPassword(this.password)
.then(() => {
this.dialog = false;
this.showSnackbar({ text: this.$tr('paswordChangeSuccess') });
})
.catch(() => {
this.showSnackbar({ text: this.$tr('passwordChangeFailed') });
});
},
},
$trs: {
Expand Down
88 changes: 70 additions & 18 deletions 88 contentcuration/contentcuration/frontend/settings/pages/__tests__/changePasswordForm.spec.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,81 @@ function makeWrapper() {
}

describe('changePasswordForm', () => {
let wrapper;

beforeEach(() => {
wrapper = makeWrapper();
it('should render the form', () => {
const wrapper = makeWrapper();
expect(wrapper.html()).toContain('Change password');
expect(wrapper.html()).toContain('New password');
expect(wrapper.html()).toContain('Confirm new password');
expect(wrapper.html()).toContain('Save changes');
expect(wrapper.html()).toContain('Cancel');
});

it('validation should fail if passwords do not match', async () => {
await wrapper.setData({ password: 'test' });
expect(typeof wrapper.vm.passwordConfirmRules[0]('data')).toBe('string');
describe('if a password is too short', () => {
let updateUserPassword;
let wrapper;

beforeAll(async () => {
wrapper = makeWrapper();
updateUserPassword = jest.spyOn(wrapper.vm, 'updateUserPassword');
const passwordInputs = wrapper.findAll('input[type="password"]');
passwordInputs.at(0).setValue('pw');
wrapper.findComponent({ name: 'KModal' }).vm.$emit('submit');
await wrapper.vm.$nextTick();
});

it('should show a correct error message', () => {
expect(wrapper.html()).toContain('Password should be at least 8 characters long');
});

it('should not call updateUserPassword', () => {
expect(updateUserPassword).not.toHaveBeenCalled();
});
});

it('failed validation should not call updateUserPassword', async () => {
const updateUserPassword = jest.spyOn(wrapper.vm, 'updateUserPassword');
updateUserPassword.mockImplementation(() => Promise.resolve());
await wrapper.vm.submitPassword();
expect(updateUserPassword).not.toHaveBeenCalled();
describe(`if passwords don't match`, () => {
let updateUserPassword;
let wrapper;

beforeAll(async () => {
wrapper = makeWrapper();
updateUserPassword = jest.spyOn(wrapper.vm, 'updateUserPassword');
const passwordInputs = wrapper.findAll('input[type="password"]');
passwordInputs.at(0).setValue('password1');
passwordInputs.at(1).setValue('password2');
wrapper.findComponent({ name: 'KModal' }).vm.$emit('submit');
await wrapper.vm.$nextTick();
});

it('should show a correct error message', () => {
expect(wrapper.html()).toContain(`Passwords don't match`);
});

it('should not call updateUserPassword', () => {
expect(updateUserPassword).not.toHaveBeenCalled();
});
});

it('clicking submit should call updateUserPassword', async () => {
const updateUserPassword = jest.spyOn(wrapper.vm, 'updateUserPassword');
updateUserPassword.mockImplementation(() => Promise.resolve());
await wrapper.setData({ password: 'tester123', confirmation: 'tester123' });
await wrapper.vm.submitPassword();
expect(updateUserPassword).toHaveBeenCalled();
describe('if passwords match and are valid', () => {
let updateUserPassword;
let wrapper;

beforeAll(async () => {
wrapper = makeWrapper();
updateUserPassword = jest.spyOn(wrapper.vm, 'updateUserPassword');
const passwordInputs = wrapper.findAll('input[type="password"]');
passwordInputs.at(0).setValue('password123');
passwordInputs.at(1).setValue('password123');
wrapper.findComponent({ name: 'KModal' }).vm.$emit('submit');
await wrapper.vm.$nextTick();
});

it('should not show any error messages', () => {
expect(wrapper.html()).not.toContain('Password should be at least 8 characters long');
expect(wrapper.html()).not.toContain(`Passwords don't match`);
});

it('should call updateUserPassword', () => {
expect(updateUserPassword).toHaveBeenCalled();
});
});
});
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.