change-form.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import Ember from 'ember';
  2. import rpc from 'misago/utils/rpc';
  3. export default Ember.ObjectController.extend({
  4. isLoading: false,
  5. password: '',
  6. actions: {
  7. submit: function() {
  8. if (this.get('isLoading')) {
  9. return;
  10. }
  11. var password = Ember.$.trim(this.get('password'));
  12. if (password === "") {
  13. this.get('toast').warning(gettext("Enter new password."));
  14. return;
  15. }
  16. this.set('isLoading', true);
  17. var self = this;
  18. rpc(this.get('change_password_url'), {
  19. password: password
  20. }).then(function() {
  21. self.send('success');
  22. }, function(jqXHR) {
  23. self.send('error', jqXHR);
  24. }).finally(function() {
  25. self.set('isLoading', false);
  26. });
  27. },
  28. success: function() {
  29. this.set('password', '');
  30. this.send('openLoginModal');
  31. this.get('toast').success(gettext("Your password has been changed."));
  32. },
  33. error: function(jqXHR) {
  34. var rejection = jqXHR.responseJSON;
  35. if (jqXHR.status === 400){
  36. this.get('toast').error(rejection.detail);
  37. } else {
  38. if (jqXHR.status === 404) {
  39. this.get('toast').error(rejection.detail);
  40. this.transitionTo('forgotten-password');
  41. } else {
  42. this.send('toastError', jqXHR);
  43. }
  44. }
  45. }
  46. }
  47. });