@@ -11,16 +11,6 @@ String.prototype.replaceAll = function(s1,s2){
1111 return this . replace ( new RegExp ( s1 , "gm" ) , s2 ) ;
1212} ;
1313
14-
15- // 生成默认用户数据
16- function GenDeUserdata ( ) {
17- var userdata = { } ;
18- userdata . username = "" ;
19- userdata . passwd = "" ;
20- userdata . flow = [ ] ;
21- return userdata ;
22- }
23-
2414buptnet = { } ;
2515
2616// 0:未登录,1:已登录
@@ -43,7 +33,7 @@ buptnet.env = {};
4333buptnet . Script2Json = function ( scriptStr ) {
4434 var retStr = [ ] ;
4535
46- scriptStr = scriptStr . replaceAll ( ';' , '\n' ) . replaceAll ( '\'' , '\"' ) ;
36+ scriptStr = scriptStr . replaceAll ( ';' , '\n' ) . replaceAll ( '\'' , '\"' ) ;
4737 scriptStr = scriptStr . match ( / .+ / g) ;
4838 scriptStr . forEach ( function ( element ) {
4939 retStr . push ( element . replace ( / ( [ \w _ ] + ) = ( .* ) / , "\"$1\":$2" ) ) ;
@@ -53,17 +43,19 @@ buptnet.Script2Json = function (scriptStr){
5343 return JSON . parse ( retStr ) ;
5444}
5545
56-
57-
58- // 充值的流量,返回单位 MB
46+ /**
47+ * 充值的流量,返回单位 MB
48+ */
5949buptnet . GetExFlow = function ( ) {
6050 var exFlow = buptnet . state_data [ 'fee' ] ;
6151 // exFlow/10000=元,一元一GB
6252 exFlow = parseInt ( exFlow / 10000 * 1024 * 1024 ) ;
6353 return buptbase . ConvertFlow ( exFlow ) ;
6454}
6555
66- // 已用流量,返回单位 MB
56+ /**
57+ * 已用流量,返回单位 MB
58+ */
6759buptnet . GetFlow = function ( ) {
6860 var flow = buptnet . state_data [ 'flow' ] ;
6961 return buptbase . ConvertFlow ( flow ) ;
@@ -80,9 +72,10 @@ buptnet.btnwait.start = function(){
8072 buptnet . btnwait . btn . text ( 'ing...' ) ;
8173 buptnet . btnwait . btn . attr ( 'disabled' , 'disabled' ) ;
8274}
83- // buptnet.btnwait = Ladda.create(document.querySelector( '#btn-login'));
8475
85- // 无动画的切换登录和登陆后的页面
76+ /**
77+ * 无动画的切换登录和登陆后的页面
78+ */
8679buptnet . ChangePage = function ( ) {
8780 if ( buptnet . state_last != buptnet . state ) {
8881
@@ -99,7 +92,10 @@ buptnet.ChangePage = function(){
9992 buptbase . log ( 'change' ) ;
10093}
10194
102- // 获取一般情况下页面内嵌入的JavaScript变量
95+ /**
96+ * 获取一般情况下页面内嵌入的JavaScript变量
97+ * @param jqObj 返回的页面的化后的jQuery对象
98+ */
10399buptnet . GetScriptData = function ( jqObj ) {
104100 // 获取页面内script参数
105101 var data = jqObj . filter ( 'script' ) . get ( 0 ) . innerText ;
@@ -108,10 +104,63 @@ buptnet.GetScriptData = function(jqObj){
108104 return buptnet . Script2Json ( data ) ;
109105}
110106
107+ /**
108+ * 检查是否为BUPT-portal环境
109+ */
110+ buptnet . BUPT_portal_Check = function ( ) {
111+ $ . ajax ( {
112+ type : "GET" ,
113+ dataType : "html" ,
114+ url : buptbase . urls . portal_server ,
115+ async : false ,
116+ success : function ( result ) {
117+ buptbase . log ( "in portal" )
118+ $ ( '#out-error' ) . hide ( ) ;
119+ $ ( '#in-error' ) . show ( ) ;
120+ } ,
121+ error : function ( data ) {
122+ buptbase . log ( "out portal" )
123+ $ ( '#in-error' ) . hide ( ) ;
124+ $ ( '#out-error' ) . show ( ) ;
125+ }
126+ } ) ;
127+
128+ }
129+
130+ /**
131+ * BUPT-portal环境且未接入校园网时候自动登录首选账号
132+ */
133+ buptnet . BUPT_portal_login = function ( ) {
134+ var su = buptnet . GetSuperUser ( ) ;
135+ if ( su . username ) {
136+ $ . ajax ( {
137+ type : "POST" ,
138+ dataType : "html" ,
139+ url : buptbase . urls . portal_serverin ,
140+ data : { 'user' :su . username , 'pass' :su . password } ,
141+ success : function ( result ) {
142+ buptbase . log ( "in portal" ) ;
143+ // 装载首选用户并登陆
144+ buptnet . LoadLoginInfo ( ) ;
145+ buptnet . Login ( ) ;
146+ // 切换面板
147+ $ ( '#error' ) . hide ( ) ;
148+ $ ( '#fun-panel' ) . show ( ) ;
149+ } ,
150+ error : function ( data ) {
151+ buptbase . log ( "out portal" ) ;
152+ }
153+ } ) ;
154+ } else {
155+ $ ( '#inlogin-fail' ) . show ( ) ;
156+ }
157+ }
158+
111159// 连接不上
112160buptnet . Ajaxfaild = function ( ) {
113161 $ ( '#login-panel' ) . hide ( ) ;
114162 $ ( '#fun-panel' ) . hide ( ) ;
163+ buptnet . BUPT_portal_Check ( ) ;
115164 $ ( '#error' ) . fadeIn ( ) ;
116165}
117166
@@ -472,7 +521,7 @@ buptnet.LoadUserList = function(){
472521/**
473522 * 绑定一些回调函数
474523 */
475- buptnet . BindButton = function ( params ) {
524+ buptnet . BindButton = function ( ) {
476525 $ ( '#btn-login' ) . click ( buptnet . Login ) ;
477526 $ ( '#btn-logoff' ) . click ( buptnet . Logoff ) ;
478527
@@ -514,6 +563,8 @@ buptnet.BindButton = function (params) {
514563 } ) ;
515564 // 绑定,模态对话框
516565 $ ( '#myModal' ) . on ( 'shown.bs.modal' , function ( ) { } ) ;
566+ //绑定portal下的一键登录
567+ $ ( '#btn-inlogin' ) . click ( buptnet . BUPT_portal_login ) ;
517568}
518569
519570/**
0 commit comments