Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Commit

Permalink
fist push
Browse files Browse the repository at this point in the history
set the code type


add something


delete trash


push
  • Loading branch information
Jeffz615 committed Mar 18, 2020
1 parent 1a9ebf6 commit fa82e22
Show file tree
Hide file tree
Showing 6 changed files with 976 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.js linguist-language=python
*.py linguist-language=python
47 changes: 47 additions & 0 deletions PyScutLogin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# encoding:utf-8

import requests
import re
import execjs
import os

def PyScutLogin(username: str, password: str, service: str = '') -> requests.session:
u = username
p = password

url = 'https://sso.scut.edu.cn/cas/login'
if service:
url += '?service=' + service
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.22 Safari/537.36 SE 2.X MetaSr 1.0'}
session = requests.session()
r = session.get(url, headers=headers)

# lt : r'value="(LT-\d+?-\w+?-cas)"'
lt = re.findall(r'value="(LT-\d+?-\w+?-cas)"', r.text)[0]
execution = re.findall(r'name="execution" value="(.+?)"', r.text)[0]

u = u.strip()
p = p.strip()

basepath = os.path.abspath(__file__)
folder = os.path.dirname(basepath)
jspath = os.path.join(folder, 'des.js')
with open(jspath) as f:
ctx = execjs.compile(f.read())
s = u+p+lt
rsa = ctx.call('strEnc', s, '1', '2', '3')

# POST /cas/login
data = {
'rsa': rsa,
'ul': len(u),
'pl': len(p),
'lt': lt,
'execution': execution,
'_eventId': 'submit'
}
print('LoginData :',data)
r = session.post(url, data=data, headers=headers)
print('Cookies :',session.cookies.items())
return session
Loading

0 comments on commit fa82e22

Please sign in to comment.