register-users.js 1.4 KB

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