request-link.js 1.3 KB

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