|
162 | 162 | }
|
163 | 163 | }
|
164 | 164 |
|
| 165 | + async function qrLogin(url) { |
| 166 | + const skoleId = await url.match(/\/\d+\//g).toString() |
| 167 | + .replaceAll('/', ''); |
| 168 | + const userId = await url.match(/userId=\d+/g).toString() |
| 169 | + .replaceAll('userId=', ''); |
| 170 | + const QrId = await url.split('QrId=')[1]; |
| 171 | +
|
| 172 | + const response = await fetch(`${api}/qr-auth`, { |
| 173 | + headers: { |
| 174 | + userId, |
| 175 | + QrId, |
| 176 | + skoleId |
| 177 | + } |
| 178 | + }); |
| 179 | + if (response.ok) { |
| 180 | + const lectioCookie = response.headers.get('set-lectio-cookie'); |
| 181 | + if (lectioCookie && lectioCookie !== null) localStorage.setItem('lectio-cookie', lectioCookie); |
| 182 | +
|
| 183 | + await cookieInfo().then(cookie => fetch(`https://db.betterlectio.dk/bruger?bruger_id=${cookie.userId}&schoolId=${cookie.schoolId}`)); |
| 184 | + reloadData(); |
| 185 | +
|
| 186 | + const originalLink = decodeURIComponent(redirectTo); |
| 187 | + location.href = originalLink; |
| 188 | + } |
| 189 | + } |
| 190 | +
|
165 | 191 | function handleEnterLogin(evt) {
|
166 | 192 | if (evt?.key === 'Enter') login();
|
167 | 193 | }
|
|
171 | 197 | qrAuth = !qrAuth;
|
172 | 198 | }
|
173 | 199 |
|
174 |
| - let qrUrl; |
175 | 200 | function qrCodeDropped(element) {
|
176 |
| - element.preventDefault(); |
177 | 201 | const html5QrCode = new Html5Qrcode('reader');
|
178 | 202 |
|
179 | 203 | html5QrCode.scanFile(element.dataTransfer.files[0], false)
|
180 | 204 | .then(qrCodeMessage => {
|
181 |
| - qrUrl = qrCodeMessage; |
| 205 | + qrLogin(qrCodeMessage); |
182 | 206 | })
|
183 | 207 | .catch(err => {
|
184 | 208 | console.log(`Error scanning file. Reason: ${err}`);
|
185 | 209 | });
|
186 | 210 | }
|
187 | 211 | function qrCodeUploaded(element) {
|
188 |
| - element.preventDefault(); |
189 | 212 | const html5QrCode = new Html5Qrcode('reader');
|
190 | 213 |
|
191 | 214 | html5QrCode.scanFile(element.target.files[0], false)
|
192 | 215 | .then(qrCodeMessage => {
|
193 |
| - qrUrl = qrCodeMessage; |
| 216 | + qrLogin(qrCodeMessage); |
194 | 217 | })
|
195 | 218 | .catch(err => {
|
196 | 219 | console.log(`Error scanning file. Reason: ${err}`);
|
|
228 | 251 | <form action="javascript:void(0);" autocomplete="on" method="post">
|
229 | 252 | <div class="form-control w-full max-w-xl">
|
230 | 253 | {#if qrAuth}
|
231 |
| - <div on:drop={qrCodeDropped} on:dragover={event => event.preventDefault()}> |
| 254 | + <div class="flex justify-center" on:drop|preventDefault={qrCodeDropped} on:dragover|preventDefault> |
232 | 255 | <label class="flex justify-center element w-3/5 aspect-square hover:cursor-pointer">
|
233 |
| - Træk eller upload din QR kode her |
234 |
| - <input type="file" name="file_upload" class="hidden" on:change={qrCodeUploaded}> |
| 256 | + Træk eller upload din QR kode her for at logge ind |
| 257 | + <input type="file" class="hidden" on:change|preventDefault={qrCodeUploaded}> |
235 | 258 | </label>
|
236 | 259 | </div>
|
237 |
| - <p>{qrUrl}</p> |
238 | 260 | <span id="reader"></span>
|
| 261 | + <p class="text-xs mt-4"> |
| 262 | + Denne side bruger cookies til at huske dine oplysninger til næste gang, du logger ind. Når du logger ind, accepterer du, at din |
| 263 | + browser gemmer dine oplysninger. De gemmes kun på din browser og bliver ikke sendt til nogen server udover Lectio og |
| 264 | + vores proxy/translation layer. |
| 265 | + <br> |
| 266 | + <span class="font-bold">Når du indlæser din QR kode (logger ind), accepterer du automatisk vores</span> |
| 267 | + <a class="font-medium text-blue-600 hover:underline dark:text-blue-500" href="/tos">Servicevilkår & Privatlivspolitik</a> |
| 268 | + </p> |
239 | 269 | {:else}
|
240 | 270 | <input
|
241 | 271 | type="text"
|
|
302 | 332 | </div>
|
303 | 333 | {/if}
|
304 | 334 | </div>
|
| 335 | + <p class="text-xs mt-4"> |
| 336 | + Denne side bruger cookies til at huske dine oplysninger til næste gang, du logger ind. Når du logger ind, accepterer du, at din |
| 337 | + browser gemmer dine oplysninger. De gemmes kun på din browser og bliver ikke sendt til nogen server udover Lectio og |
| 338 | + vores proxy/translation layer. |
| 339 | + <br> |
| 340 | + <span class="font-bold">Når du logger ind, accepterer du automatisk vores</span> |
| 341 | + <a class="font-medium text-blue-600 hover:underline dark:text-blue-500" href="/tos">Servicevilkår & Privatlivspolitik</a> |
| 342 | + </p> |
| 343 | + <div class="divider" /> |
| 344 | + <div class="flex justify-end"> |
| 345 | + <button tabindex="0" type="submit" class="btn-primary btn group" on:click={login} on:keyup={handleEnterLogin}> |
| 346 | + <p>Log ind</p> |
| 347 | + <label class="swap SWAPICONSTATE" for="login"> |
| 348 | + <svg |
| 349 | + xmlns="http://www.w3.org/2000/svg" |
| 350 | + class="octicon arrow-symbol-mktg swap-off" |
| 351 | + width="24" |
| 352 | + height="24" |
| 353 | + viewBox="0 0 16 16" |
| 354 | + fill="none" |
| 355 | + ><path |
| 356 | + class="group-hover:translate-x-1 translate-x-0 transition-all ease-in-out duration-200" |
| 357 | + fill="currentColor" |
| 358 | + d="M7.28033 3.21967C6.98744 2.92678 6.51256 2.92678 6.21967 3.21967C5.92678 3.51256 5.92678 3.98744 6.21967 4.28033L7.28033 3.21967ZM11 8L11.5303 8.53033C11.8232 8.23744 11.8232 7.76256 11.5303 7.46967L11 8ZM6.21967 11.7197C5.92678 12.0126 5.92678 12.4874 6.21967 12.7803C6.51256 13.0732 6.98744 13.0732 7.28033 12.7803L6.21967 11.7197ZM6.21967 4.28033L10.4697 8.53033L11.5303 7.46967L7.28033 3.21967L6.21967 4.28033ZM10.4697 7.46967L6.21967 11.7197L7.28033 12.7803L11.5303 8.53033L10.4697 7.46967Z" |
| 359 | + /><path |
| 360 | + class="scale-x-0 group-hover:scale-x-100 group-hover:translate-x-1 group-hover:opacity-100 opacity-0 translate-x-0 transition-all duration-200 ease-in-out origin-bottom" |
| 361 | + stroke="currentColor" |
| 362 | + d="M1.75 8H11" |
| 363 | + stroke-width="1.5" |
| 364 | + stroke-linecap="round" |
| 365 | + /></svg |
| 366 | + > |
| 367 | + <div class="swap-on loading loading-sm" /> |
| 368 | + </label> |
| 369 | + </button> |
| 370 | + </div> |
305 | 371 | {/if}
|
306 |
| - <p class="text-xs mt-4"> |
307 |
| - Denne side bruger cookies til at huske dine oplysninger til næste gang, du logger ind. Når du logger ind, accepterer du, at din |
308 |
| - browser gemmer dine oplysninger. De gemmes kun på din browser og bliver ikke sendt til nogen server udover Lectio og |
309 |
| - vores proxy/translation layer. |
310 |
| - <br> |
311 |
| - <span class="font-bold">Når du logger ind, accepterer du automatisk vores</span> |
312 |
| - <a class="font-medium text-blue-600 hover:underline dark:text-blue-500" href="/tos">Servicevilkår & Privatlivspolitik</a> |
313 |
| - </p> |
314 |
| - <div class="divider" /> |
315 |
| - <div class="flex justify-end"> |
316 |
| - <button tabindex="0" type="submit" class="btn-primary btn group" on:click={login} on:keyup={handleEnterLogin}> |
317 |
| - <p>Log ind</p> |
318 |
| - <label class="swap SWAPICONSTATE" for="login"> |
319 |
| - <svg |
320 |
| - xmlns="http://www.w3.org/2000/svg" |
321 |
| - class="octicon arrow-symbol-mktg swap-off" |
322 |
| - width="24" |
323 |
| - height="24" |
324 |
| - viewBox="0 0 16 16" |
325 |
| - fill="none" |
326 |
| - ><path |
327 |
| - class="group-hover:translate-x-1 translate-x-0 transition-all ease-in-out duration-200" |
328 |
| - fill="currentColor" |
329 |
| - d="M7.28033 3.21967C6.98744 2.92678 6.51256 2.92678 6.21967 3.21967C5.92678 3.51256 5.92678 3.98744 6.21967 4.28033L7.28033 3.21967ZM11 8L11.5303 8.53033C11.8232 8.23744 11.8232 7.76256 11.5303 7.46967L11 8ZM6.21967 11.7197C5.92678 12.0126 5.92678 12.4874 6.21967 12.7803C6.51256 13.0732 6.98744 13.0732 7.28033 12.7803L6.21967 11.7197ZM6.21967 4.28033L10.4697 8.53033L11.5303 7.46967L7.28033 3.21967L6.21967 4.28033ZM10.4697 7.46967L6.21967 11.7197L7.28033 12.7803L11.5303 8.53033L10.4697 7.46967Z" |
330 |
| - /><path |
331 |
| - class="scale-x-0 group-hover:scale-x-100 group-hover:translate-x-1 group-hover:opacity-100 opacity-0 translate-x-0 transition-all duration-200 ease-in-out origin-bottom" |
332 |
| - stroke="currentColor" |
333 |
| - d="M1.75 8H11" |
334 |
| - stroke-width="1.5" |
335 |
| - stroke-linecap="round" |
336 |
| - /></svg |
337 |
| - > |
338 |
| - <div class="swap-on loading loading-sm" /> |
339 |
| - </label> |
340 |
| - </button> |
341 |
| - </div> |
342 | 372 | </div>
|
343 | 373 | </form>
|
344 | 374 | </div>
|
|
0 commit comments