Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
fix: move sign in to TEST
Browse files Browse the repository at this point in the history
  • Loading branch information
beetcb committed Jan 18, 2021
1 parent e238b68 commit fe84ba7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
36 changes: 36 additions & 0 deletions TEST/dcampus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { handleCookie, conf } = require('../index')
const { signApp } = require('../campusphere/app')

// Grab users array
const users = conf.get('users')
// Grab school info
const school = conf.get('school')

;(async () => {
// Log in and save cookie to conf, using conf.get('cookie') to get them
await handleCookie()
// wait * minute for signing
await sleep(0)
// Sign in
await signIn()
})()

async function sleep(timeout) {
return new Promise(r => setTimeout(r, timeout * 1000 * 60))
}

async function signIn() {
// sign in asynchronizedly with promise all and diff instance of signApp class
await Promise.all(
users.map(async i => {
const cookie = i.cookie
? { campusphere: i.cookie }
: conf.get(`cookie.${i.alias || i.username}`)

const sign = new signApp(school, i)

await sign.signInfo(cookie)
await sign.signWithForm()
})
)
}
23 changes: 2 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,7 @@ async function handleLogin(i, storedCookie) {
}
}

async function signIn(i) {
const cookie = i.cookie
? { campusphere: i.cookie }
: conf.get(`cookie.${i.alias || i.username}`)
const sign = new signApp(school, i)
await sign.signInfo(cookie)
await sign.signWithForm()
}


function storeCookie(path, i, set) {
const name = i.alias || i.username
Expand All @@ -78,16 +71,4 @@ function storeCookie(path, i, set) {
}
}

async function sleep(timeout) {
return new Promise(r => setTimeout(r, timeout * 1000 * 60))
}

;(async () => {
// Pre-loading cookie for sign in
await handleCookie()
// wait 1 minute for signing
await sleep(0)

// sign in asynchronizedly with promise all and diff instance of signApp class
Promise.all(users.map(e => signIn(e)))
})()
module.exports = { handleCookie, conf }

0 comments on commit fe84ba7

Please sign in to comment.