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C3CE,EAAKH,QAAU,CAAE/F,QAAAA,EAASgG,OAAAA,EAC3B,GACD,GAAC,CAAA1J,IAAA,UAAAC,MAED,WACCN,KAAK8F,gBACN,I,uEAACP,CAAA,CA5SQ,GA+SV,W","sources":["webpack://mitt-nercia/./src/modules/init/errorScreen/ErrorScreen.js","webpack://mitt-nercia/./src/modules/init|sync|C:/^/..*/([^/]*)/1.[jt]s$/i","webpack://mitt-nercia/./src/modules/init-modules.ts","webpack://mitt-nercia/./src/app.js","webpack://mitt-nercia/./src/modules/init/auth/Auth.js"],"sourcesContent":["import { uri } from 'modapp-utils';\nimport './errorScreen.scss';\n\n/**\n * ErrorScreen shows login error messages, otherwise calls auth.authenticate.\n */\nclass ErrorScreen {\n\n\tconstructor(app, params) {\n\t\tthis.app = app;\n\n\t\tthis.app.require([ 'auth' ], this._init.bind(this));\n\t}\n\n\t_init(module) {\n\t\tthis.module = module;\n\n\t\tlet q = uri.getQuery();\n\t\tif (q.error) {\n\t\t\ttry {\n\t\t\t\tlet err = JSON.parse(atob(q.error));\n\t\t\t\tthis._showError(err);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(\"Failed to parse error message: \", e);\n\t\t\t\tconsole.error(`Message: \"${q.error}\"`);\n\t\t\t\tthis._redirect();\n\t\t\t}\n\t\t} else {\n\t\t\tthis._showLoader();\n\t\t\tthis.module.auth.authenticate().catch(err => {\n\t\t\t\tconsole.error(\"Authentication failed: \", err);\n\t\t\t\tthis._showError(err);\n\t\t\t});\n\t\t}\n\t}\n\n\trender(el) {\n\t\tlet e = document.createElement('div');\n\t\te.classList.add('errorscreen');\n\t\te.innerHTML = '
' +\n\t\t\t'
' +\n\t\t\t\t'

Något gick fel

' +\n\t\t\t\t'
' +\n\t\t\t\t\t'

Ett fel inträffade när du försökte logga in:

