2015-03-19 10:22:48 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
App.controller "RegisterUsersController", ($scope, queuedHttp) ->
|
|
|
|
$scope.users = []
|
|
|
|
|
|
|
|
$scope.inputs =
|
|
|
|
emails: ""
|
|
|
|
|
|
|
|
parseEmails = (emailsString)->
|
|
|
|
regexBySpaceOrComma = /[\s,]+/
|
|
|
|
emails = emailsString.split(regexBySpaceOrComma)
|
|
|
|
emails = _.map emails, (email)->
|
|
|
|
email = email.trim()
|
|
|
|
emails = _.select emails, (email)->
|
|
|
|
email.indexOf("@") != -1
|
|
|
|
return emails
|
|
|
|
|
|
|
|
$scope.registerUsers = () ->
|
|
|
|
emails = parseEmails($scope.inputs.emails)
|
|
|
|
$scope.error = false
|
|
|
|
for email in emails
|
|
|
|
queuedHttp
|
|
|
|
.post("/admin/register", {
|
|
|
|
email: email,
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
})
|
2017-06-20 11:27:05 -04:00
|
|
|
.then (response) ->
|
|
|
|
{ data } = response
|
|
|
|
user = data
|
2015-03-19 10:22:48 -04:00
|
|
|
$scope.users.push user
|
|
|
|
$scope.inputs.emails = ""
|
2017-06-20 06:49:55 -04:00
|
|
|
.catch () ->
|
2015-03-19 10:22:48 -04:00
|
|
|
$scope.error = true
|