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

Commit

Permalink
feat: store cookie, login in only when its needed
Browse files Browse the repository at this point in the history
  • Loading branch information
beetcb committed Dec 18, 2020
1 parent ff37ae5 commit 576ae7e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 635 deletions.
51 changes: 40 additions & 11 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,46 @@ const { signApp } = require('./campusphere/app')
const school = conf.get('school')
const users = conf.get('users')
log.object(users)
if (!users.length) log.error('未找到用户,请运行 ./init.js -u 配置')
if (!users) {
log.error('未找到用户,请运行 ./init.js -u 配置')
process.exit(1)
}

/**
* Keys of this cookie Object:
* YOU CAN USE THIS COOKIE FOR EVERYTHING
* @compusphere something about cp daliy's app
* @swms continuing log into your school's swms [stu work magagement system]
*/
let cookie, storeCookiePath

users.forEach(async i => {
/**
* Keys of this cookie Object:
* YOU CAN USE THIS COOKIE FOR EVERYTHING
* @compusphere something about cp daliy's app
* @swms continuing log into your school's swms [stu work magagement system]
*/
const cookie = await login(school, i)

const sign = new signApp(school, cookie)
await sign.signInfo()
storeCookiePath = `cookie.${i.alias || i.username}`

if (!conf.get(storeCookiePath)) {
await reLogin(i)
} else {
storeCookie(storeCookiePath)
}

let sign = new signApp(school, cookie, i)
const isNeedLogIn = await sign.signInfo()
if (isNeedLogIn) {
await reLogin(i)
sign = new signApp(school, cookie)
await sign.signInfo()
}
await sign.signWithForm()

process.exit(0)
})

async function reLogin(i) {
cookie = await login(school, i)
conf.set(storeCookiePath, cookie)
}

function storeCookie(path) {
cookie = conf.get(path)
log.success('Using stored cookie')
}
Loading

0 comments on commit 576ae7e

Please sign in to comment.