UserAffiliationsReconfirmController.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import _ from 'lodash'
  2. import App from '../../../base'
  3. export default App.controller('UserAffiliationsReconfirmController', function(
  4. $scope,
  5. UserAffiliationsDataService,
  6. $window
  7. ) {
  8. $scope.reconfirm = {}
  9. // For portals:
  10. $scope.userEmails = window.data.userEmails
  11. // For settings page:
  12. $scope.ui = $scope.ui || {} // $scope.ui inherited on settings page
  13. // For dashboard:
  14. $scope.allInReconfirmNotificationPeriods =
  15. window.data.allInReconfirmNotificationPeriods
  16. function sendReconfirmEmail(email) {
  17. $scope.ui.hasError = false
  18. $scope.ui.isMakingRequest = true
  19. UserAffiliationsDataService.resendConfirmationEmail(email)
  20. .then(() => {
  21. $scope.reconfirm[email].reconfirmationSent = true
  22. })
  23. .catch(error => {
  24. $scope.ui.hasError = true
  25. })
  26. .finally(() => ($scope.ui.isMakingRequest = false))
  27. }
  28. $scope.reconfirmationRemoveEmail = $window.data.reconfirmationRemoveEmail
  29. $scope.reconfirmedViaSAML = $window.data.reconfirmedViaSAML
  30. $scope.requestReconfirmation = function(obj, userEmail) {
  31. const email = userEmail.email
  32. // For the settings page, disable other parts of affiliation UI
  33. $scope.ui.isMakingRequest = true
  34. $scope.ui.isProcessing = true
  35. // create UI scope for requested email
  36. $scope.reconfirm[email] = $scope.reconfirm[email] || {} // keep existing scope for resend email requests
  37. const location = obj.currentTarget.getAttribute('data-location')
  38. const institutionId = _.get(userEmail, ['affiliation', 'institution', 'id'])
  39. const ssoEnabled = _.get(userEmail, [
  40. 'affiliation',
  41. 'institution',
  42. 'ssoEnabled'
  43. ])
  44. if (ssoEnabled) {
  45. $window.location.href = `${$scope.samlInitPath}?university_id=${institutionId}&reconfirm=${location}`
  46. } else {
  47. sendReconfirmEmail(email)
  48. }
  49. }
  50. })