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(
  16. 'RegisterUsersController',
  17. function ($scope, queuedHttp) {
  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. }
  46. )