Skip to content

Commit

Permalink
Merge branch 'NonozgYtb-multiple-feats'
Browse files Browse the repository at this point in the history
  • Loading branch information
maelgangloff committed Apr 28, 2023
2 parents f568665 + efe571a commit 45bc91b
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 47 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"main": "src/index.js",
"scripts": {
"lint": "eslint src/",
"start": "electron ."
"start": "electron .",
"build": "electron-builder build --linux --win"
},
"keywords": [
"Skolengo",
Expand Down Expand Up @@ -39,7 +40,6 @@
"build": {
"appId": "fr.maelgangloff.scolengo.token",
"productName": "Scolengo Token",
"copyright": "Copyright © 2023 Maël Gangloff <contact@maelgangloff.fr>",
"icon": "src/icon.png",
"win": {
"target": "portable"
Expand Down
134 changes: 105 additions & 29 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,41 +1,117 @@
* {
box-sizing: border-box;
}

body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
Arial, sans-serif;
margin: auto;
padding: 2rem;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
Helvetica, Arial, sans-serif;
margin: auto;
display: flex;
flex-direction: column;
}

h1 {
padding-top: 2rem;
}

html,
body {
height: 100%;
}

body > :not(footer) {
padding: 0 2rem;
}

footer {
text-align:center;
padding: 5px;
background-color: #abbaba;
color: #000;
position: absolute;
bottom: 0;
margin-top: auto;
text-align: center;
padding: 5px;
background-color: #abbaba;
color: #000;
}

pre {
overflow-x: auto;
white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;
overflow-x: auto;
white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;
}

ul.schools {
list-style-type: none;
}

ul.schools li {
display: flex;
gap: 8px;
align-items: baseline;
padding: 8px;
flex-wrap: wrap;
}

ul.schools li:hover {
background-color: #dedede;
border-radius: 8px;
}

.school-select {
margin-left: auto;
}

input[type=text] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
input[type="text"] {
width: 100%;
padding: 12px 20px;
margin: 0;
box-sizing: border-box;
border-radius: 4px;
border: 2px solid #04aa6d;
outline: none;
}

input[type=text]:focus {
border-color: #146447;
}

button {
background-color: #04AA6D;
border: none;
color: white;
padding: 16px 32px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
}
background-color: #04aa6d;
border: none;
color: white;
padding: 8px 16px;
border-radius: 4px;
text-decoration: none;
margin: 0;
cursor: pointer;
outline: none;
}

button:hover {
background-color: #146447;
}

#schoolForm {
display: flex;
gap: 8px;
}

:link, a {
color: #2196F3;
text-decoration: none;
}

:link:hover, a:hover {
text-decoration: underline;
}

*:focus-visible {
outline: solid;
}

