register-users.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-undef,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS101: Remove unnecessary use of Array.from
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  13. */
  14. define(['base'], App =>
  15. App.controller('RegisterUsersController', function($scope, queuedHttp) {
  16. $scope.users = []
  17. $scope.inputs = { emails: '' }
  18. const parseEmails = function(emailsString) {
  19. const regexBySpaceOrComma = /[\s,]+/
  20. let emails = emailsString.split(regexBySpaceOrComma)
  21. emails = _.map(emails, email => (email = email.trim()))
  22. emails = _.filter(emails, email => email.indexOf('@') !== -1)
  23. return emails
  24. }
  25. return ($scope.registerUsers = function() {
  26. const emails = parseEmails($scope.inputs.emails)
  27. $scope.error = false
  28. return Array.from(emails).map(email =>
  29. queuedHttp
  30. .post('/admin/register', {
  31. email,
  32. _csrf: window.csrfToken
  33. })
  34. .then(function(response) {
  35. const { data } = response
  36. const user = data
  37. $scope.users.push(user)
  38. return ($scope.inputs.emails = '')
  39. })
  40. .catch(() => ($scope.error = true))
  41. )
  42. })
  43. }))