2020-06-23 04:45:38 -04:00
|
|
|
import _ from 'lodash'
|
2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../base'
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
export default App.controller(
|
|
|
|
'RegisterUsersController',
|
|
|
|
function ($scope, queuedHttp) {
|
|
|
|
$scope.users = []
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.inputs = { emails: '' }
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const parseEmails = function (emailsString) {
|
|
|
|
const regexBySpaceOrComma = /[\s,]+/
|
|
|
|
let emails = emailsString.split(regexBySpaceOrComma)
|
|
|
|
emails = _.map(emails, email => (email = email.trim()))
|
|
|
|
emails = _.filter(emails, email => email.indexOf('@') !== -1)
|
|
|
|
return emails
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
return ($scope.registerUsers = function () {
|
|
|
|
const emails = parseEmails($scope.inputs.emails)
|
|
|
|
$scope.error = false
|
|
|
|
return Array.from(emails).map(email =>
|
|
|
|
queuedHttp
|
|
|
|
.post('/admin/register', {
|
|
|
|
email,
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
2021-04-14 09:17:21 -04:00
|
|
|
})
|
|
|
|
.then(function (response) {
|
|
|
|
const { data } = response
|
|
|
|
const user = data
|
|
|
|
$scope.users.push(user)
|
|
|
|
return ($scope.inputs.emails = '')
|
|
|
|
})
|
|
|
|
.catch(() => ($scope.error = true))
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|