2021-02-22 10:01:02 -05:00
|
|
|
import _ from 'lodash'
|
|
|
|
import App from '../../../base'
|
2021-04-14 05:00:33 -04:00
|
|
|
import getMeta from '../../../utils/meta'
|
2021-02-22 10:01:02 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
export default App.controller(
|
|
|
|
'UserAffiliationsReconfirmController',
|
2021-04-15 10:23:41 -04:00
|
|
|
function ($scope, $http, $window) {
|
2021-04-14 09:17:21 -04:00
|
|
|
const samlInitPath = ExposedSettings.samlInitPath
|
|
|
|
$scope.reconfirm = {}
|
|
|
|
$scope.ui = $scope.ui || {} // $scope.ui inherited on settings page
|
|
|
|
$scope.userEmails = getMeta('ol-userEmails')
|
|
|
|
$scope.reconfirmedViaSAML = getMeta('ol-reconfirmedViaSAML')
|
2021-04-14 05:00:33 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// For portals:
|
|
|
|
const portalAffiliation = getMeta('ol-portalAffiliation')
|
|
|
|
if (portalAffiliation) {
|
|
|
|
$scope.portalInReconfirmNotificationPeriod =
|
|
|
|
portalAffiliation && portalAffiliation.inReconfirmNotificationPeriod
|
|
|
|
$scope.userEmail = $scope.portalInReconfirmNotificationPeriod // mixin to show notification uses userEmail
|
|
|
|
}
|
2021-04-14 05:00:33 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// For settings page:
|
|
|
|
$scope.reconfirmationRemoveEmail = getMeta('ol-reconfirmationRemoveEmail')
|
2021-04-14 05:00:33 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
// For dashboard:
|
|
|
|
$scope.allInReconfirmNotificationPeriods = getMeta(
|
|
|
|
'ol-allInReconfirmNotificationPeriods'
|
|
|
|
)
|
2021-02-22 10:01:02 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
function sendReconfirmEmail(email) {
|
|
|
|
$scope.ui.hasError = false
|
|
|
|
$scope.ui.isMakingRequest = true
|
2021-04-15 10:23:41 -04:00
|
|
|
$http
|
|
|
|
.post('/user/emails/send-reconfirmation', {
|
|
|
|
email,
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
2021-04-15 10:23:41 -04:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
.then(() => {
|
|
|
|
$scope.reconfirm[email].reconfirmationSent = true
|
|
|
|
})
|
2021-09-14 06:43:57 -04:00
|
|
|
.catch(_ => {
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.ui.hasError = true
|
|
|
|
})
|
|
|
|
.finally(() => ($scope.ui.isMakingRequest = false))
|
|
|
|
}
|
2021-02-22 10:01:02 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.requestReconfirmation = function (obj, userEmail) {
|
|
|
|
const email = userEmail.email
|
|
|
|
// For the settings page, disable other parts of affiliation UI
|
|
|
|
$scope.ui.isMakingRequest = true
|
|
|
|
$scope.ui.isProcessing = true
|
|
|
|
// create UI scope for requested email
|
|
|
|
$scope.reconfirm[email] = $scope.reconfirm[email] || {} // keep existing scope for resend email requests
|
2021-02-22 10:01:02 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
const location = obj.currentTarget.getAttribute('data-location')
|
|
|
|
const institutionId = _.get(userEmail, [
|
|
|
|
'affiliation',
|
|
|
|
'institution',
|
2021-04-27 03:52:58 -04:00
|
|
|
'id',
|
2021-04-14 09:17:21 -04:00
|
|
|
])
|
|
|
|
const ssoEnabled = _.get(userEmail, [
|
|
|
|
'affiliation',
|
|
|
|
'institution',
|
2021-04-27 03:52:58 -04:00
|
|
|
'ssoEnabled',
|
2021-04-14 09:17:21 -04:00
|
|
|
])
|
2021-02-22 10:01:02 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
if (ssoEnabled) {
|
|
|
|
$window.location.href = `${samlInitPath}?university_id=${institutionId}&reconfirm=${location}`
|
|
|
|
} else {
|
|
|
|
sendReconfirmEmail(email)
|
|
|
|
}
|
2021-02-22 10:01:02 -05:00
|
|
|
}
|
|
|
|
}
|
2021-04-14 09:17:21 -04:00
|
|
|
)
|