register-users.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. import App from '../base'
  14. export default App.controller('RegisterUsersController', function(
  15. $scope,
  16. queuedHttp
  17. ) {
  18. $scope.users = []
  19. $scope.inputs = { emails: '' }
  20. const parseEmails = function(emailsString) {
  21. const regexBySpaceOrComma = /[\s,]+/
  22. let emails = emailsString.split(regexBySpaceOrComma)
  23. emails = _.map(emails, email => (email = email.trim()))
  24. emails = _.filter(emails, email => email.indexOf('@') !== -1)
  25. return emails
  26. }
  27. return ($scope.registerUsers = function() {
  28. const emails = parseEmails($scope.inputs.emails)
  29. $scope.error = false
  30. return Array.from(emails).map(email =>
  31. queuedHttp
  32. .post('/admin/register', {
  33. email,
  34. _csrf: window.csrfToken
  35. })
  36. .then(function(response) {
  37. const { data } = response
  38. const user = data
  39. $scope.users.push(user)
  40. return ($scope.inputs.emails = '')
  41. })
  42. .catch(() => ($scope.error = true))
  43. )
  44. })
  45. })