示例#1
0
文件: login.py 项目: zlgz/school-api
    def _get_api(self, login_url, exist_verify, **kwargs):
        # 登录请求
        code = ''
        login_types = ['学生', '教师', '部门']
        login_payload = self._get_login_payload(login_url, **kwargs)
        if exist_verify:
            res = self._get('/CheckCode.aspx')
            if res.content[:7] != to_binary('GIF89aH'):
                raise CheckCodeException(self.code, "验证码获取失败")
            code = CHECK_CODE.verify(res.content)

        account = self.user.account.encode('gb2312')
        payload = {
            'txtUserName': account,
            'TextBox1': account,
            'TextBox2': self.user.password,
            'TextBox3': code,
            'txtSecretCode': code,
            'RadioButtonList1':
            login_types[self.user.user_type].encode('gb2312'),
            'Button1': ' 登 录 '.encode('gb2312')
        }
        payload.update(login_payload)

        res = self._post(login_url,
                         data=payload,
                         allow_redirects=False,
                         **kwargs)
        return res
示例#2
0
 def _handle_login_result(self, res):
     ''' 处理页面弹框信息 '''
     if res is True:
         # 登录成功
         return
     tip = get_alert_tip(res.text)
     if tip:
         if tip == '验证码不正确!!':
             raise CheckCodeException(self.code, tip)
         raise IdentityException(self.code, tip)
     raise LoginException(self.code, '教务系统请求异常')
示例#3
0
 def _handle_login_result(self, res, *args, **kwargs):
     # 登录成功之后,教务系统会返回 302 跳转
     if res.status_code == 500:
         raise LoginException(self.code, '教务系统请求异常')
     elif res.status_code != 302:
         tip = self._get_login_result_tip(res.text)
         if tip == '验证码不正确!!':
             # 首次验证码错误,则再次登录
             res = self._get_api(*args, **kwargs)
             if res.status_code != 302:
                 tip = self._get_login_result_tip(res.text)
                 if tip == '验证码不正确!!':
                     raise CheckCodeException(self.code, tip)
         raise IdentityException(self.code, tip)