1
1
function supportsLocalStorage ( ) {
2
2
try {
3
- return 'localStorage' in window && window [ 'localStorage' ] !== null ;
3
+ return 'localStorage' in window && window [ 'localStorage' ] !== null ;
4
4
} catch ( e ) {
5
- return false ;
5
+ return false ;
6
6
}
7
7
}
8
8
9
9
function getCachedTicket ( ) {
10
10
if ( ! supportsLocalStorage ( ) ) {
11
- return ;
11
+ return ;
12
12
}
13
13
var storedTicket = localStorage [ "webathena.ticket" ] ;
14
14
if ( ! storedTicket ) {
15
- return ;
15
+ return ;
16
16
}
17
17
var session = krb . Session . fromDict ( JSON . parse ( storedTicket ) ) ;
18
18
if ( session . isExpired ( ) ) {
19
- return ;
19
+ return ;
20
20
}
21
21
return session ;
22
22
}
23
23
24
24
function saveTicketToCache ( ticket ) {
25
25
if ( ! supportsLocalStorage ( ) ) {
26
- return ;
26
+ return ;
27
27
}
28
28
localStorage [ "webathena.ticket" ] = JSON . stringify ( ticket ) ;
29
29
}
30
30
31
31
function destroyCachedTicket ( ) {
32
32
if ( ! supportsLocalStorage ( ) ) {
33
- return ;
33
+ return ;
34
34
}
35
35
localStorage . removeItem ( "webathena.ticket" ) ;
36
36
}
37
37
38
38
function getCurrentLocker ( ) {
39
39
if ( ! supportsLocalStorage ( ) ) {
40
- return ;
40
+ return ;
41
41
}
42
42
// TODO implement this to actually work...
43
43
return getCachedTicket ( ) . client . principalName . nameString [ 0 ] ;
@@ -47,29 +47,29 @@ function getTicket() {
47
47
var deferred = Q . defer ( ) ;
48
48
var session = getCachedTicket ( ) ;
49
49
if ( session ) {
50
- deferred . resolve ( session ) ;
51
- return deferred . promise ;
50
+ deferred . resolve ( session ) ;
51
+ return deferred . promise ;
52
52
}
53
53
WinChan . open ( {
54
- url : "https://webathena.mit.edu/#!request_ticket_v1" ,
55
- relay_url : "https://webathena.mit.edu/relay.html" ,
56
- params : {
57
- realm : 'ATHENA.MIT.EDU' ,
58
- principal : [ 'host' , 'sql.mit.edu' ] ,
59
- }
54
+ url : "https://webathena.mit.edu/#!request_ticket_v1" ,
55
+ relay_url : "https://webathena.mit.edu/relay.html" ,
56
+ params : {
57
+ realm : 'ATHENA.MIT.EDU' ,
58
+ principal : [ 'host' , 'sql.mit.edu' ] ,
59
+ }
60
60
} , function ( err , r ) {
61
- console . log ( "got reply" , err , r ) ;
62
- if ( err ) {
63
- deferred . reject ( err ) ;
64
- return ;
65
- }
66
- if ( r . status !== "OK" ) {
67
- deferred . reject ( r ) ;
68
- return ;
69
- }
70
- saveTicketToCache ( r . session ) ;
71
- session = krb . Session . fromDict ( r . session ) ;
72
- deferred . resolve ( session ) ;
61
+ console . log ( "got reply" , err , r ) ;
62
+ if ( err ) {
63
+ deferred . reject ( err ) ;
64
+ return ;
65
+ }
66
+ if ( r . status !== "OK" ) {
67
+ deferred . reject ( r ) ;
68
+ return ;
69
+ }
70
+ saveTicketToCache ( r . session ) ;
71
+ session = krb . Session . fromDict ( r . session ) ;
72
+ deferred . resolve ( session ) ;
73
73
} ) ;
74
74
return deferred . promise ;
75
75
}
@@ -81,8 +81,8 @@ function updateLoginControls() {
81
81
notSignedIn . hidden = ! ! session ;
82
82
myAccount . hidden = ! session ;
83
83
if ( session ) {
84
- var username = document . getElementById ( "sql-username" ) ;
85
- username . textContent = session . client . principalName . nameString [ 0 ] ;
84
+ var username = document . getElementById ( "sql-username" ) ;
85
+ username . textContent = session . client . principalName . nameString [ 0 ] ;
86
86
}
87
87
}
88
88
@@ -100,7 +100,7 @@ document.getElementById("log-out").addEventListener("click", function (e) {
100
100
101
101
! function ( $ ) {
102
102
$ ( function ( ) {
103
- updateLoginControls ( ) ;
103
+ updateLoginControls ( ) ;
104
104
} )
105
105
} ( window . jQuery )
106
106
@@ -122,23 +122,23 @@ function remctl(command) {
122
122
var streams = { } ;
123
123
124
124
function flushStreams ( ) {
125
- var overallLength = 0 ;
126
- for ( var i = 0 ; ( i < chunks . length ) ; i ++ ) {
127
- overallLength += chunks [ i ] . length ;
128
- }
129
- var arr = new Uint8Array ( overallLength ) ;
130
- overallLength = 0 ;
131
- for ( var i = 0 ; ( i < chunks . length ) ; i ++ ) {
132
- arr . set ( chunks [ i ] , overallLength ) ;
133
- overallLength += chunks [ i ] . length ;
134
- }
135
- return arrayutils . toString ( arr ) ;
125
+ var overallLength = 0 ;
126
+ for ( var i = 0 ; ( i < chunks . length ) ; i ++ ) {
127
+ overallLength += chunks [ i ] . length ;
128
+ }
129
+ var arr = new Uint8Array ( overallLength ) ;
130
+ overallLength = 0 ;
131
+ for ( var i = 0 ; ( i < chunks . length ) ; i ++ ) {
132
+ arr . set ( chunks [ i ] , overallLength ) ;
133
+ overallLength += chunks [ i ] . length ;
134
+ }
135
+ return arrayutils . toString ( arr ) ;
136
136
}
137
137
138
138
var chunks = [ ] ;
139
139
return session . ready ( ) . then ( function ( ) {
140
140
return session . command ( command , function ( stream , data ) {
141
- chunks . push ( data ) ;
141
+ chunks . push ( data ) ;
142
142
} ) ;
143
143
} ) . then ( function ( status ) {
144
144
if ( status !== 0 && status !== 1 ) {
@@ -175,14 +175,14 @@ function showAlert(basename, heading, body, style) {
175
175
var alertTemplate = $ ( "#alert-template" ) ;
176
176
var alertPlaceholder = $ ( "#" + basename + "-placeholder" ) ;
177
177
if ( alertPlaceholder . length > 0 ) {
178
- var alertNode = alertTemplate . clone ( ) . removeAttr ( "id" ) ;
178
+ var alertNode = alertTemplate . clone ( ) . removeAttr ( "id" ) ;
179
179
alertNode . find ( ".alert-template-head" ) . text ( heading ) ;
180
180
alertNode . find ( ".alert-template-body" ) . text ( body ) ;
181
181
alertNode . removeAttr ( "hidden" ) ;
182
- if ( style ) {
182
+ if ( style ) {
183
183
alertNode . addClass ( style ) ;
184
- }
185
- alertPlaceholder . append ( alertNode ) ;
184
+ }
185
+ alertPlaceholder . append ( alertNode ) ;
186
186
}
187
187
}
188
188
@@ -193,41 +193,41 @@ function clearAlerts(basename) {
193
193
function registerModalListeners ( ) {
194
194
var cpw = $ ( '#change-password' ) ;
195
195
if ( cpw ) {
196
- cpw . unbind ( "submit" ) ;
197
- cpw . submit ( function ( e ) {
198
- e . preventDefault ( ) ;
196
+ cpw . unbind ( "submit" ) ;
197
+ cpw . submit ( function ( e ) {
198
+ e . preventDefault ( ) ;
199
199
clearAlerts ( "password-alert" ) ;
200
- pw = cpw . find ( ".field-password" ) . val ( ) ;
201
- confirmPw = cpw . find ( ".field-confirmPassword" ) . val ( )
202
- if ( pw . length < 6 ) {
203
- showAlert ( "password-alert" , "Error!" , "Password is too short." , "alert-error" ) ;
204
- return false ;
205
- }
206
- if ( pw === confirmPw ) {
207
- showAlert ( "password-alert" , "Processing!" , "Please wait." ) ;
200
+ pw = cpw . find ( ".field-password" ) . val ( ) ;
201
+ confirmPw = cpw . find ( ".field-confirmPassword" ) . val ( )
202
+ if ( pw . length < 6 ) {
203
+ showAlert ( "password-alert" , "Error!" , "Password is too short." , "alert-error" ) ;
204
+ return false ;
205
+ }
206
+ if ( pw === confirmPw ) {
207
+ showAlert ( "password-alert" , "Processing!" , "Please wait." ) ;
208
208
cpw . find ( ":submit" ) . attr ( "disabled" , "" ) ;
209
- sqlCommand ( [ "password" , "set" , getCurrentLocker ( ) , pw ] ) . finally ( function ( ) {
209
+ sqlCommand ( [ "password" , "set" , getCurrentLocker ( ) , pw ] ) . finally ( function ( ) {
210
210
clearAlerts ( "password-alert" ) ;
211
211
cpw . find ( ":submit" ) . removeAttr ( "disabled" ) ;
212
212
} ) . then ( function ( result ) {
213
- showAlert ( "password-alert" , "Success!" , "Password updated." , "alert-success" ) ;
214
- } , function ( err ) {
213
+ showAlert ( "password-alert" , "Success!" , "Password updated." , "alert-success" ) ;
214
+ } , function ( err ) {
215
215
showAlert ( "password-alert" , "Error" , "Failed to change password: " + err , "alert-error" ) ;
216
216
throw err ;
217
217
} ) . done ( ) ;
218
- return false ;
219
- }
220
- showAlert ( "password-alert" , "Error" , "Passwords do not match." , "alert-error" ) ;
221
- return false ;
222
- } ) ;
218
+ return false ;
219
+ }
220
+ showAlert ( "password-alert" , "Error" , "Passwords do not match." , "alert-error" ) ;
221
+ return false ;
222
+ } ) ;
223
223
}
224
224
var profile = $ ( '#change-profile' ) ;
225
225
if ( profile ) {
226
226
// Disable all input while we load up the profile.
227
227
profile . find ( "input" ) . attr ( "disabled" , "" ) ;
228
228
profile . find ( ":submit" ) . attr ( "disabled" , "" ) ;
229
229
230
- showAlert ( "profile-alert" , "Loading..." , "Please wait." ) ;
230
+ showAlert ( "profile-alert" , "Loading..." , "Please wait." ) ;
231
231
232
232
sqlCommand ( [ "profile" , "get" , getCurrentLocker ( ) ] ) . finally ( function ( ) {
233
233
clearAlerts ( "profile-alert" ) ;
@@ -241,8 +241,8 @@ function registerModalListeners() {
241
241
profile . find ( ".field-user-email" ) . val ( result . email ) ;
242
242
243
243
// NOW hook up the form.
244
- profile . submit ( function ( e ) {
245
- e . preventDefault ( ) ;
244
+ profile . submit ( function ( e ) {
245
+ e . preventDefault ( ) ;
246
246
clearAlerts ( "profile-alert" ) ;
247
247
248
248
var fullname = profile . find ( ".field-user-fullname" ) . val ( ) ;
@@ -252,24 +252,24 @@ function registerModalListeners() {
252
252
email : email
253
253
} ) ;
254
254
255
- showAlert ( "profile-alert" , "Processing!" , "Please wait." ) ;
255
+ showAlert ( "profile-alert" , "Processing!" , "Please wait." ) ;
256
256
cpw . find ( ":submit" ) . attr ( "disabled" , "" ) ;
257
- sqlCommand ( [ "profile" , "set" , getCurrentLocker ( ) , profileStr ] ) . finally ( function ( ) {
257
+ sqlCommand ( [ "profile" , "set" , getCurrentLocker ( ) , profileStr ] ) . finally ( function ( ) {
258
258
clearAlerts ( "profile-alert" ) ;
259
259
cpw . find ( ":submit" ) . removeAttr ( "disabled" ) ;
260
260
} ) . then ( function ( result ) {
261
- showAlert ( "profile-alert" , "Success!" , "Profile updated." , "alert-success" ) ;
262
- } , function ( err ) {
261
+ showAlert ( "profile-alert" , "Success!" , "Profile updated." , "alert-success" ) ;
262
+ } , function ( err ) {
263
263
showAlert ( "profile-alert" , "Error" , "Failed to change profile: " + err , "alert-error" ) ;
264
264
throw err ;
265
265
} ) . done ( ) ;
266
- return false ;
267
- } ) ;
266
+ return false ;
267
+ } ) ;
268
268
} , function ( err ) {
269
269
showAlert ( "profile-alert" , "Error" , "Failed to get profile: " + err , "alert-error" ) ;
270
270
} ) . done ( ) ;
271
271
272
- profile . unbind ( "submit" ) ;
272
+ profile . unbind ( "submit" ) ;
273
273
}
274
274
}
275
275
0 commit comments