set-new-password-form.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import Ember from 'ember';
  2. export default Ember.Component.extend({
  3. tagName: 'form',
  4. isLoading: false,
  5. password: '',
  6. router: function() {
  7. return this.container.lookup('router:main');
  8. }.property(),
  9. url: function() {
  10. return 'change-password/' + this.get('model.user_id') + '/' + this.get('model.token');
  11. }.property('model'),
  12. submit: function() {
  13. if (this.get('isLoading')) {
  14. return false;
  15. }
  16. var password = Ember.$.trim(this.get('password'));
  17. if (password === "") {
  18. this.toast.warning(gettext("Enter new password."));
  19. return false;
  20. }
  21. this.set('isLoading', true);
  22. var self = this;
  23. this.rpc.ajax(this.get('url'), {
  24. password: password
  25. }).then(function() {
  26. self.success();
  27. }, function(jqXHR) {
  28. self.error(jqXHR);
  29. }).finally(function() {
  30. self.set('isLoading', false);
  31. });
  32. return false;
  33. },
  34. success: function() {
  35. this.set('password', '');
  36. this.auth.openLoginModal();
  37. this.toast.success(gettext("Your password has been changed."));
  38. },
  39. error: function(jqXHR) {
  40. var rejection = jqXHR.responseJSON;
  41. if (jqXHR.status === 400){
  42. this.toast.error(rejection.detail);
  43. } else {
  44. if (jqXHR.status === 404) {
  45. this.toast.error(rejection.detail);
  46. this.get('router').transitionTo('forgotten-password');
  47. } else {
  48. this.toast.apiError(jqXHR);
  49. }
  50. }
  51. }
  52. });