99
1010from .utils import encrypt , rds
1111
12+ import time
13+ import json
14+
1215
1316def idslogin (username : str , password : str , ** kwargs ) -> Session :
1417 """Handle ids.hit.edu.cn login
@@ -32,40 +35,41 @@ def idslogin(username: str, password: str, **kwargs) -> Session:
3235 else :
3336 s = Session ()
3437 # get pwdDefaultEncryptSalt
35- r1 = s .get ('http ://ids.hit.edu.cn/authserver/login' )
36- pwd_default_encrypt_salt = re . compile (
37- 'pwdDefaultEncryptSalt = "(.*)"' ). search ( r1 . text ). groups ()[ 0 ]
38+ r1 = s .get ('https ://ids.hit.edu.cn/authserver/login' )
39+ soup = BeautifulSoup ( r1 . text , 'html.parser' ). select_one ( '#pwdFromId' )
40+ pwd_default_encrypt_salt = soup . find ( 'input' , { 'id' : 'pwdEncryptSalt' })[ 'value' ]
3841 passwordEncrypt = encrypt (
3942 rds (64 ).encode ()+ password .encode (), pwd_default_encrypt_salt .encode ())
4043 # Detect Captcha
41- r2 = s .get ('http ://ids.hit.edu.cn/authserver/needCaptcha.html ' ,
44+ r2 = s .get ('https ://ids.hit.edu.cn/authserver/checkNeedCaptcha.htl ' ,
4245 params = {
4346 'username' : username ,
44- 'pwdEncrypt2 ' : 'pwdEncryptSalt'
47+ '_ ' : round ( time . time () * 1000 )
4548 })
46- if r2 .text == 'true' :
47- if 'captchaResponse' in kwargs :
48- captchaResponse = kwargs ['captchaResponse' ]
49- else :
50- r = s .get ('http://ids.hit.edu.cn/authserver/captcha.html' , params = {
51- 'ts' : random .randint (0 , 999 )
52- })
53- raise CaptchaNeeded (s , r .content )
49+ if json .loads (r2 .text )['isNeed' ]:
50+ raise NotImplementedError ('Captcha is unsupported currently.' )
51+ # if 'captchaResponse' in kwargs:
52+ # captchaResponse = kwargs['captchaResponse']
53+ # else:
54+ # r = s.get('http://ids.hit.edu.cn/authserver/captcha.html', params={
55+ # 'ts': random.randint(0, 999)
56+ # })
57+ # raise CaptchaNeeded(s, r.content)
5458 else :
5559 captchaResponse = None
56- soup = BeautifulSoup (r1 .text , 'html.parser' )
5760 r = s .post (r1 .url , data = {
5861 "username" : username ,
5962 "password" : passwordEncrypt ,
60- "captchaResponse " : captchaResponse ,
63+ "captcha " : captchaResponse ,
6164 "lt" : soup .find ('input' , {'name' : 'lt' })['value' ],
6265 "dllt" : soup .find ('input' , {'name' : 'dllt' })['value' ],
6366 "execution" : soup .find ('input' , {'name' : 'execution' })['value' ],
6467 "_eventId" : soup .find ('input' , {'name' : '_eventId' })['value' ],
65- "rmShown " : soup .find ('input' , {'name' : 'rmShown ' })['value' ],
68+ "cllt " : soup .find ('input' , {'name' : 'cllt ' })['value' ],
6669 # "pwdDefaultEncryptSalt": pwd_default_encrypt_salt
6770 })
68- if r .url != 'http://ids.hit.edu.cn/authserver/index.do' :
71+ if r .url not in ['https://ids.hit.edu.cn/personalInfo/personCenter/index.html' ,
72+ 'https://ids.hit.edu.cn/personalInfo/personalMobile/index.html' ]:
6973 raise LoginFailed ()
7074
7175 if kwargs .get ('need_check_resp' , False ):
0 commit comments