Skip to content

Commit 9fb6202

Browse files
committed
checkpoint.
1 parent f5f2924 commit 9fb6202

File tree

3 files changed

+88
-6
lines changed

3 files changed

+88
-6
lines changed

index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const password = process.env.LMS_PASSWORD;
33

44
const osmosis = require('osmosis');
55
const auth = require('./src/auth');
6+
const user = require('./src/user');
67

78
const debug = require('debug')('main');
89

@@ -17,7 +18,24 @@ class scraper {
1718
}
1819
}
1920

20-
auth.keepLoggedIn(username, password, osmosis);
21+
// auth.keepLoggedIn(username, password, osmosis);
22+
23+
auth.login(username, password, osmosis).then(function (result) {
24+
user.getLoginInfo(osmosis)
25+
.then((result) => {
26+
console.log(result);
27+
}, (err) => {
28+
console.log("Error occured " + err);
29+
});
30+
});
31+
32+
// user.getLoginInfo(osmosis)
33+
// .then((result) => {
34+
// console.log(result);
35+
// }, (err) => {
36+
// console.log("Error occured " + err);
37+
// });
38+
2139

2240

2341

src/auth.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,48 @@ const cookie = require('cookie');
33
const debug = require('debug')('auth');
44
const Promise = require('bluebird');
55

6-
// WARN: Super duplicated code
6+
// WARN: Super duplicated messy code
7+
8+
// class preauth {
9+
// static async getLoginInfo(agent) {
10+
// const homeString = 'https://lms.iiitb.ac.in/moodle/my/';
11+
// const headerMenu = '.headermenu';
12+
// const loginInfoDiv = '.logininfo';
13+
14+
// return new Promise((resolve, reject) => {
15+
// agent
16+
// .get(homeString)
17+
// // .wait(headerMenu)
18+
// .find(headerMenu)
19+
// .set({
20+
// loginInfo: loginInfoDiv,
21+
// })
22+
// .data((data) => {
23+
// if(data){
24+
// resolve(data);
25+
// } else {
26+
// reject("data-null")
27+
// }
28+
// })
29+
// .error(err => reject(err));
30+
// });
31+
// }
32+
33+
// static async isLoggedIn(agent) {
34+
// const loggedOut = 'You are not logged in.';
35+
// const loggedIn = '';
36+
// return new Promise((resolve, reject) => {
37+
// const loginStatus = preauth.getLoginInfo(agent);
38+
// loginStatus.then((result) => {
39+
// if(result === loggedOut) {
40+
// resolve('logged-out');
41+
// } else if(result.spl)
42+
43+
// }, (err) => {});
44+
// });
45+
46+
// }
47+
// }
748

849
class auth {
950
static isLoggedIn(agent) {

src/user.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
1-
const config = require('config');
1+
// const config = require('config');
22
const debug = require('debug')('auth');
33
const Promise = require('bluebird');
44

55
class user {
6-
getName(agent){
6+
static getLoginInfo(agent) {
7+
const homeString = 'https://lms.iiitb.ac.in/moodle/my/';
8+
const headerMenu = '.headermenu';
9+
const loginInfoDiv = '.logininfo';
710

8-
}
9-
}
11+
return new Promise((resolve, reject) => {
12+
agent
13+
.get(homeString)
14+
// .wait(headerMenu)
15+
.find(headerMenu)
16+
.set({
17+
loginInfo: loginInfoDiv,
18+
})
19+
.data((data) => {
20+
if(data){
21+
resolve(data);
22+
} else {
23+
reject("Null data value found.")
24+
}
25+
})
26+
.error(err => reject(err));
27+
});
28+
}
29+
}
30+
31+
32+
module.exports = user;

0 commit comments

Comments
 (0)