summaryrefslogtreecommitdiff
path: root/school/node_modules/pronote-api/src/cas/generics/aten.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2023-01-10 14:54:04 +0100
committerMinteck <contact@minteck.org>2023-01-10 14:54:04 +0100
commit99c1d9af689e5325f3cf535c4007b3aeb8325229 (patch)
treee663b3c2ebdbd67c818ac0c5147f0ce1d2463cda /school/node_modules/pronote-api/src/cas/generics/aten.js
parent9871b03912fc28ad38b4037ebf26a78aa937baba (diff)
downloadpluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.gz
pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.tar.bz2
pluralconnect-99c1d9af689e5325f3cf535c4007b3aeb8325229.zip
Update - This is an automated commit
Diffstat (limited to 'school/node_modules/pronote-api/src/cas/generics/aten.js')
-rw-r--r--school/node_modules/pronote-api/src/cas/generics/aten.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/school/node_modules/pronote-api/src/cas/generics/aten.js b/school/node_modules/pronote-api/src/cas/generics/aten.js
new file mode 100644
index 0000000..44cfa83
--- /dev/null
+++ b/school/node_modules/pronote-api/src/cas/generics/aten.js
@@ -0,0 +1,76 @@
+const fs = require('fs');
+const path = require('path');
+
+const jsdom = require('jsdom');
+
+const errors = require('../../errors');
+const { getDOM, submitForm, extractStart } = require('../api');
+
+// eslint-disable-next-line no-sync
+const jsEncrypt = fs.readFileSync(path.join(__dirname, 'jsencrypt.min.js'));
+
+async function login({ url, account, username, password, startURL, atenURL, postSubmit })
+{
+ if (!startURL.startsWith('http')) {
+ if (startURL.startsWith('/')) {
+ startURL = startURL.substring(1);
+ }
+
+ startURL = `https://${atenURL}/${startURL}`;
+ }
+
+ const jar = new jsdom.CookieJar();
+ const dom = await getDOM({
+ url: startURL,
+ jar,
+ runScripts: true,
+ hook
+ });
+
+ await submit({ dom, jar, username, password, atenURL });
+
+ if (postSubmit) {
+ await postSubmit({ dom, jar });
+ }
+
+ return extractStart(await getDOM({
+ url: url + account.value + '.html',
+ jar,
+ asIs: true
+ }));
+}
+
+async function submit({ dom, jar, username, password, atenURL })
+{
+ dom.window.document.getElementById('user').value = username;
+ dom.window.document.getElementById('password').value = password;
+
+ dom.window.eval('creerCookie(document.getElementById(\'user\'), document.getElementById(\'password\'));');
+
+ const result = await submitForm({
+ dom,
+ jar,
+ actionRoot: `https://${atenURL}/login/`
+ });
+
+ if (result.window.document.getElementById('aten-auth')) {
+ throw errors.WRONG_CREDENTIALS.drop();
+ }
+
+ return submitForm({
+ dom: result,
+ jar,
+ asIs: true
+ });
+}
+
+function hook(window)
+{
+ window.eval(jsEncrypt + '; window.JSEncrypt = JSEncrypt;');
+}
+
+module.exports = {
+ login,
+ submit,
+ hook
+};