diff --git a/app/adapters/user.js b/app/adapters/user.js new file mode 100644 index 0000000000000000000000000000000000000000..facc00cabb978b3d48edc2c1ccb1be2842331bce --- /dev/null +++ b/app/adapters/user.js @@ -0,0 +1,18 @@ +import ApplicationAdapter from './application'; + + +export default class UserAdapter extends ApplicationAdapter { + + _defaultContentType = 'application/json'; + + changePassword(model, new_password) { + const url = this.buildURL('user', model.id) + 'change-password/'; + + return this.ajax(url, 'POST', { + data: { + 'password': new_password + } + }); + } + +} \ No newline at end of file diff --git a/app/components/user/change_password.hbs b/app/components/user/change_password.hbs index 3412bf4300ba4e562d6980f9a184491f595e1608..b4f74d88e2daff8d1f47d9b6847e2063ab1929fc 100644 --- a/app/components/user/change_password.hbs +++ b/app/components/user/change_password.hbs @@ -18,6 +18,8 @@ <div class="mb-3"> <Button::Submit + @text="Change Password" + @disabled={{this.disabled}} @onClick={{this.onSubmit}} /> <Button::Cancel @route="users"/> </div> diff --git a/app/components/user/change_password.js b/app/components/user/change_password.js index b356586734e45cb61ae64d1a2be76ee5d88d3545..951fc42274a57801202eae2a73d57b3e9d1d233a 100644 --- a/app/components/user/change_password.js +++ b/app/components/user/change_password.js @@ -10,11 +10,26 @@ class ChangeUserPasswordComponent extends Component { @tracked new_password_1; @tracked new_password_2; + get disabled() { + /** + * If both password inputs are empty submit button is disabled. + * Also, submit form button will be disabled if given + * passwords do not match. + */ + if (this.new_password_1 && new_password_2) { + if (this.new_password_1 === this.new_password_2) { + return false; + } + } + + return true; + } + @action onSubmit() { let user = this.args.user; - user.save(); + user.changePassword(this.new_password_1); this.router.transitionTo('users'); } } diff --git a/app/models/user.js b/app/models/user.js index 01f5c18e1748aaf741a63f349cf942fd4817d848..6b6ac8ec88c1b15b80f475856e8ea0081c44b830 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -13,6 +13,12 @@ class UserModel extends Model { @attr created_at; @attr updated_at; @belongsTo('role') role; + + changePassword(new_password) { + const adapter = this.store.adapterFor('user'); + + return adapter.changePassword(this, new_password); + } } export default UserModel;