' +\n\t\t\t\t\t'' +\n\t\t\t\t'
' +\n\t\t\t\t\t'Gå tillbaka' +\n\t\t\t\t'
' +\n\t\t\t'
' +\n\t\t'
';\n\t\te.querySelector(\"#msg\").textContent = this.err.message;\n\t\tlet url = window.location.href.split('?')[0];\n\t\tlet l = e.querySelector(\"#link\");\n\t\tl.href = url;\n\t\tif (url == window.location.href) {\n\t\t\tl.onclick = () => window.location.reload();\n\t\t}\n\n\t\tthis.el = e;\n\t\tel.appendChild(e);\n\t\treturn e;\n\t}\n\n\tunrender() {\n\t\tif (this.el) {\n\t\t\tthis.el.parentNode.removeChild(this.el);\n\t\t\tthis.el = null;\n\t\t}\n\t}\n\n\t_showError(err) {\n\t\tthis.err = err;\n\t\tthis.app.setComponent(this);\n\t}\n\n\t_showLoader() {\n\t\tthis.app.setComponent(new class {\n\t\t\trender(el) {\n\t\t\t\tconst spinner = document.createElement(\"div\");\n\t\t\t\tspinner.className = 'errorscreen';\n\t\t\t\tspinner.innerHTML = '
';\n\t\t\t\tel.appendChild(spinner);\n\t\t\t\tthis.spinner = spinner;\n\t\t\t}\n\t\t\tunrender() {\n\t\t\t\tthis.spinner?.remove();\n\t\t\t}\n\t\t});\n\t}\n\n\t_redirect() {\n\t\twindow.location.replace(window.location.href.split('?')[0]);\n\t}\n}\n\nexport default ErrorScreen;\n","var map = {\n\t\"./api/Api.js\": 9365,\n\t\"./auth/Auth.js\": 77519,\n\t\"./errorScreen/ErrorScreen.js\": 3153\n};\n\n\nfunction webpackContext(req) {\n\tvar id = webpackContextResolve(req);\n\treturn __webpack_require__(id);\n}\nfunction webpackContextResolve(req) {\n\tif(!__webpack_require__.o(map, req)) {\n\t\tvar e = new Error(\"Cannot find module '\" + req + \"'\");\n\t\te.code = 'MODULE_NOT_FOUND';\n\t\tthrow e;\n\t}\n\treturn map[req];\n}\nwebpackContext.keys = function webpackContextKeys() {\n\treturn Object.keys(map);\n};\nwebpackContext.resolve = webpackContextResolve;\nmodule.exports = webpackContext;\nwebpackContext.id = 20025;","import { AppModule } from \"modapp\";\nimport type Api from \"./init/api/Api\";\n\nconst req = require.context(\"./init/\", true, /^\\..*\\/([^/]*)\\/\\1.[jt]s$/i);\n\n// Manually declared types for the dynamically loaded modules\ninterface TypedModules {\n\tapi: Api;\n}\n\n// @ts-expect-error\n// `modules` gets late-initialized below, so we can safely ignore the type error here.\nconst modules: TypedModules & Record = {\n\t// Add third party modules here\n};\n\n// Using the first-character-lowercase name of the js-file as module name\nreq.keys().forEach(key => {\n\tconst match = key.match(/\\/([^/]*)\\.[jt]s$/);\n\tconst name = match![1].charAt(0).toLowerCase() + match![1].slice(1);\n\tif (modules[name]) {\n\t\tthrow new Error(`Duplicate module: ${key}`);\n\t}\n\tmodules[name] = req(key).default;\n});\n\nexport default modules;\n","import './sentry';\nimport 'core-js/stable';\nimport { AppExt } from 'modapp';\nimport initModules from 'modules/init-modules';\nimport moduleConfig from 'moduleConfig';\nimport 'scss/index.scss';\n\n// Create app and load core modules\nlet app = new AppExt(moduleConfig);\n\napp.loadBundle(initModules).then(result => {\n\tconsole.log(\"[Main] Init modules: \", result);\n\tapp.render(document.body);\n\n\t// If we are not logged in, we will get redirected.\n\t// Avoid loading the rest of the page to avoid ChunkLoadError reports\n\t// caused by the redirect.\n\treturn result.modules.auth.getUserPromise().then(() => {\n\n\t\t// Load main modules\n\t\treturn import(/* webpackChunkName: \"main\" */ 'modules/main-modules')\n\t\t\t.then(({ default: mainModules }) => app.loadBundle(mainModules))\n\t\t\t.then(result => console.log(\"[Main] Main modules: \", result));\n\t});\n}).catch((err) => console.error(err));\n\n// Make app global\nwindow.app = app;\n","import { Model } from 'modapp-resource';\nimport l10n from 'utils/l10n';\n\nconst mainRoles = [\n\t{ id: 'staff', name: l10n.l('auth.admin', \"Administratör\") },\n\t{ id: 'educator', name: l10n.l('auth.educator', \"Utbildare\") },\n\t{ id: 'participant', name: l10n.l('auth.participant', \"Deltagare\") },\n];\n\n/**\n * Auth fetches the currently logged in user on start, or redirects to the login\n * page if the user is not logged in.\n */\nclass Auth {\n\n\tconstructor(app, params) {\n\t\tthis.app = app;\n\t\tthis.params = Object.assign({\n\t\t\tloginUrl: '/auth',\n\t\t\tlogoutUrl: '/auth/logout',\n\t\t\tauthenticateUrl: '/auth?noredirect',\n\t\t\tredirected: false\n\t\t}, params);\n\n\t\t// Bind callbacks\n\t\tthis._onConnect = this._onConnect.bind(this);\n\t\tthis._onUnsubscribe = this._onUnsubscribe.bind(this);\n\n\t\tthis.app.require([ 'api' ], this._init.bind(this));\n\t}\n\n\t_init(module) {\n\t\tthis.module = module;\n\t\tthis.userPromise = null;\n\t\tthis._createExtUserPromise();\n\t\tthis.model = new Model({\n\t\t\tdata: {\n\t\t\t\tloggedIn: false,\n\t\t\t\tuser: null,\n\t\t\t\troles: new Model({\n\t\t\t\t\teventBus: this.app.eventBus\n\t\t\t\t}),\n\t\t\t\tactiveRole: null\n\t\t\t},\n\t\t\teventBus: this.app.eventBus\n\t\t});\n\n\t\tthis.module.api.setOnConnect(this._onConnect);\n\t}\n\n\t/**\n\t * Gets the auth model containing the currently logged in user.\n\t * @returns {Model} The auth model.\n\t */\n\tgetModel() {\n\t\treturn this.model;\n\t}\n\n\t/**\n\t * Gets the auth roles model containing all the roles of the logged in user.\n\t * @returns {Model} The roles model.\n\t */\n\tgetRoles() {\n\t\treturn this.model.roles;\n\t}\n\n\t/**\n\t * Gets the model of the logged in user.\n\t * @returns {UserModel} The user model.\n\t */\n\tgetUser() {\n\t\treturn this.model.user || null;\n\t}\n\n\t/**\n\t * Gets a promise to the logged in user.\n\t * It resolves as soon as the user is logged in and fetched.\n\t * @returns {Promise.} Currently logged in user.\n\t */\n\tgetUserPromise() {\n\t\treturn this.extUserPromise;\n\t}\n\n\t/**\n\t * Gets a list of the main roles.\n\t * @returns {Array.} Array of role objects: { id, name }\n\t */\n\tgetMainRoles() {\n\t\treturn mainRoles;\n\t}\n\n\t/**\n\t * Sets the active role of the user. The role must be a main role held by the user.\n\t * @param {string} roleId ID of role.\n\t */\n\tsetActiveRole(roleId) {\n\t\tfor (let r of mainRoles) {\n\t\t\tif (roleId == r.id) {\n\t\t\t\tif (!this.model.roles[roleId]) {\n\t\t\t\t\tconsole.error(\"User does not have role: \", roleId);\n\t\t\t\t} else {\n\t\t\t\t\tthis.model.set({ activeRole: roleId });\n\t\t\t\t\tif (sessionStorage && this.model.user) {\n\t\t\t\t\t\tsessionStorage.setItem('auth.user.' + this.model.user.id + '.activeRole', roleId);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthrow new Error(\"Invalid main role: \" + roleId);\n\t}\n\n\t/**\n\t * Redirects the browser to the login page.\n\t */\n\tredirectToLogin() {\n\t\tif (this.params.redirected) {\n\t\t\tconsole.log(\"Already redirected\");\n\t\t\treturn;\n\t\t}\n\t\twindow.location.replace(this.params.loginUrl + '?redirect_uri=' + encodeURIComponent(window.location.href));\n\t}\n\n\t/**\n\t * Authenticates the user or redirects to login if not logged in.\n\t *\n\t * The returned promise will be rejected if the API returns any other error\n\t * than 'user.authenticationFailed'. If user.authenticationFailed is\n\t * returned, the auth module will redirect the client to the authentication\n\t * endpoint.\n\t * @param {boolean} [noRedirect] Flag that prevents failed authentication to redirect to login.\n\t * @returns {Promise} Promise to the authenticate.\n\t */\n\tauthenticate(noRedirect) {\n\t\treturn fetch(this.params.authenticateUrl, {\n\t\t\tmethod: 'POST',\n\t\t\tmode: 'cors',\n\t\t\tcredentials: 'include',\n\t\t}).catch(err => {\n\t\t\t// Rethrow fetch errors as a more friendly message.\n\t\t\tthrow { code: 'auth.authFetchFailed', message: \"Det gick inte att nå Nercia API. Kontakta Nercia om felet kvarstår.\", data: err };\n\t\t}).then(resp => {\n\t\t\tif (resp.status >= 400) {\n\t\t\t\treturn resp.json().then(err => {\n\t\t\t\t\tif (!noRedirect && resp.status < 500) {\n\t\t\t\t\t\tthis.redirectToLogin();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthrow err;\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn this._getCurrentUser().catch(err => {\n\t\t\t\t// On access denied, we have failed to authentication and\n\t\t\t\t// shouldredirect.\n\t\t\t\tif (!noRedirect && (err.code == 'system.accessDenied' || err.code == 'auth.invalidToken')) {\n\t\t\t\t\tthis.redirectToLogin();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Rewrite the system.connectionError to a friendly message.\n\t\t\t\tif (err.code == 'system.connectionError') {\n\t\t\t\t\terr = { code: err.code, message: \"Det gick inte att ansluta till Nercia API. Kontakta Nercia om felet kvarstår.\" };\n\t\t\t\t}\n\t\t\t\t// Or else we throw the error to be handled by the caller to show an\n\t\t\t\t// error message.\n\t\t\t\tthrow err;\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Redirects the browser to the login page.\n\t */\n\tlogout() {\n\t\twindow.location.replace(this.params.logoutUrl + '?redirect_uri=' + encodeURIComponent(window.location.href));\n\t}\n\n\t/**\n\t * Check if the current user has all of the provided roles.\n\t * @param {string|Array.} roles Role(s).\n\t * @returns {boolean} True if the user has all roles, otherwise false.\n\t */\n\thasRoles(roles) {\n\t\tif (!roles) {\n\t\t\treturn true;\n\t\t}\n\t\troles = Array.isArray(roles) ? roles : arguments;\n\t\tlet rs = this.getRoles();\n\t\tfor (let r of roles) {\n\t\t\tif (!rs[r]) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t}\n\n\tgetRoleName(role) {\n\t\tfor (let r of mainRoles) {\n\t\t\tif (r.id == role) {\n\t\t\t\treturn r.name;\n\t\t\t}\n\t\t}\n\t\treturn l10n.l('auth.missingRole', \"Saknar roll\");\n\t}\n\n\t/**\n\t * Check if the current user has any of the provided roles.\n\t * @param {string|Array.} roles Role(s).\n\t * @returns {boolean} True if the user has any of the roles, otherwise false.\n\t */\n\thasAnyRole(roles) {\n\t\tif (!roles) {\n\t\t\treturn false;\n\t\t}\n\t\troles = Array.isArray(roles) ? roles : arguments;\n\t\tlet rs = this.getRoles();\n\t\tfor (let r of roles) {\n\t\t\tif (rs[r]) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t_onConnect() {\n\t\treturn this.module.api.authenticate('user.sub', 'authenticate')\n\t\t\t.then(roles => {\n\t\t\t\t// Set the roles model\n\t\t\t\tlet o = Object.assign({}, this.model.roles.props);\n\t\t\t\tfor (let k in o) {\n\t\t\t\t\to[k] = undefined;\n\t\t\t\t}\n\t\t\t\tfor (let r of roles) {\n\t\t\t\t\to[r] = true;\n\t\t\t\t}\n\t\t\t\tthis.model.roles.set(o);\n\t\t\t\t// Reset active role if we lost the currently active one\n\t\t\t\tif (this.model.activeRole && !o[this.model.activeRole]) {\n\t\t\t\t\tthis.model.set({ activeRole: this._getMainRole() });\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch(() => this._onUnsubscribe());\n\t}\n\n\t_getMainRole() {\n\t\tlet p = this.model.roles.props;\n\t\tfor (let r of mainRoles) {\n\t\t\tif (p[r.id]) {\n\t\t\t\treturn r.id;\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\t_getCurrentUser() {\n\t\tif (!this.userPromise) {\n\t\t\tthis.userPromise = this.module.api.call('user.sub', 'getUser')\n\t\t\t\t.then(user => {\n\t\t\t\t\t// Get active role\n\t\t\t\t\tlet activeRole = this.model.activeRole;\n\t\t\t\t\t// Load from sessionStorage if available\n\t\t\t\t\tif (!activeRole && sessionStorage) {\n\t\t\t\t\t\tactiveRole = sessionStorage.getItem('auth.user.' + user.id + '.activeRole');\n\t\t\t\t\t}\n\t\t\t\t\t// Get first matching role\n\t\t\t\t\tif (!activeRole || !this.model.roles[activeRole]) {\n\t\t\t\t\t\tactiveRole = this._getMainRole();\n\t\t\t\t\t}\n\t\t\t\t\tthis.model.set({\n\t\t\t\t\t\tloggedIn: true,\n\t\t\t\t\t\tuser,\n\t\t\t\t\t\tactiveRole\n\t\t\t\t\t});\n\t\t\t\t\tuser.on('unsubscribe', this._onUnsubscribe);\n\t\t\t\t\tthis.extUser.resolve(user);\n\t\t\t\t\treturn user;\n\t\t\t\t})\n\t\t\t\t.catch(err => {\n\t\t\t\t\tthis.userPromise = null;\n\t\t\t\t\tthis.extUser.reject(err);\n\t\t\t\t\tthrow err;\n\t\t\t\t});\n\t\t}\n\t\treturn this.userPromise;\n\t}\n\n\t_onUnsubscribe() {\n\t\t// Remove user model\n\t\tif (this.model.user) {\n\t\t\tthis.model.user.off('unsubscribe', this._onUnsubscribe);\n\t\t\tthis.model.set({\n\t\t\t\tloggedIn: false,\n\t\t\t\tuser: null,\n\t\t\t\tactiveRole: null\n\t\t\t});\n\t\t\tthis._createExtUserPromise();\n\t\t\t// Clear roles\n\t\t\tlet o = Object.assign({}, this.model.roles.props);\n\t\t\tfor (let k in o) {\n\t\t\t\to[k] = undefined;\n\t\t\t}\n\t\t\tthis.model.roles.set(o);\n\t\t}\n\t\tthis.userPromise = null;\n\t}\n\n\t_createExtUserPromise() {\n\t\tthis.extUserPromise = new Promise((resolve, reject) => {\n\t\t\tthis.extUser = { resolve, reject };\n\t\t});\n\t}\n\n\tdispose() {\n\t\tthis._onUnsubscribe();\n\t}\n}\n\nexport default Auth;\n"],"names":["ErrorScreen","app","params","_classCallCheck","this","require","_init","bind","_createClass","key","value","module","_this","q","uri","error","err","JSON","parse","atob","_showError","e","console","concat","_redirect","_showLoader","auth","authenticate","catch","el","document","createElement","classList","add","innerHTML","querySelector","textContent","message","url","window","location","href","split","l","onclick","reload","appendChild","parentNode","removeChild","setComponent","_class","spinner","className","_this$spinner","remove","replace","map","webpackContext","req","id","webpackContextResolve","__webpack_require__","o","Error","code","keys","Object","resolve","exports","modules","forEach","match","name","charAt","toLowerCase","slice","default","AppExt","moduleConfig","loadBundle","initModules","then","result","log","render","body","getUserPromise","_ref","mainModules","mainRoles","l10n","Auth","assign","loginUrl","logoutUrl","authenticateUrl","redirected","_onConnect","_onUnsubscribe","userPromise","_createExtUserPromise","model","Model","data","loggedIn","user","roles","eventBus","activeRole","api","setOnConnect","extUserPromise","roleId","_i","_mainRoles","length","set","sessionStorage","setItem","encodeURIComponent","noRedirect","fetch","method","mode","credentials","resp","status","json","redirectToLogin","_getCurrentUser","Array","isArray","arguments","_step","rs","getRoles","_iterator","_createForOfIteratorHelper","s","n","done","f","role","_i2","_mainRoles2","r","_step2","_iterator2","_this2","props","k","undefined","_step3","_iterator3","_getMainRole","p","_i3","_mainRoles3","_this3","call","getItem","on","extUser","reject","off","_this4","Promise"],"sourceRoot":""}