def chapAuth(): try: cli = PortalClient(secret=secret, syslog=self.syslog) rc_req = PortalV2.newReqChallenge(userIp,secret, chap=is_chap) rc_resp = yield cli.sendto(rc_req,ac_addr) if rc_resp.errCode > 0: if rc_resp.errCode == 2: set_user_cookie() self.redirect(firsturl) return raise PortalError(cmcc.AckChallengeErrs[rc_resp.errCode]) # req auth ra_req = PortalV2.newReqAuth( userIp, username, password, rc_resp.reqId, rc_resp.get_challenge(), secret, ac_addr[0], serialNo=rc_req.serialNo, chap=is_chap ) ra_resp = yield cli.sendto(ra_req,ac_addr) if ra_resp.errCode > 0: if ra_resp.errCode == 2: set_user_cookie() self.redirect(firsturl) return _err_msg = "{0},{1}".format(cmcc.AckAuthErrs[ra_resp.errCode], ra_resp.get_text_info()[0] or "") raise PortalError(_err_msg) # aff_ack aa_req = PortalV2.newAffAckAuth(userIp,secret,ac_addr[0],ra_req.serialNo,rc_resp.reqId, chap=is_chap) yield cli.sendto(aa_req,ac_addr,recv=False) self.syslog.info('Portal [username:{0}] chap auth success'.format(_username)) if self.settings.debug: self.syslog.debug('Portal [username:%s] chap auth login [cast:%s ms]' % ( _username, (time.time() - start_time) * 1000)) set_user_cookie() self.redirect(firsturl) except Exception as err: try: self.syslog.exception("Portal [username:%s] chap auth catch exception, %s" % ( _username, utils.safestr(err.message))) back_login(msg=u"Portal chap auth error,%s" % err.message) except: back_login(msg=u"Portal chap auth error,server process error") finally: cli.close()
def chapAuth(): try: cli = PortalClient(secret=secret) rc_req = PortalV2.newReqChallenge(userIp, secret, chap=is_chap) rc_resp = yield cli.sendto(rc_req, ac_addr) if rc_resp.errCode > 0: if rc_resp.errCode == 2: set_user_cookie() self.redirect(firsturl) return back_login(msg=cmcc.AckChallengeErrs[rc_resp.errCode]) return # req auth ra_req = PortalV2.newReqAuth( userIp, username, password, rc_resp.reqId, rc_resp.get_challenge(), secret, ac_addr[0], serialNo=rc_req.serialNo, chap=is_chap ) ra_resp = yield cli.sendto(ra_req, ac_addr) if ra_resp.errCode > 0: if ra_resp.errCode == 2: set_user_cookie() self.redirect(firsturl) return back_login(msg="%s,%s" % (cmcc.AckAuthErrs[ra_resp.errCode], ra_resp.get_text_info()[0] or "")) return # aff_ack aa_req = PortalV2.newAffAckAuth(userIp, secret, ac_addr[0], ra_req.serialNo, rc_resp.reqId, chap=is_chap) yield cli.sendto(aa_req, ac_addr, recv=False) log.msg('auth success') set_user_cookie() self.redirect(firsturl) except Exception as err: try: log.msg(u"portal chap auth failure,%s" % err.message) back_login(msg=u"portal chap auth error,%s" % err.message) except: back_login(msg=u"portal chap auth error,server process error") import traceback traceback.print_exc() finally: cli.close()
def chapAuth(): try: cli = PortalClient(secret=secret) rc_req = PortalV2.newReqChallenge(userIp, secret, chap=is_chap) rc_resp = yield cli.sendto(rc_req, ac_addr) if rc_resp.errCode > 0: if rc_resp.errCode == 2: set_user_cookie() self.redirect(firsturl) return back_login(msg=cmcc.AckChallengeErrs[rc_resp.errCode]) return # req auth ra_req = PortalV2.newReqAuth(userIp, username, password, rc_resp.reqId, rc_resp.get_challenge(), secret, ac_addr[0], serialNo=rc_req.serialNo, chap=is_chap) ra_resp = yield cli.sendto(ra_req, ac_addr) if ra_resp.errCode > 0: if ra_resp.errCode == 2: set_user_cookie() self.redirect(firsturl) return back_login(msg="%s,%s" % (cmcc.AckAuthErrs[ra_resp.errCode], ra_resp.get_text_info()[0] or "")) return # aff_ack aa_req = PortalV2.newAffAckAuth(userIp, secret, ac_addr[0], ra_req.serialNo, rc_resp.reqId, chap=is_chap) yield cli.sendto(aa_req, ac_addr, recv=False) log.msg('auth success') set_user_cookie() self.redirect(firsturl) except Exception as err: try: log.msg(u"portal chap auth failure,%s" % err.message) back_login(msg=u"portal chap auth error,%s" % err.message) except: back_login( msg=u"portal chap auth error,server process error") import traceback traceback.print_exc() finally: cli.close()