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

Commit

Permalink
fix: log info
Browse files Browse the repository at this point in the history
  • Loading branch information
beetcb committed Dec 19, 2020
1 parent 358c5fd commit b45c61f
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 14 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules
userConf.yml
eng.traineddata
*.traineddata
package-lock.json
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<h3 align="center">campushpere-auth-simplified</h3>
</p>


## About

**campushpere-auth-simplified** 使用交互式的配置程序,实现了学工系统的登录
Expand All @@ -23,7 +22,7 @@
1. 安装此项目

```sh
git clone https://git.io/JL4oc
git clone https://github.com/beetcb/campushpere-auth-simplified.git
cd campushpere-auth-simplified && chmod +x init.js
npm i
```
Expand All @@ -40,7 +39,6 @@ npm i

```sh
./init.js -u

```

- 使用文件配置用户: 根目录下创建 `userConf.yml`, 参考以下示例:
Expand All @@ -61,14 +59,15 @@ npm i
```sh
node index.js
```

3. 扩展:

注意: 只需要引入 `crawler/casLogin.js` 作为模块即可获得验证 cookie 信息对象,含 `swms``campusphere` 参数,分别对应 学工 和 金智教务(今日校园相关) 验证凭据


## Features

- 交互式配置: `campushpere-awesome-auth` 提供交互式的命令行完成 用户 及 学校 的配置,同时也支持使用 `yml` 文件来配置

- 验证持久化: 缓存验证信息于内存, 只在失效时更新

## Thanks
Expand All @@ -77,6 +76,6 @@ node index.js

## Disclaimer

`campushpere-auth-simplified` 用于学习和研究 NodeJs,请勿商用或非法使用
`campushpere-auth-simplified` 用于学习和研究 NodeJS,请勿商用或违法使用

> 作者: [`beetcb`](https://www.beetcb.com), 邮箱: `[email protected]`
2 changes: 0 additions & 2 deletions campusphere/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ exports.signApp = class signApp extends (
})

if (res.headers.hasOwnProperty('set-cookie')) return true

const signQ = await res.json()
this.curTask = signQ.datas.unSignedTasks[0]
return false
Expand Down Expand Up @@ -164,6 +163,5 @@ exports.signApp = class signApp extends (

let decrypted = decipher.update(encrypted, 'base64', 'utf8')
decrypted += decipher.final('utf8')
console.log(decrypted)
}
}
2 changes: 1 addition & 1 deletion crawler/casLogIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ module.exports = async function login(school, user) {
headers,
redirect: 'manual',
})

reCook(res, 0)

return cookie
}

Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { signApp } = require('./campusphere/app')

const school = conf.get('school')
const users = conf.get('users')
log.object(users)

if (!users) {
log.error('未找到用户,请运行 ./init.js -u 配置')
process.exit(1)
Expand All @@ -30,21 +30,21 @@ users.forEach(async i => {
storeCookie(storeCookiePath)
}

let sign = new signApp(school, cookie, i)
let sign = new signApp(school, cookie)
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)
log.success('Cookie stored to local storage')
}

function storeCookie(path) {
Expand Down
1 change: 0 additions & 1 deletion init.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class User {
const doc = yaml.load(fs.readFileSync(path, 'utf8'))
if (!doc) return
loadedUsers = doc
log.object(doc)
} catch (e) {
console.log(e)
}
Expand Down
Empty file added userConf.yml
Empty file.

0 comments on commit b45c61f

Please sign in to comment.