-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from PapillonApp/dev
Passage vers `main`
- Loading branch information
Showing
31 changed files
with
429 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,49 @@ | ||
import {EDCore} from "../index"; | ||
import {studentAccount} from "~/types"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
// @ts-ignore | ||
import { Select } from "enquirer"; | ||
import ora, {Ora} from "ora"; | ||
import {AccountInfo} from "../src/utils/types/accounts"; | ||
|
||
export const ED = new EDCore(); | ||
|
||
const username = ""; | ||
const password = ""; | ||
const uid = uuidv4(); | ||
|
||
async function handle2FA() { | ||
const token = await ED.auth.get2FAToken(username, password); | ||
const QCM = await ED.auth.get2FA(token); | ||
const chooseAnswer = new Select({ | ||
name: 'answer', | ||
message: QCM.question, | ||
choices: QCM.propositions | ||
}); | ||
const answer = await chooseAnswer.run() | ||
const loader = ora('Envoie de la réponse...').start(); | ||
const authFactors = await ED.auth.resolve2FA(answer); | ||
loader.succeed('Envoie de la réponse') | ||
loader.start('Connexion...') | ||
await ED.auth.login(username, password, uid, authFactors) | ||
loggedInHook(loader) | ||
} | ||
|
||
function loggedInHook(loader: Ora) { | ||
const account = ED.student as AccountInfo; | ||
loader.succeed(`Connecté en tant que ${account.prenom} ${account.nom}`); | ||
} | ||
|
||
export async function login() { | ||
await ED.auth.login("jean", "jean%", uuidv4()).then(() => { | ||
const account = ED.student as studentAccount; | ||
console.log(`Logged in as ${account.particule} ${account.prenom} ${account.nom}`); | ||
}).catch(err => { | ||
console.error(`Failed to login: Error ${err.code}: ${err.message}`); | ||
const loader = ora('Authentification...').start(); | ||
await ED.auth.login(username, password, uid).then(() => { | ||
loggedInHook(loader); | ||
}).catch(async err => { | ||
if (err.code == 12) { | ||
loader.fail('La double authentification est activée, répondez à la question pour vous connecter'); | ||
await handle2FA(); | ||
return; | ||
} | ||
loader.fail(`Failed to login: Error ${err.code}: ${err.message}`); | ||
process.exit(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export const API = "https://api.ecoledirecte.com/v3"; | ||
export const VERSION = "6.15.1"; | ||
|
||
export default { | ||
API | ||
API, | ||
VERSION | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.