request-link.js 1.3 KB

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