@media (prefers-color-scheme: dark) {
body { background: #212121; color: #ddd; }
input[type=text],footer { background: #333; color: #ddd; }
ul.schools li:hover { background-color: #333333; }
}

9 changes: 6 additions & 3 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="fr>
<head>
<meta charset="UTF-8" />
<title>Authentification auprès de Skolengo</title>
Expand All @@ -13,9 +13,12 @@ <h1>🏫 Trouver mon établissement</h1>
<input type="text" id="schoolName" placeholder="Nom de votre établissement et/ou code postal" autofocus>
<button type="submit">Valider</button>
</form>
<ul class="schools">
</ul>
<section class="section-iframe"></section>
<footer>
<a href="https://github.com/maelgangloff/scolengo-token" target="_blank">scolengo-token</a> - Distribué sous licence GNU GPL v3.0 - Copyright © 2023 Maël Gangloff <contact@maelgangloff.fr>
<a href="https://github.com/maelgangloff/scolengo-token" target="_blank">scolengo-token</a> - Distribué sous licence GNU GPL v3.0</a>
</footer>
<script src="./renderer.js"></script>
</body>
</html>
</html>
23 changes: 14 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const CAS_CALLBACK = 'skoapp-prod://sign-in-callback'
let mainWindow = null
let oidClient
/** @type {import('scolengo-api/types/models/School').School} */
let school
let selectedSchool

const createWindow = () => {
mainWindow = new BrowserWindow({
Expand All @@ -24,18 +24,23 @@ const createWindow = () => {
return mainWindow
}

ipcMain.on('school-name', async (event, schoolName) => {
ipcMain.on('school-search', async (event, schoolName) => {
try {
const schools = await Skolengo.searchSchool({ text: schoolName })
const schools = await Skolengo.searchSchool({ text: schoolName }, 100)
if (!schools.length) {
dialog.showErrorBox('Établissement introuvable', "Nous avons cherché partout, mais nous n'avons pas trouvé cet établissement...")
return mainWindow.reload()
}
school = schools[0]
dialog.showMessageBox(mainWindow, {
title: 'Établissement sélectionné',
message: `Vous avez sélectionné cet établissement : ${school.name} (${school.emsCode})`
})
mainWindow.webContents.send('school-list', schools)
} catch (e) {
dialog.showErrorBox('Erreur', 'Une erreur est survenue, veuillez réessayer...')
return mainWindow.reload()
}
})

ipcMain.on('school-auth', async (event, school) => {
try {
selectedSchool = school
oidClient = await Skolengo.getOIDClient(school)
const authURL = oidClient.authorizationUrl()
mainWindow.loadURL(authURL)
Expand All @@ -62,7 +67,7 @@ else {
try {
const tokenSet = await oidClient.callback(CAS_CALLBACK, oidClient.callbackParams(url))
await window.loadFile(path.join(__dirname, 'success.html'))
const authData = { tokenSet, school }
const authData = { tokenSet, school: selectedSchool }
window.webContents.send('send-token', authData)
} catch (e) {
dialog.showErrorBox('Erreur', "L'authentification a échoué, veuillez réessayer...")
Expand Down
6 changes: 4 additions & 2 deletions src/preload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { contextBridge, ipcRenderer } = require('electron')

contextBridge.exposeInMainWorld('electronAPI', {
setSchool: (schoolName) => ipcRenderer.send('school-name', schoolName),
sendToken: (token) => ipcRenderer.on('send-token', token)
setSearch: (schoolName) => ipcRenderer.send('school-search', schoolName),
onSchoolList: (callback) => ipcRenderer.on('school-list', callback),
sendToken: (token) => ipcRenderer.on('send-token', token),
schoolAuth: (school) => ipcRenderer.send('school-auth', school)
})
29 changes: 28 additions & 1 deletion src/renderer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
const form = document.getElementById('schoolForm')
const schoolsElem = document.querySelector('.schools')

form.addEventListener('submit', (e) => {
e.preventDefault()
form.hidden = true
window.electronAPI.setSchool(document.getElementById('schoolName').value)
window.electronAPI.setSearch(document.getElementById('schoolName').value)
})

window.addEventListener('load', () => {
window.electronAPI.onSchoolList((_, schools) => {
schoolsElem.innerHTML = ''
schools.forEach((school) => {
const schooHTML = `<b class="school-name">${
school.name
}</b><span class="school-ems">(${
school.emsCode
})</span>-<i class="school-city">${school.city
.replace(/CEDEX ([0-9]+)/, '')
.trim()} ${
school.zipCode
}</i><button class="school-select">Choisir</button>`
const li = document.createElement('li')
li.innerHTML = schooHTML
li.querySelector('.school-select').addEventListener(
'click',
async () => {
window.electronAPI.schoolAuth(school)
}
)
schoolsElem.appendChild(li)
})
})
})
6 changes: 5 additions & 1 deletion src/success.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
<h1>💖 Félicitations !</h1>
<p><b>🚨 ATTENTION: Ne communiquez jamais vos jetons à un tiers. Ils vous sont strictement personnels. Si vous pensez que vos jetons ont été dérobés, révoquez-les immédiatement.</b></p>
<p>Vous pouvez utiliser ces informations d'authentification avec la librairie <a href="https://github.com/maelgangloff/scolengo-api">scolengo-api</a>.</p>
<a class="dllink">📁 Télecharger le fichier de configuration</a>
<pre>
<code id="auth"></code>
</pre>
<script>
<script>
const auth = document.getElementById('auth')
const dllink = document.querySelector('.dllink');
window.electronAPI.sendToken((event, token) => {
auth.innerHTML = JSON.stringify(token, null, 2)
dllink.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(token, null, 2)));
dllink.setAttribute('download', "config.json");
})
</script>
</body>
Expand Down

0 comments on commit 45bc91b

Please # to comment.