UserAffiliationsReconfirmController.js 2.4 KB

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