diff --git a/controllers/login.js b/controllers/login.js index 519eb4efa8..7c6dd1ce05 100644 --- a/controllers/login.js +++ b/controllers/login.js @@ -318,10 +318,6 @@ const determineRedirectUrl = (req) => { return '/dashboard'; }; -const filterSchoolsWithLdapLogin = (schools) => schools -// eslint-disable-next-line max-len - .filter((school) => school.systems?.some((system) => system.type === 'ldap' && !system.oauthConfig)); - async function getOauthSystems(req) { return api(req, { version: 'v3' }) .get('/systems/public?onlyOauth=true') @@ -338,7 +334,7 @@ router.all('/', async (req, res, next) => { const oauthSystems = await getOauthSystems(req); res.render('authentication/home', { - schools: filterSchoolsWithLdapLogin(schools), + schools, systems: [], oauthSystems: oauthSystems.data || [], inline: true, @@ -370,7 +366,7 @@ const renderLogin = async (req, res) => { res.render('authentication/login', { pageTitle: res.$t('home.header.link.login'), - schools: filterSchoolsWithLdapLogin(schools), + schools, systems: [], oauthSystems, oauthErrorLogout, @@ -446,27 +442,6 @@ router.get('/login/success', authHelper.authChecker, async (req, res) => { return res.redirect(`/firstLogin?redirect=${redirectUrl}`); } - // if this happens: SSO - const { - accountId, - systemId, - schoolId, - } = res.locals.currentPayload || {}; - if (accountId && systemId && schoolId) { - const schools = await LoginSchoolsCache.get(req); - if (schools.length > 0) { - const checkSchool = schools.find((school) => school._id === schoolId); - if (checkSchool && checkSchool.systems) { - const schoolWithSystem = checkSchool.systems.find( - (system) => system._id === systemId, - ); - if (schoolWithSystem) { - res.redirect(`/registration/${schoolId}/sso/${accountId}`); - } - } - } - } - const redirectUrl = determineRedirectUrl(req); res.redirect(redirectUrl); diff --git a/controllers/registration.js b/controllers/registration.js index 0a7c8dc34e..e57af5d197 100644 --- a/controllers/registration.js +++ b/controllers/registration.js @@ -12,8 +12,6 @@ const { getCurrentLanguage } = require('../helpers/i18n'); const { setCookie } = require('../helpers/cookieHelper'); const { logger, formatError } = require('../helpers'); -const { LoginSchoolsCache } = require('../helpers/cache'); - let invalid = false; const isProduction = NODE_ENV === 'production'; @@ -192,12 +190,9 @@ router.post( ); const schoolExists = async (req, schoolId) => { - const schools = await LoginSchoolsCache.get(req); - if (schools.length > 0) { - const checkSchool = schools.find((school) => school._id === schoolId); - return checkSchool !== undefined; - } - return false; + const res = await api(req, { version: 'v3' }).get(`/school/exists/id/${schoolId}`); + + return res.exists; }; router.get(['/registration/:classOrSchoolId/byparent', '/registration/:classOrSchoolId/byparent/:sso/:accountId'], diff --git a/helpers/cache/schools.js b/helpers/cache/schools.js index 1dc9720d7f..f3e74a11c9 100644 --- a/helpers/cache/schools.js +++ b/helpers/cache/schools.js @@ -5,7 +5,7 @@ const { logger, formatError } = require('..'); const getLoginSchools = async (req) => { let schools = []; try { - schools = await api(req).get('/schoolsList'); + schools = await api(req, { version: 'v3' }).get('/school/list-for-ldap-login'); } catch (err) { logger.error('error getting schools', formatError(err)); } diff --git a/static/scripts/login.js b/static/scripts/login.js index 1c49e4c6fe..b7aa68ce0b 100644 --- a/static/scripts/login.js +++ b/static/scripts/login.js @@ -93,23 +93,21 @@ $(document).ready(() => { incTimer(); } - const loadSystems = (systems) => { + const setSystemOptions = (systems) => { $systems.empty(); - const ldapSystems = systems.filter((system) => system.type === 'ldap'); - - ldapSystems.forEach((system) => { + systems.forEach((system) => { const systemAlias = system.alias ? ` (${system.alias})` : ''; let selected = false; - if (storage.local.getItem('loginSystem') === system._id) { + if (storage.local.getItem('loginSystem') === `${system.id}//${system.type}`) { selected = true; } // eslint-disable-next-line max-len - $systems.append(`${system.type}${systemAlias}`); + $systems.append(`${system.type}${systemAlias}`); }); // eslint-disable-next-line no-unused-expressions - ldapSystems.length < 2 ? $systems.parent().hide() : $systems.parent().show(); + systems.length < 2 ? $systems.parent().hide() : $systems.parent().show(); $systems.trigger('chosen:updated'); }; @@ -223,7 +221,7 @@ $(document).ready(() => { enableDisableLdapBtn(id); const dataSystems = $(event.target).find(':selected').data('systems'); if (id !== '' && dataSystems) { - loadSystems(dataSystems); + setSystemOptions(dataSystems); } else { $systems.parent().hide(); } diff --git a/views/authentication/forms/login.hbs b/views/authentication/forms/login.hbs index 4fe39fcf90..cdb8a91d5e 100644 --- a/views/authentication/forms/login.hbs +++ b/views/authentication/forms/login.hbs @@ -47,7 +47,7 @@ {{$t "login.input.noSchoolsSelection"}} {{#each schools}} - {{this.name}} + {{this.name}} {{else}} {{$t "login.input.noSchoolsAvailable"}} {{/each}} @@ -57,7 +57,7 @@ {{$t "login.label.system"}} {{#each systems}} - {{this.type}}{{#if this.alias}}({{this.alias}}){{/if}} + {{this.type}}{{#if this.alias}}({{this.alias}}){{/if}} {{else}} {{$t "login.input.noSystemsAvailable"}} {{/each}} @@ -204,7 +204,7 @@ {{$t "login.input.noSchoolsSelection"}} {{#each schools}} - {{this.name}} + {{this.name}} {{else}} {{$t "login.input.noSchoolsAvailable"}} {{/each}} @@ -214,7 +214,7 @@ {{#each systems}} - {{this.type}}{{#if this.alias}}({{this.alias}}){{/if}} + {{this.type}}{{#if this.alias}}({{this.alias}}){{/if}} {{else}} {{$t "login.input.noSystemsAvailable"}} {{/each}}