register-users.js 1.4 KB

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