106 * @param int The security level to authenticate at - see http://docs.enanocms.org/Help:Appendix_B |
106 * @param int The security level to authenticate at - see http://docs.enanocms.org/Help:Appendix_B |
107 */ |
107 */ |
108 |
108 |
109 window.ajaxLoginInit = function(call_on_finish, user_level) |
109 window.ajaxLoginInit = function(call_on_finish, user_level) |
110 { |
110 { |
111 load_component(['messagebox', 'flyin', 'fadefilter', 'jquery', 'jquery-ui', 'l10n', 'crypto']); |
111 load_component(['messagebox', 'flyin', 'fadefilter', 'jquery', 'jquery-ui', 'l10n', 'crypto']); |
112 |
112 |
113 logindata = {}; |
113 logindata = {}; |
114 |
114 |
115 var title = ( user_level > USER_LEVEL_MEMBER ) ? $lang.get('user_login_ajax_prompt_title_elev') : $lang.get('user_login_ajax_prompt_title'); |
115 var title = ( user_level > USER_LEVEL_MEMBER ) ? $lang.get('user_login_ajax_prompt_title_elev') : $lang.get('user_login_ajax_prompt_title'); |
116 logindata.mb_object = new MessageBox(MB_OKCANCEL | MB_ICONLOCK, title, ''); |
116 logindata.mb_object = new MessageBox(MB_OKCANCEL | MB_ICONLOCK, title, ''); |
117 |
117 |
118 // |
118 // |
119 // Cancel function: called when the "Cancel" button is clicked |
119 // Cancel function: called when the "Cancel" button is clicked |
120 // |
120 // |
121 logindata.mb_object.onclick['Cancel'] = function() |
121 logindata.mb_object.onclick['Cancel'] = function() |
122 { |
122 { |
123 // Hide the error message, if any |
123 // Hide the error message, if any |
124 $('#ajax_login_error_box').remove(); |
124 $('#ajax_login_error_box').remove(); |
125 // Hide the captcha, if any |
125 // Hide the captcha, if any |
126 if ( document.getElementById('autoCaptcha') ) |
126 if ( document.getElementById('autoCaptcha') ) |
127 { |
127 { |
128 var to = fly_out_top(document.getElementById('autoCaptcha'), false, true); |
128 var to = fly_out_top(document.getElementById('autoCaptcha'), false, true); |
129 setTimeout(function() { |
129 setTimeout(function() { |
130 var d = document.getElementById('autoCaptcha'); |
130 var d = document.getElementById('autoCaptcha'); |
131 d.parentNode.removeChild(d); |
131 d.parentNode.removeChild(d); |
132 }, to); |
132 }, to); |
133 } |
133 } |
134 // Ask the server to delete the encryption key we're using |
134 // Ask the server to delete the encryption key we're using |
135 ajaxLoginPerformRequest({ |
135 ajaxLoginPerformRequest({ |
136 mode: 'clean_key', |
136 mode: 'clean_key', |
137 key_aes: logindata.key_aes, |
137 key_aes: logindata.key_aes, |
138 key_dh: logindata.key_dh |
138 key_dh: logindata.key_dh |
139 }); |
139 }); |
140 }; |
140 }; |
141 |
141 |
142 // Clicking OK will not cause the box to destroy, as this function returns true. |
142 // Clicking OK will not cause the box to destroy, as this function returns true. |
143 logindata.mb_object.onbeforeclick['OK'] = function() |
143 logindata.mb_object.onbeforeclick['OK'] = function() |
144 { |
144 { |
145 // Just call the submitter and let it take care of everything |
145 // Just call the submitter and let it take care of everything |
146 ajaxLoginSubmitForm(); |
146 ajaxLoginSubmitForm(); |
147 return true; |
147 return true; |
148 } |
148 } |
149 |
149 |
150 // Fetch the inner content area |
150 // Fetch the inner content area |
151 logindata.mb_inner = document.getElementById('messageBox').getElementsByTagName('div')[0]; |
151 logindata.mb_inner = document.getElementById('messageBox').getElementsByTagName('div')[0]; |
152 |
152 |
153 // Initialize state |
153 // Initialize state |
154 logindata.showing_status = false; |
154 logindata.showing_status = false; |
155 logindata.user_level = user_level; |
155 logindata.user_level = user_level; |
156 logindata.successfunc = call_on_finish; |
156 logindata.successfunc = call_on_finish; |
157 |
157 |
158 // Build the "loading" window |
158 // Build the "loading" window |
159 ajaxLoginSetStatus(AJAX_STATUS_LOADING_KEY); |
159 ajaxLoginSetStatus(AJAX_STATUS_LOADING_KEY); |
160 |
160 |
161 // Request the key |
161 // Request the key |
162 ajaxLoginPerformRequest({ mode: 'getkey' }); |
162 ajaxLoginPerformRequest({ mode: 'getkey' }); |
163 } |
163 } |
164 |
164 |
165 /** |
165 /** |
166 * For compatibility only. Really, folks, it's ajaxLoginInit. If you need a |
166 * For compatibility only. Really, folks, it's ajaxLoginInit. If you need a |
167 * mnemonic device, use "two 'in's." |
167 * mnemonic device, use "two 'in's." |
168 */ |
168 */ |
169 |
169 |
170 window.ajaxLogonInit = function(call_on_finish, user_level) |
170 window.ajaxLogonInit = function(call_on_finish, user_level) |
171 { |
171 { |
172 return ajaxLoginInit(call_on_finish, user_level); |
172 return ajaxLoginInit(call_on_finish, user_level); |
173 } |
173 } |
174 |
174 |
175 /** |
175 /** |
176 * Sets the contents of the AJAX login window to the appropriate status message. |
176 * Sets the contents of the AJAX login window to the appropriate status message. |
177 * @param int One of AJAX_STATUS_* constants |
177 * @param int One of AJAX_STATUS_* constants |
178 */ |
178 */ |
179 |
179 |
180 window.ajaxLoginSetStatus = function(status) |
180 window.ajaxLoginSetStatus = function(status) |
181 { |
181 { |
182 if ( !logindata.mb_inner ) |
182 if ( !logindata.mb_inner ) |
183 return false; |
183 return false; |
184 if ( logindata.showing_status ) |
184 if ( logindata.showing_status ) |
185 { |
185 { |
186 var div = document.getElementById('ajax_login_status'); |
186 var div = document.getElementById('ajax_login_status'); |
187 if ( div ) |
187 if ( div ) |
188 logindata.mb_inner.removeChild(div); |
188 logindata.mb_inner.removeChild(div); |
189 } |
189 } |
190 switch(status) |
190 switch(status) |
191 { |
191 { |
192 case AJAX_STATUS_LOADING_KEY: |
192 case AJAX_STATUS_LOADING_KEY: |
193 |
193 |
194 // Create the status div |
194 // Create the status div |
195 var div = document.createElement('div'); |
195 var div = document.createElement('div'); |
196 div.id = 'ajax_login_status'; |
196 div.id = 'ajax_login_status'; |
197 div.style.marginTop = '10px'; |
197 div.style.marginTop = '10px'; |
198 div.style.textAlign = 'center'; |
198 div.style.textAlign = 'center'; |
199 |
199 |
200 // The circly ball ajaxy image + status message |
200 // The circly ball ajaxy image + status message |
201 var status_msg = $lang.get('user_login_ajax_fetching_key'); |
201 var status_msg = $lang.get('user_login_ajax_fetching_key'); |
202 |
202 |
203 // Insert the status message |
203 // Insert the status message |
204 div.appendChild(document.createTextNode(status_msg)); |
204 div.appendChild(document.createTextNode(status_msg)); |
205 |
205 |
206 // Append a br or two to space things properly |
206 // Append a br or two to space things properly |
207 div.appendChild(document.createElement('br')); |
207 div.appendChild(document.createElement('br')); |
208 div.appendChild(document.createElement('br')); |
208 div.appendChild(document.createElement('br')); |
209 |
209 |
210 var img = document.createElement('img'); |
210 var img = document.createElement('img'); |
211 img.src = ( ajax_login_loadimg_path ) ? ajax_login_loadimg_path : scriptPath + '/images/loading-big.gif'; |
211 img.src = ( ajax_login_loadimg_path ) ? ajax_login_loadimg_path : scriptPath + '/images/loading-big.gif'; |
212 div.appendChild(img); |
212 div.appendChild(img); |
213 |
213 |
214 // Another coupla brs |
214 // Another coupla brs |
215 div.appendChild(document.createElement('br')); |
215 div.appendChild(document.createElement('br')); |
216 div.appendChild(document.createElement('br')); |
216 div.appendChild(document.createElement('br')); |
217 |
217 |
218 // The link to the full login form |
218 // The link to the full login form |
219 var small = document.createElement('small'); |
219 var small = document.createElement('small'); |
220 small.innerHTML = $lang.get('user_login_ajax_link_fullform', { link_full_form: makeUrlNS('Special', 'Login/' + title) }); |
220 small.innerHTML = $lang.get('user_login_ajax_link_fullform', { link_full_form: makeUrlNS('Special', 'Login/' + title) }); |
221 div.appendChild(small); |
221 div.appendChild(small); |
222 |
222 |
223 // Insert the entire message into the login window |
223 // Insert the entire message into the login window |
224 logindata.mb_inner.innerHTML = ''; |
224 logindata.mb_inner.innerHTML = ''; |
225 logindata.mb_inner.appendChild(div); |
225 logindata.mb_inner.appendChild(div); |
226 |
226 |
227 break; |
227 break; |
228 case AJAX_STATUS_GENERATING_KEY: |
228 case AJAX_STATUS_GENERATING_KEY: |
229 |
229 |
230 // Create the status div |
230 // Create the status div |
231 var div = document.createElement('div'); |
231 var div = document.createElement('div'); |
232 div.id = 'ajax_login_status'; |
232 div.id = 'ajax_login_status'; |
233 div.style.marginTop = '10px'; |
233 div.style.marginTop = '10px'; |
234 div.style.textAlign = 'center'; |
234 div.style.textAlign = 'center'; |
235 |
235 |
236 // The circly ball ajaxy image + status message |
236 // The circly ball ajaxy image + status message |
237 var status_msg = $lang.get('user_login_ajax_generating_key'); |
237 var status_msg = $lang.get('user_login_ajax_generating_key'); |
238 |
238 |
239 // Insert the status message |
239 // Insert the status message |
240 div.appendChild(document.createTextNode(status_msg)); |
240 div.appendChild(document.createTextNode(status_msg)); |
241 |
241 |
242 // Append a br or two to space things properly |
242 // Append a br or two to space things properly |
243 div.appendChild(document.createElement('br')); |
243 div.appendChild(document.createElement('br')); |
244 div.appendChild(document.createElement('br')); |
244 div.appendChild(document.createElement('br')); |
245 |
245 |
246 var img = document.createElement('img'); |
246 var img = document.createElement('img'); |
247 img.src = ( ajax_login_lockimg_path ) ? ajax_login_lockimg_path : scriptPath + '/images/lock48.png'; |
247 img.src = ( ajax_login_lockimg_path ) ? ajax_login_lockimg_path : scriptPath + '/images/lock48.png'; |
248 div.appendChild(img); |
248 div.appendChild(img); |
249 |
249 |
250 // Another coupla brs |
250 // Another coupla brs |
251 div.appendChild(document.createElement('br')); |
251 div.appendChild(document.createElement('br')); |
252 div.appendChild(document.createElement('br')); |
252 div.appendChild(document.createElement('br')); |
253 |
253 |
254 // The link to the full login form |
254 // The link to the full login form |
255 var small = document.createElement('small'); |
255 var small = document.createElement('small'); |
256 small.innerHTML = $lang.get('user_login_ajax_link_fullform_dh', { link_full_form: makeUrlNS('Special', 'Login/' + title) }); |
256 small.innerHTML = $lang.get('user_login_ajax_link_fullform_dh', { link_full_form: makeUrlNS('Special', 'Login/' + title) }); |
257 div.appendChild(small); |
257 div.appendChild(small); |
258 |
258 |
259 // Insert the entire message into the login window |
259 // Insert the entire message into the login window |
260 logindata.mb_inner.innerHTML = ''; |
260 logindata.mb_inner.innerHTML = ''; |
261 logindata.mb_inner.appendChild(div); |
261 logindata.mb_inner.appendChild(div); |
262 |
262 |
263 break; |
263 break; |
264 case AJAX_STATUS_LOGGING_IN: |
264 case AJAX_STATUS_LOGGING_IN: |
265 |
265 |
266 // Create the status div |
266 // Create the status div |
267 var div = document.createElement('div'); |
267 var div = document.createElement('div'); |
268 div.id = 'ajax_login_status'; |
268 div.id = 'ajax_login_status'; |
269 div.style.marginTop = '10px'; |
269 div.style.marginTop = '10px'; |
270 div.style.textAlign = 'center'; |
270 div.style.textAlign = 'center'; |
271 |
271 |
272 // The circly ball ajaxy image + status message |
272 // The circly ball ajaxy image + status message |
273 var status_msg = $lang.get('user_login_ajax_loggingin'); |
273 var status_msg = $lang.get('user_login_ajax_loggingin'); |
274 |
274 |
275 // Insert the status message |
275 // Insert the status message |
276 div.appendChild(document.createTextNode(status_msg)); |
276 div.appendChild(document.createTextNode(status_msg)); |
277 |
277 |
278 // Append a br or two to space things properly |
278 // Append a br or two to space things properly |
279 div.appendChild(document.createElement('br')); |
279 div.appendChild(document.createElement('br')); |
280 div.appendChild(document.createElement('br')); |
280 div.appendChild(document.createElement('br')); |
281 |
281 |
282 var img = document.createElement('img'); |
282 var img = document.createElement('img'); |
283 img.src = ( ajax_login_loadimg_path ) ? ajax_login_loadimg_path : scriptPath + '/images/loading-big.gif'; |
283 img.src = ( ajax_login_loadimg_path ) ? ajax_login_loadimg_path : scriptPath + '/images/loading-big.gif'; |
284 div.appendChild(img); |
284 div.appendChild(img); |
285 |
285 |
286 // Insert the entire message into the login window |
286 // Insert the entire message into the login window |
287 logindata.mb_inner.innerHTML = ''; |
287 logindata.mb_inner.innerHTML = ''; |
288 logindata.mb_inner.appendChild(div); |
288 logindata.mb_inner.appendChild(div); |
289 |
289 |
290 break; |
290 break; |
291 case AJAX_STATUS_SUCCESS: |
291 case AJAX_STATUS_SUCCESS: |
292 |
292 |
293 // Create the status div |
293 // Create the status div |
294 var div = document.createElement('div'); |
294 var div = document.createElement('div'); |
295 div.id = 'ajax_login_status'; |
295 div.id = 'ajax_login_status'; |
296 div.style.marginTop = '10px'; |
296 div.style.marginTop = '10px'; |
297 div.style.textAlign = 'center'; |
297 div.style.textAlign = 'center'; |
298 |
298 |
299 // The circly ball ajaxy image + status message |
299 // The circly ball ajaxy image + status message |
300 var status_msg = $lang.get('user_login_success_short'); |
300 var status_msg = $lang.get('user_login_success_short'); |
301 |
301 |
302 // Insert the status message |
302 // Insert the status message |
303 div.appendChild(document.createTextNode(status_msg)); |
303 div.appendChild(document.createTextNode(status_msg)); |
304 |
304 |
305 // Append a br or two to space things properly |
305 // Append a br or two to space things properly |
306 div.appendChild(document.createElement('br')); |
306 div.appendChild(document.createElement('br')); |
307 div.appendChild(document.createElement('br')); |
307 div.appendChild(document.createElement('br')); |
308 |
308 |
309 var img = document.createElement('img'); |
309 var img = document.createElement('img'); |
310 img.src = ( ajax_login_successimg_path ) ? ajax_login_successimg_path : scriptPath + '/images/check.png'; |
310 img.src = ( ajax_login_successimg_path ) ? ajax_login_successimg_path : scriptPath + '/images/check.png'; |
311 div.appendChild(img); |
311 div.appendChild(img); |
312 |
312 |
313 // Insert the entire message into the login window |
313 // Insert the entire message into the login window |
314 logindata.mb_inner.innerHTML = ''; |
314 logindata.mb_inner.innerHTML = ''; |
315 logindata.mb_inner.appendChild(div); |
315 logindata.mb_inner.appendChild(div); |
316 |
316 |
317 break; |
317 break; |
318 |
318 |
319 case AJAX_STATUS_ERROR: |
319 case AJAX_STATUS_ERROR: |
320 // Create the status div |
320 // Create the status div |
321 var div = document.createElement('div'); |
321 var div = document.createElement('div'); |
322 div.id = 'ajax_login_status'; |
322 div.id = 'ajax_login_status'; |
323 div.style.marginTop = '10px'; |
323 div.style.marginTop = '10px'; |
324 div.style.textAlign = 'center'; |
324 div.style.textAlign = 'center'; |
325 |
325 |
326 // The circly ball ajaxy image + status message |
326 // The circly ball ajaxy image + status message |
327 var status_msg = $lang.get('user_login_ajax_err_crypto'); |
327 var status_msg = $lang.get('user_login_ajax_err_crypto'); |
328 |
328 |
329 // Insert the status message |
329 // Insert the status message |
330 div.appendChild(document.createTextNode(status_msg)); |
330 div.appendChild(document.createTextNode(status_msg)); |
331 |
331 |
332 // Append a br or two to space things properly |
332 // Append a br or two to space things properly |
333 div.appendChild(document.createElement('br')); |
333 div.appendChild(document.createElement('br')); |
334 div.appendChild(document.createElement('br')); |
334 div.appendChild(document.createElement('br')); |
335 |
335 |
336 var img = document.createElement('img'); |
336 var img = document.createElement('img'); |
337 img.src = ( ajax_login_successimg_path ) ? ajax_login_successimg_path : scriptPath + '/images/checkbad.png'; |
337 img.src = ( ajax_login_successimg_path ) ? ajax_login_successimg_path : scriptPath + '/images/checkbad.png'; |
338 div.appendChild(img); |
338 div.appendChild(img); |
339 |
339 |
340 // Append a br or two to space things properly |
340 // Append a br or two to space things properly |
341 div.appendChild(document.createElement('br')); |
341 div.appendChild(document.createElement('br')); |
342 div.appendChild(document.createElement('br')); |
342 div.appendChild(document.createElement('br')); |
343 |
343 |
344 // The circly ball ajaxy image + status message |
344 // The circly ball ajaxy image + status message |
345 var detail_msg = $lang.get('user_login_ajax_err_crypto_details'); |
345 var detail_msg = $lang.get('user_login_ajax_err_crypto_details'); |
346 var full_link = $lang.get('user_login_ajax_err_crypto_link'); |
346 var full_link = $lang.get('user_login_ajax_err_crypto_link'); |
347 var link = document.createElement('a'); |
347 var link = document.createElement('a'); |
348 link.href = makeUrlNS('Special', 'Login/' + title, 'level=' + logindata.user_level, true); |
348 link.href = makeUrlNS('Special', 'Login/' + title, 'level=' + logindata.user_level, true); |
349 link.appendChild(document.createTextNode(full_link)); |
349 link.appendChild(document.createTextNode(full_link)); |
350 var span = document.createElement('span'); |
350 var span = document.createElement('span'); |
351 span.style.fontSize = 'smaller'; |
351 span.style.fontSize = 'smaller'; |
352 |
352 |
353 // Insert the message |
353 // Insert the message |
354 span.appendChild(document.createTextNode(detail_msg + ' ')); |
354 span.appendChild(document.createTextNode(detail_msg + ' ')); |
355 span.appendChild(link); |
355 span.appendChild(link); |
356 div.appendChild(span); |
356 div.appendChild(span); |
357 |
357 |
358 // Insert the entire message into the login window |
358 // Insert the entire message into the login window |
359 logindata.mb_inner.innerHTML = ''; |
359 logindata.mb_inner.innerHTML = ''; |
360 logindata.mb_inner.appendChild(div); |
360 logindata.mb_inner.appendChild(div); |
361 |
361 |
362 break; |
362 break; |
363 |
363 |
364 default: |
364 default: |
365 eval(setHook('login_set_status')); |
365 eval(setHook('login_set_status')); |
366 break; |
366 break; |
367 |
367 |
368 case AJAX_STATUS_DESTROY: |
368 case AJAX_STATUS_DESTROY: |
369 case null: |
369 case null: |
370 case undefined: |
370 case undefined: |
371 logindata.showing_status = false; |
371 logindata.showing_status = false; |
372 return; |
372 return; |
373 break; |
373 break; |
374 } |
374 } |
375 logindata.showing_status = true; |
375 logindata.showing_status = true; |
376 } |
376 } |
377 |
377 |
378 /** |
378 /** |
379 * Performs an AJAX logon request to the server and calls ajaxLoginProcessResponse() on the result. |
379 * Performs an AJAX logon request to the server and calls ajaxLoginProcessResponse() on the result. |
380 * @param object JSON packet to send |
380 * @param object JSON packet to send |
381 * @param function Optional function to call on the response as well. |
381 * @param function Optional function to call on the response as well. |
382 */ |
382 */ |
383 |
383 |
384 window.ajaxLoginPerformRequest = function(json, _hookfunc) |
384 window.ajaxLoginPerformRequest = function(json, _hookfunc) |
385 { |
385 { |
386 json = toJSONString(json); |
386 json = toJSONString(json); |
387 json = ajaxEscape(json); |
387 json = ajaxEscape(json); |
388 var hookfunc = typeof(_hookfunc) == 'function' ? _hookfunc : false; |
388 var hookfunc = typeof(_hookfunc) == 'function' ? _hookfunc : false; |
389 ajaxPost(makeUrlNS('Special', 'Login/action.json'), 'r=' + json, function(ajax) |
389 ajaxPost(makeUrlNS('Special', 'Login/action.json'), 'r=' + json, function(ajax) |
390 { |
390 { |
391 if ( ajax.readyState == 4 && ajax.status == 200 ) |
391 if ( ajax.readyState == 4 && ajax.status == 200 ) |
392 { |
392 { |
393 // parse response |
393 // parse response |
394 var response = String(ajax.responseText + ''); |
394 var response = String(ajax.responseText + ''); |
395 if ( !check_json_response(response) ) |
395 if ( !check_json_response(response) ) |
396 { |
396 { |
397 handle_invalid_json(response); |
397 handle_invalid_json(response); |
398 return false; |
398 return false; |
399 } |
399 } |
400 response = parseJSON(response); |
400 response = parseJSON(response); |
401 ajaxLoginProcessResponse(response, hookfunc); |
401 ajaxLoginProcessResponse(response, hookfunc); |
402 } |
402 } |
403 }, true); |
403 }, true); |
404 } |
404 } |
405 |
405 |
406 /** |
406 /** |
407 * Processes a response from the login server |
407 * Processes a response from the login server |
408 * @param object JSON response |
408 * @param object JSON response |
409 */ |
409 */ |
410 |
410 |
411 window.ajaxLoginProcessResponse = function(response, hookfunc) |
411 window.ajaxLoginProcessResponse = function(response, hookfunc) |
412 { |
412 { |
413 // Did the server send a plaintext error? |
413 // Did the server send a plaintext error? |
414 if ( response.mode == 'error' ) |
414 if ( response.mode == 'error' ) |
415 { |
415 { |
416 if ( logindata.mb_object ) |
416 if ( logindata.mb_object ) |
417 { |
417 { |
418 logindata.mb_object.destroy(); |
418 logindata.mb_object.destroy(); |
419 var error_msg = $lang.get('user_' + ( response.error.toLowerCase() )); |
419 var error_msg = $lang.get('user_' + ( response.error.toLowerCase() )); |
420 new MessageBox(MB_ICONSTOP | MB_OK, $lang.get('user_err_login_generic_title'), error_msg); |
420 new MessageBox(MB_ICONSTOP | MB_OK, $lang.get('user_err_login_generic_title'), error_msg); |
421 } |
421 } |
422 else |
422 else |
423 { |
423 { |
424 alert(response.error); |
424 alert(response.error); |
425 } |
425 } |
426 return false; |
426 return false; |
427 } |
427 } |
428 |
428 |
429 // Main mode switch |
429 // Main mode switch |
430 switch ( response.mode ) |
430 switch ( response.mode ) |
431 { |
431 { |
432 case 'initial': |
432 case 'initial': |
433 // Rid ourselves of any loading windows |
433 // Rid ourselves of any loading windows |
434 ajaxLoginSetStatus(AJAX_STATUS_DESTROY); |
434 ajaxLoginSetStatus(AJAX_STATUS_DESTROY); |
435 // show any errors |
435 // show any errors |
436 ajaxLoginShowFriendlyError(response); |
436 ajaxLoginShowFriendlyError(response); |
437 // The server wants us to build the login form, all the information is there |
437 // The server wants us to build the login form, all the information is there |
438 ajaxLoginBuildForm(response); |
438 ajaxLoginBuildForm(response); |
439 break; |
439 break; |
440 case 'login_success': |
440 case 'login_success': |
441 ajaxLoginSetStatus(AJAX_STATUS_SUCCESS); |
441 ajaxLoginSetStatus(AJAX_STATUS_SUCCESS); |
442 logindata.successfunc(response.key, response); |
442 logindata.successfunc(response.key, response); |
443 break; |
443 break; |
444 case 'reset_pass_used': |
444 case 'reset_pass_used': |
445 // We logged in with a temporary password. Prompt the user to go to the temp password page and |
445 // We logged in with a temporary password. Prompt the user to go to the temp password page and |
446 // reset their real password. If they click no, treat it as a login failure, as no session key |
446 // reset their real password. If they click no, treat it as a login failure, as no session key |
447 // is actually issued when this type of login is performed. |
447 // is actually issued when this type of login is performed. |
448 |
448 |
449 var conf = confirm($lang.get('user_login_ajax_msg_used_temp_pass')); |
449 var conf = confirm($lang.get('user_login_ajax_msg_used_temp_pass')); |
450 if ( conf ) |
450 if ( conf ) |
451 { |
451 { |
452 var url = makeUrlNS('Special', 'PasswordReset/stage2/' + response.user_id + '/' + response.temp_password); |
452 var url = makeUrlNS('Special', 'PasswordReset/stage2/' + response.user_id + '/' + response.temp_password); |
453 window.location = url; |
453 window.location = url; |
454 break; |
454 break; |
455 } |
455 } |
456 // else, treat as a failure |
456 // else, treat as a failure |
457 default: |
457 default: |
458 // Rid ourselves of any loading windows |
458 // Rid ourselves of any loading windows |
459 ajaxLoginSetStatus(AJAX_STATUS_DESTROY); |
459 ajaxLoginSetStatus(AJAX_STATUS_DESTROY); |
460 document.getElementById('messageBox').style.backgroundColor = '#C0C0C0'; |
460 document.getElementById('messageBox').style.backgroundColor = '#C0C0C0'; |
461 var mb_parent = document.getElementById('messageBox').parentNode; |
461 var mb_parent = document.getElementById('messageBox').parentNode; |
462 $(mb_parent).effect("shake", {}, 200); |
462 $(mb_parent).effect("shake", {}, 200); |
463 setTimeout(function() |
463 setTimeout(function() |
464 { |
464 { |
465 document.getElementById('messageBox').style.backgroundColor = '#FFF'; |
465 document.getElementById('messageBox').style.backgroundColor = '#FFF'; |
466 console.debug(response); |
466 console.debug(response); |
467 ajaxLoginShowFriendlyError(response); |
467 ajaxLoginShowFriendlyError(response); |
468 ajaxLoginBuildForm(response); |
468 ajaxLoginBuildForm(response); |
469 }, 2500); |
469 }, 2500); |
470 |
470 |
471 break; |
471 break; |
472 case 'logout_success': |
472 case 'logout_success': |
473 if ( ENANO_SID ) |
473 if ( ENANO_SID ) |
474 { |
474 { |
475 ajaxLoginReplaceSIDInline(false, ENANO_SID, USER_LEVEL_MEMBER); |
475 ajaxLoginReplaceSIDInline(false, ENANO_SID, USER_LEVEL_MEMBER); |
476 } |
476 } |
477 break; |
477 break; |
478 case 'noop': |
478 case 'noop': |
479 break; |
479 break; |
480 } |
480 } |
481 if ( hookfunc ) |
481 if ( hookfunc ) |
482 { |
482 { |
483 hookfunc(response); |
483 hookfunc(response); |
484 } |
484 } |
485 } |
485 } |
486 |
486 |
487 /* |
487 /* |
488 * RESPONSE HANDLERS |
488 * RESPONSE HANDLERS |
489 */ |
489 */ |
493 * @param object Metadata to build off of |
493 * @param object Metadata to build off of |
494 */ |
494 */ |
495 |
495 |
496 window.ajaxLoginBuildForm = function(data) |
496 window.ajaxLoginBuildForm = function(data) |
497 { |
497 { |
498 // let's hope this effectively preloads the image... |
498 // let's hope this effectively preloads the image... |
499 var _1 = document.createElement('img'); |
499 var _1 = document.createElement('img'); |
500 _1.src = ( ajax_login_successimg_path ) ? ajax_login_successimg_path : scriptPath + '/images/check.png'; |
500 _1.src = ( ajax_login_successimg_path ) ? ajax_login_successimg_path : scriptPath + '/images/check.png'; |
501 var _2 = document.createElement('img'); |
501 var _2 = document.createElement('img'); |
502 _2.src = ( ajax_login_lockimg_path ) ? ajax_login_lockimg_path : scriptPath + '/images/lock48.png'; |
502 _2.src = ( ajax_login_lockimg_path ) ? ajax_login_lockimg_path : scriptPath + '/images/lock48.png'; |
503 |
503 |
504 var div = document.createElement('div'); |
504 var div = document.createElement('div'); |
505 div.id = 'ajax_login_form'; |
505 div.id = 'ajax_login_form'; |
506 |
506 |
507 var show_captcha = ( data.lockout.active && data.lockout.policy == 'captcha' ) ? data.lockout.captcha : false; |
507 var show_captcha = ( data.lockout.active && data.lockout.policy == 'captcha' ) ? data.lockout.captcha : false; |
508 |
508 |
509 // text displayed on re-auth |
509 // text displayed on re-auth |
510 if ( logindata.user_level > USER_LEVEL_MEMBER ) |
510 if ( logindata.user_level > USER_LEVEL_MEMBER ) |
511 { |
511 { |
512 div.innerHTML += $lang.get('user_login_ajax_prompt_body_elev') + '<br /><br />'; |
512 div.innerHTML += $lang.get('user_login_ajax_prompt_body_elev') + '<br /><br />'; |
513 } |
513 } |
514 |
514 |
515 // Create the form |
515 // Create the form |
516 var form = document.createElement('form'); |
516 var form = document.createElement('form'); |
517 form.action = 'javascript:void(ajaxLoginSubmitForm());'; |
517 form.action = 'javascript:void(ajaxLoginSubmitForm());'; |
518 form.onsubmit = function() |
518 form.onsubmit = function() |
519 { |
519 { |
520 ajaxLoginSubmitForm(); |
520 ajaxLoginSubmitForm(); |
521 return false; |
521 return false; |
522 } |
522 } |
523 if ( IE ) |
523 if ( IE ) |
524 { |
524 { |
525 form.style.marginTop = '-20px'; |
525 form.style.marginTop = '-20px'; |
526 } |
526 } |
527 |
527 |
528 // Using tables to wrap form elements because it results in a |
528 // Using tables to wrap form elements because it results in a |
529 // more visually appealing form. Yes, tables suck. I don't really |
529 // more visually appealing form. Yes, tables suck. I don't really |
530 // care - they make forms look good. |
530 // care - they make forms look good. |
531 |
531 |
532 var table = document.createElement('table'); |
532 var table = document.createElement('table'); |
533 table.style.margin = '0 auto'; |
533 table.style.margin = '0 auto'; |
534 |
534 |
535 // Field - username |
535 // Field - username |
536 var tr1 = document.createElement('tr'); |
536 var tr1 = document.createElement('tr'); |
537 var td1_1 = document.createElement('td'); |
537 var td1_1 = document.createElement('td'); |
538 td1_1.appendChild(document.createTextNode($lang.get('user_login_field_username') + ':')); |
538 td1_1.appendChild(document.createTextNode($lang.get('user_login_field_username') + ':')); |
539 tr1.appendChild(td1_1); |
539 tr1.appendChild(td1_1); |
540 var td1_2 = document.createElement('td'); |
540 var td1_2 = document.createElement('td'); |
541 var f_username = document.createElement('input'); |
541 var f_username = document.createElement('input'); |
542 f_username.id = 'ajax_login_field_username'; |
542 f_username.id = 'ajax_login_field_username'; |
543 f_username.name = 'ajax_login_field_username'; |
543 f_username.name = 'ajax_login_field_username'; |
544 f_username.type = 'text'; |
544 f_username.type = 'text'; |
545 f_username.size = '25'; |
545 f_username.size = '25'; |
546 if ( data.username ) |
546 if ( data.username ) |
547 f_username.value = data.username; |
547 f_username.value = data.username; |
548 td1_2.appendChild(f_username); |
548 td1_2.appendChild(f_username); |
549 tr1.appendChild(td1_2); |
549 tr1.appendChild(td1_2); |
550 table.appendChild(tr1); |
550 table.appendChild(tr1); |
551 |
551 |
552 // Field - password |
552 // Field - password |
553 var tr2 = document.createElement('tr'); |
553 var tr2 = document.createElement('tr'); |
554 var td2_1 = document.createElement('td'); |
554 var td2_1 = document.createElement('td'); |
555 td2_1.appendChild(document.createTextNode($lang.get('user_login_field_password') + ':')); |
555 td2_1.appendChild(document.createTextNode($lang.get('user_login_field_password') + ':')); |
556 tr2.appendChild(td2_1); |
556 tr2.appendChild(td2_1); |
557 var td2_2 = document.createElement('td'); |
557 var td2_2 = document.createElement('td'); |
558 var f_password = document.createElement('input'); |
558 var f_password = document.createElement('input'); |
559 f_password.id = 'ajax_login_field_password'; |
559 f_password.id = 'ajax_login_field_password'; |
560 f_password.name = 'ajax_login_field_username'; |
560 f_password.name = 'ajax_login_field_username'; |
561 f_password.type = 'password'; |
561 f_password.type = 'password'; |
562 f_password.size = '25'; |
562 f_password.size = '25'; |
563 if ( !show_captcha ) |
563 if ( !show_captcha ) |
564 { |
564 { |
565 f_password.onkeyup = function(e) |
565 f_password.onkeyup = function(e) |
566 { |
566 { |
567 if ( !e ) |
567 if ( !e ) |
568 e = window.event; |
568 e = window.event; |
569 if ( !e && IE ) |
569 if ( !e && IE ) |
570 return true; |
570 return true; |
571 if ( e.keyCode == 13 ) |
571 if ( e.keyCode == 13 ) |
572 { |
572 { |
573 ajaxLoginSubmitForm(); |
573 ajaxLoginSubmitForm(); |
574 } |
574 } |
575 } |
575 } |
576 } |
576 } |
577 td2_2.appendChild(f_password); |
577 td2_2.appendChild(f_password); |
578 tr2.appendChild(td2_2); |
578 tr2.appendChild(td2_2); |
579 table.appendChild(tr2); |
579 table.appendChild(tr2); |
580 |
580 |
581 // Field - captcha |
581 // Field - captcha |
582 if ( show_captcha ) |
582 if ( show_captcha ) |
583 { |
583 { |
584 var tr3 = document.createElement('tr'); |
584 var tr3 = document.createElement('tr'); |
585 var td3_1 = document.createElement('td'); |
585 var td3_1 = document.createElement('td'); |
586 td3_1.appendChild(document.createTextNode($lang.get('user_login_field_captcha') + ':')); |
586 td3_1.appendChild(document.createTextNode($lang.get('user_login_field_captcha') + ':')); |
587 tr3.appendChild(td3_1); |
587 tr3.appendChild(td3_1); |
588 var td3_2 = document.createElement('td'); |
588 var td3_2 = document.createElement('td'); |
589 var f_captcha = document.createElement('input'); |
589 var f_captcha = document.createElement('input'); |
590 f_captcha.id = 'ajax_login_field_captcha'; |
590 f_captcha.id = 'ajax_login_field_captcha'; |
591 f_captcha.name = 'ajax_login_field_username'; |
591 f_captcha.name = 'ajax_login_field_username'; |
592 f_captcha.type = 'text'; |
592 f_captcha.type = 'text'; |
593 f_captcha.size = '25'; |
593 f_captcha.size = '25'; |
594 f_captcha.onkeyup = function(e) |
594 f_captcha.onkeyup = function(e) |
595 { |
595 { |
596 if ( !e ) |
596 if ( !e ) |
597 e = window.event; |
597 e = window.event; |
598 if ( !e.keyCode ) |
598 if ( !e.keyCode ) |
599 return true; |
599 return true; |
600 if ( e.keyCode == 13 ) |
600 if ( e.keyCode == 13 ) |
601 { |
601 { |
602 ajaxLoginSubmitForm(); |
602 ajaxLoginSubmitForm(); |
603 } |
603 } |
604 } |
604 } |
605 td3_2.appendChild(f_captcha); |
605 td3_2.appendChild(f_captcha); |
606 tr3.appendChild(td3_2); |
606 tr3.appendChild(td3_2); |
607 table.appendChild(tr3); |
607 table.appendChild(tr3); |
608 } |
608 } |
609 |
609 |
610 // ok, this is a compatibility hack |
610 // ok, this is a compatibility hack |
611 data.locked_out = { locked_out: data.lockout.active }; |
611 data.locked_out = { locked_out: data.lockout.active }; |
612 |
612 |
613 // hook for the login form |
613 // hook for the login form |
614 eval(setHook('login_build_form')); |
614 eval(setHook('login_build_form')); |
615 |
615 |
616 delete(data.locked_out); |
616 delete(data.locked_out); |
617 |
617 |
618 // Done building the main part of the form |
618 // Done building the main part of the form |
619 form.appendChild(table); |
619 form.appendChild(table); |
620 |
620 |
621 // Checkbox container |
621 // Checkbox container |
622 var boxen = document.createElement('div'); |
622 var boxen = document.createElement('div'); |
623 boxen.style.textAlign = 'center'; |
623 boxen.style.textAlign = 'center'; |
624 boxen.style.padding = '7px 0'; |
624 boxen.style.padding = '7px 0'; |
625 |
625 |
626 // Field: remember login |
626 // Field: remember login |
627 if ( logindata.user_level <= USER_LEVEL_MEMBER ) |
627 if ( logindata.user_level <= USER_LEVEL_MEMBER ) |
628 { |
628 { |
629 var lbl_remember = document.createElement('label'); |
629 var lbl_remember = document.createElement('label'); |
630 lbl_remember.style.fontSize = 'smaller'; |
630 lbl_remember.style.fontSize = 'smaller'; |
631 lbl_remember.style.textAlign = 'center'; |
631 lbl_remember.style.textAlign = 'center'; |
632 |
632 |
633 // figure out what text to put in the "remember me" checkbox |
633 // figure out what text to put in the "remember me" checkbox |
634 // infinite session length? |
634 // infinite session length? |
635 if ( data.extended_time == 0 ) |
635 if ( data.extended_time == 0 ) |
636 { |
636 { |
637 // yes, infinite |
637 // yes, infinite |
638 var txt_remember = $lang.get('user_login_ajax_check_remember_infinite'); |
638 var txt_remember = $lang.get('user_login_ajax_check_remember_infinite'); |
639 } |
639 } |
640 else |
640 else |
641 { |
641 { |
642 if ( data.extended_time % 7 == 0 ) |
642 if ( data.extended_time % 7 == 0 ) |
643 { |
643 { |
644 // number of days is a multiple of 7 |
644 // number of days is a multiple of 7 |
645 // use weeks as our unit |
645 // use weeks as our unit |
646 var sess_time = data.extended_time / 7; |
646 var sess_time = data.extended_time / 7; |
647 var unit = 'week'; |
647 var unit = 'week'; |
648 } |
648 } |
649 else |
649 else |
650 { |
650 { |
651 // use days as our unit |
651 // use days as our unit |
652 var sess_time = data.extended_time; |
652 var sess_time = data.extended_time; |
653 var unit = 'day'; |
653 var unit = 'day'; |
654 } |
654 } |
655 // more than one week or day? |
655 // more than one week or day? |
656 if ( sess_time != 1 ) |
656 if ( sess_time != 1 ) |
657 unit += 's'; |
657 unit += 's'; |
658 |
658 |
659 // assemble the string |
659 // assemble the string |
660 var txt_remember = $lang.get('user_login_ajax_check_remember', { |
660 var txt_remember = $lang.get('user_login_ajax_check_remember', { |
661 session_length: sess_time, |
661 session_length: sess_time, |
662 length_units: $lang.get('etc_unit_' + unit) |
662 length_units: $lang.get('etc_unit_' + unit) |
663 }); |
663 }); |
664 } |
664 } |
665 var check_remember = document.createElement('input'); |
665 var check_remember = document.createElement('input'); |
666 check_remember.type = 'checkbox'; |
666 check_remember.type = 'checkbox'; |
667 // this onclick attribute changes the cookie whenever the checkbox or label is clicked |
667 // this onclick attribute changes the cookie whenever the checkbox or label is clicked |
668 check_remember.setAttribute('onclick', 'var ck = ( this.checked ) ? "enable" : "disable"; createCookie("login_remember", ck, 3650);'); |
668 check_remember.setAttribute('onclick', 'var ck = ( this.checked ) ? "enable" : "disable"; createCookie("login_remember", ck, 3650);'); |
669 if ( readCookie('login_remember') != 'disable' ) |
669 if ( readCookie('login_remember') != 'disable' ) |
670 check_remember.setAttribute('checked', 'checked'); |
670 check_remember.setAttribute('checked', 'checked'); |
671 check_remember.id = 'ajax_login_field_remember'; |
671 check_remember.id = 'ajax_login_field_remember'; |
672 lbl_remember.appendChild(check_remember); |
672 lbl_remember.appendChild(check_remember); |
673 lbl_remember.innerHTML += ' ' + txt_remember; |
673 lbl_remember.innerHTML += ' ' + txt_remember; |
674 |
674 |
675 boxen.appendChild(lbl_remember); |
675 boxen.appendChild(lbl_remember); |
676 } |
676 } |
677 |
677 |
678 var bullet = document.createElement('span'); |
678 var bullet = document.createElement('span'); |
679 bullet.innerHTML = ' '; |
679 bullet.innerHTML = ' '; |
680 bullet.style.fontSize = '12pt'; |
680 bullet.style.fontSize = '12pt'; |
681 bullet.style.borderRight = '1px solid #aaa'; |
681 bullet.style.borderRight = '1px solid #aaa'; |
682 bullet.style.margin = '0 6px 0 4px'; |
682 bullet.style.margin = '0 6px 0 4px'; |
683 |
683 |
684 // Field: enable Diffie Hellman |
684 // Field: enable Diffie Hellman |
685 if ( ajax_login_prevent_dh ) |
685 if ( ajax_login_prevent_dh ) |
686 { |
686 { |
687 if ( logindata.user_level <= USER_LEVEL_MEMBER ) |
687 if ( logindata.user_level <= USER_LEVEL_MEMBER ) |
688 // only show this if both checkboxes are visible |
688 // only show this if both checkboxes are visible |
689 boxen.appendChild(bullet); |
689 boxen.appendChild(bullet); |
690 |
690 |
691 var lbl_dh = document.createElement('span'); |
691 var lbl_dh = document.createElement('span'); |
692 lbl_dh.style.fontSize = 'smaller'; |
692 lbl_dh.style.fontSize = 'smaller'; |
693 lbl_dh.style.textAlign = 'center'; |
693 lbl_dh.style.textAlign = 'center'; |
694 lbl_dh.innerHTML = $lang.get('user_login_ajax_check_dh_ie'); |
694 lbl_dh.innerHTML = $lang.get('user_login_ajax_check_dh_ie'); |
695 boxen.appendChild(lbl_dh); |
695 boxen.appendChild(lbl_dh); |
696 } |
696 } |
697 else if ( !data.crypto.dh_enable ) |
697 else if ( !data.crypto.dh_enable ) |
698 { |
698 { |
699 // create hidden control - server requested that DiffieHellman be disabled (usually means not supported) |
699 // create hidden control - server requested that DiffieHellman be disabled (usually means not supported) |
700 var check_dh = document.createElement('input'); |
700 var check_dh = document.createElement('input'); |
701 check_dh.type = 'hidden'; |
701 check_dh.type = 'hidden'; |
702 check_dh.id = 'ajax_login_field_dh'; |
702 check_dh.id = 'ajax_login_field_dh'; |
703 boxen.appendChild(check_dh); |
703 boxen.appendChild(check_dh); |
704 } |
704 } |
705 else |
705 else |
706 { |
706 { |
707 if ( logindata.user_level <= USER_LEVEL_MEMBER ) |
707 if ( logindata.user_level <= USER_LEVEL_MEMBER ) |
708 // only show this if both checkboxes are visible |
708 // only show this if both checkboxes are visible |
709 boxen.appendChild(bullet); |
709 boxen.appendChild(bullet); |
710 |
710 |
711 var lbl_dh = document.createElement('label'); |
711 var lbl_dh = document.createElement('label'); |
712 lbl_dh.style.fontSize = 'smaller'; |
712 lbl_dh.style.fontSize = 'smaller'; |
713 lbl_dh.style.textAlign = 'center'; |
713 lbl_dh.style.textAlign = 'center'; |
714 var check_dh = document.createElement('input'); |
714 var check_dh = document.createElement('input'); |
715 check_dh.type = 'checkbox'; |
715 check_dh.type = 'checkbox'; |
716 // this onclick attribute changes the cookie whenever the checkbox or label is clicked |
716 // this onclick attribute changes the cookie whenever the checkbox or label is clicked |
717 check_dh.setAttribute('onclick', 'var ck = ( this.checked ) ? "enable" : "disable"; createCookie("diffiehellman_login", ck, 3650);'); |
717 check_dh.setAttribute('onclick', 'var ck = ( this.checked ) ? "enable" : "disable"; createCookie("diffiehellman_login", ck, 3650);'); |
718 if ( readCookie('diffiehellman_login') != 'disable' ) |
718 if ( readCookie('diffiehellman_login') != 'disable' ) |
719 check_dh.setAttribute('checked', 'checked'); |
719 check_dh.setAttribute('checked', 'checked'); |
720 check_dh.id = 'ajax_login_field_dh'; |
720 check_dh.id = 'ajax_login_field_dh'; |
721 lbl_dh.appendChild(check_dh); |
721 lbl_dh.appendChild(check_dh); |
722 lbl_dh.innerHTML += ' ' + $lang.get('user_login_ajax_check_dh'); |
722 lbl_dh.innerHTML += ' ' + $lang.get('user_login_ajax_check_dh'); |
723 boxen.appendChild(lbl_dh); |
723 boxen.appendChild(lbl_dh); |
724 } |
724 } |
725 |
725 |
726 form.appendChild(boxen); |
726 form.appendChild(boxen); |
727 |
727 |
728 if ( IE ) |
728 if ( IE ) |
729 { |
729 { |
730 div.innerHTML += form.outerHTML; |
730 div.innerHTML += form.outerHTML; |
731 } |
731 } |
732 else |
732 else |
733 { |
733 { |
734 div.appendChild(form); |
734 div.appendChild(form); |
735 } |
735 } |
736 |
736 |
737 // Diagnostic / help links |
737 // Diagnostic / help links |
738 // (only displayed in login, not in re-auth) |
738 // (only displayed in login, not in re-auth) |
739 if ( logindata.user_level == USER_LEVEL_MEMBER ) |
739 if ( logindata.user_level == USER_LEVEL_MEMBER ) |
740 { |
740 { |
741 var links = document.createElement('small'); |
741 var links = document.createElement('small'); |
742 links.style.display = 'block'; |
742 links.style.display = 'block'; |
743 links.style.textAlign = 'center'; |
743 links.style.textAlign = 'center'; |
744 links.innerHTML = ''; |
744 links.innerHTML = ''; |
745 if ( !show_captcha ) |
745 if ( !show_captcha ) |
746 links.innerHTML += $lang.get('user_login_ajax_link_fullform', { link_full_form: makeUrlNS('Special', 'Login/' + title) }) + ' • '; |
746 links.innerHTML += $lang.get('user_login_ajax_link_fullform', { link_full_form: makeUrlNS('Special', 'Login/' + title) }) + ' • '; |
747 // Always shown |
747 // Always shown |
748 links.innerHTML += $lang.get('user_login_ajax_link_forgotpass', { forgotpass_link: makeUrlNS('Special', 'PasswordReset') }) + ' • '; |
748 links.innerHTML += $lang.get('user_login_ajax_link_forgotpass', { forgotpass_link: makeUrlNS('Special', 'PasswordReset') }) + ' • '; |
749 if ( !show_captcha ) |
749 if ( !show_captcha ) |
750 links.innerHTML += $lang.get('user_login_ajax_createaccount_blurb', { reg_link: makeUrlNS('Special', 'Register') }); |
750 links.innerHTML += $lang.get('user_login_ajax_createaccount_blurb', { reg_link: makeUrlNS('Special', 'Register') }); |
751 div.appendChild(links); |
751 div.appendChild(links); |
752 } |
752 } |
753 |
753 |
754 // Insert the entire form into the login window |
754 // Insert the entire form into the login window |
755 logindata.mb_inner.innerHTML = ''; |
755 logindata.mb_inner.innerHTML = ''; |
756 logindata.mb_inner.appendChild(div); |
756 logindata.mb_inner.appendChild(div); |
757 |
757 |
758 // Post operations: field focus |
758 // Post operations: field focus |
759 setTimeout( |
759 setTimeout( |
760 function() |
760 function() |
761 { |
761 { |
762 if ( logindata.loggedin_username ) |
762 if ( logindata.loggedin_username ) |
763 document.getElementById('ajax_login_field_password').focus(); |
763 document.getElementById('ajax_login_field_password').focus(); |
764 else |
764 else |
765 document.getElementById('ajax_login_field_username').focus(); |
765 document.getElementById('ajax_login_field_username').focus(); |
766 }, 750); |
766 }, 750); |
767 |
767 |
768 // Post operations: show captcha window |
768 // Post operations: show captcha window |
769 if ( show_captcha ) |
769 if ( show_captcha ) |
770 { |
770 { |
771 ajaxShowCaptcha(show_captcha); |
771 ajaxShowCaptcha(show_captcha); |
772 } |
772 } |
773 |
773 |
774 // Post operations: stash encryption keys and All That Jazz(TM) |
774 // Post operations: stash encryption keys and All That Jazz(TM) |
775 logindata.key_aes = data.crypto.aes_key; |
775 logindata.key_aes = data.crypto.aes_key; |
776 logindata.key_dh = data.crypto.dh_public_key; |
776 logindata.key_dh = data.crypto.dh_public_key; |
777 logindata.captcha_hash = show_captcha; |
777 logindata.captcha_hash = show_captcha; |
778 logindata.loggedin_username = data.username; |
778 logindata.loggedin_username = data.username; |
779 |
779 |
780 // If policy is lockout, also disable controls |
780 // If policy is lockout, also disable controls |
781 if ( data.lockout.policy == 'lockout' && data.lockout.active ) |
781 if ( data.lockout.policy == 'lockout' && data.lockout.active ) |
782 { |
782 { |
783 f_username.setAttribute('disabled', 'disabled'); |
783 f_username.setAttribute('disabled', 'disabled'); |
784 f_password.setAttribute('disabled', 'disabled'); |
784 f_password.setAttribute('disabled', 'disabled'); |
785 } |
785 } |
786 } |
786 } |
787 |
787 |
788 window.ajaxLoginSubmitForm = function(real, username, password, captcha, remember) |
788 window.ajaxLoginSubmitForm = function(real, username, password, captcha, remember) |
789 { |
789 { |
790 // Perform AES test to make sure it's all working |
790 // Perform AES test to make sure it's all working |
791 if ( !aes_self_test() ) |
791 if ( !aes_self_test() ) |
792 { |
792 { |
793 alert('BUG: AES self-test failed'); |
793 alert('BUG: AES self-test failed'); |
794 login_cache.mb_object.destroy(); |
794 login_cache.mb_object.destroy(); |
795 return false; |
795 return false; |
796 } |
796 } |
797 // Hide the error message and captcha |
797 // Hide the error message and captcha |
798 if ( document.getElementById('ajax_login_error_box') ) |
798 if ( document.getElementById('ajax_login_error_box') ) |
799 { |
799 { |
800 document.getElementById('ajax_login_error_box').parentNode.removeChild(document.getElementById('ajax_login_error_box')); |
800 document.getElementById('ajax_login_error_box').parentNode.removeChild(document.getElementById('ajax_login_error_box')); |
801 } |
801 } |
802 if ( document.getElementById('autoCaptcha') ) |
802 if ( document.getElementById('autoCaptcha') ) |
803 { |
803 { |
804 var to = fly_out_top(document.getElementById('autoCaptcha'), false, true); |
804 var to = fly_out_top(document.getElementById('autoCaptcha'), false, true); |
805 setTimeout(function() { |
805 setTimeout(function() { |
806 var d = document.getElementById('autoCaptcha'); |
806 var d = document.getElementById('autoCaptcha'); |
807 d.parentNode.removeChild(d); |
807 d.parentNode.removeChild(d); |
808 }, to); |
808 }, to); |
809 } |
809 } |
810 // "Remember session" switch |
810 // "Remember session" switch |
811 if ( typeof(remember) == 'boolean' ) |
811 if ( typeof(remember) == 'boolean' ) |
812 { |
812 { |
813 var remember_session = remember; |
813 var remember_session = remember; |
814 } |
814 } |
815 else |
815 else |
816 { |
816 { |
817 if ( document.getElementById('ajax_login_field_remember') ) |
817 if ( document.getElementById('ajax_login_field_remember') ) |
818 { |
818 { |
819 var remember_session = ( document.getElementById('ajax_login_field_remember').checked ) ? true : false; |
819 var remember_session = ( document.getElementById('ajax_login_field_remember').checked ) ? true : false; |
820 } |
820 } |
821 else |
821 else |
822 { |
822 { |
823 var remember_session = false; |
823 var remember_session = false; |
824 } |
824 } |
825 } |
825 } |
826 // Encryption: preprocessor |
826 // Encryption: preprocessor |
827 if ( real ) |
827 if ( real ) |
828 { |
828 { |
829 var do_dh = true; |
829 var do_dh = true; |
830 } |
830 } |
831 else if ( document.getElementById('ajax_login_field_dh') ) |
831 else if ( document.getElementById('ajax_login_field_dh') ) |
832 { |
832 { |
833 var do_dh = document.getElementById('ajax_login_field_dh').checked; |
833 var do_dh = document.getElementById('ajax_login_field_dh').checked; |
834 } |
834 } |
835 else |
835 else |
836 { |
836 { |
837 if ( ajax_login_prevent_dh ) |
837 if ( ajax_login_prevent_dh ) |
838 { |
838 { |
839 // IE/MobileSafari doesn't have this control, continue silently IF the rest |
839 // IE/MobileSafari doesn't have this control, continue silently IF the rest |
840 // of the login form is there |
840 // of the login form is there |
841 if ( !document.getElementById('ajax_login_field_username') ) |
841 if ( !document.getElementById('ajax_login_field_username') ) |
842 { |
842 { |
843 return false; |
843 return false; |
844 } |
844 } |
845 } |
845 } |
846 else |
846 else |
847 { |
847 { |
848 // The user probably clicked ok when the form wasn't in there. |
848 // The user probably clicked ok when the form wasn't in there. |
849 return false; |
849 return false; |
850 } |
850 } |
851 } |
851 } |
852 |
852 |
853 if ( typeof(username) != 'string' ) |
853 if ( typeof(username) != 'string' ) |
854 { |
854 { |
855 var username = document.getElementById('ajax_login_field_username').value; |
855 var username = document.getElementById('ajax_login_field_username').value; |
856 } |
856 } |
857 if ( typeof(password) != 'string' ) |
857 if ( typeof(password) != 'string' ) |
858 { |
858 { |
859 var password = document.getElementById('ajax_login_field_password').value; |
859 var password = document.getElementById('ajax_login_field_password').value; |
860 } |
860 } |
861 if ( !captcha && document.getElementById('ajax_login_field_captcha') ) |
861 if ( !captcha && document.getElementById('ajax_login_field_captcha') ) |
862 { |
862 { |
863 var captcha = document.getElementById('ajax_login_field_captcha').value; |
863 var captcha = document.getElementById('ajax_login_field_captcha').value; |
864 } |
864 } |
865 |
865 |
866 // Only run early submit hook once |
866 // Only run early submit hook once |
867 if ( !window.logindata.early_submit_run ) |
867 if ( !window.logindata.early_submit_run ) |
868 eval(setHook('login_submit_early')); |
868 eval(setHook('login_submit_early')); |
869 |
869 |
870 window.logindata.early_submit_run = true; |
870 window.logindata.early_submit_run = true; |
871 |
871 |
872 try |
872 try |
873 { |
873 { |
874 |
874 |
875 if ( do_dh ) |
875 if ( do_dh ) |
876 { |
876 { |
877 ajaxLoginSetStatus(AJAX_STATUS_GENERATING_KEY); |
877 ajaxLoginSetStatus(AJAX_STATUS_GENERATING_KEY); |
878 if ( !real ) |
878 if ( !real ) |
879 { |
879 { |
880 // Wait while the browser updates the login window |
880 // Wait while the browser updates the login window |
881 setTimeout(function() |
881 setTimeout(function() |
882 { |
882 { |
883 ajaxLoginSubmitForm(true, username, password, captcha, remember_session); |
883 ajaxLoginSubmitForm(true, username, password, captcha, remember_session); |
884 }, 20); |
884 }, 20); |
885 return true; |
885 return true; |
886 } |
886 } |
887 var dh_start = (new Date()).getTime(); |
887 var dh_start = (new Date()).getTime(); |
888 // Perform Diffie Hellman stuff |
888 // Perform Diffie Hellman stuff |
889 var dh_priv = dh_gen_private(); |
889 var dh_priv = dh_gen_private(); |
890 var dh_pub = dh_gen_public(dh_priv); |
890 var dh_pub = dh_gen_public(dh_priv); |
891 var secret = dh_gen_shared_secret(dh_priv, logindata.key_dh); |
891 var secret = dh_gen_shared_secret(dh_priv, logindata.key_dh); |
892 // secret_hash is used to verify that the server guesses the correct secret |
892 // secret_hash is used to verify that the server guesses the correct secret |
893 var secret_hash = hex_sha1(secret); |
893 var secret_hash = hex_sha1(secret); |
894 // crypt_key is the actual AES key |
894 // crypt_key is the actual AES key |
895 var crypt_key = (hex_sha256(secret)).substr(0, (keySizeInBits / 4)); |
895 var crypt_key = (hex_sha256(secret)).substr(0, (keySizeInBits / 4)); |
896 var dh_time = (new Date()).getTime() - dh_start; |
896 var dh_time = (new Date()).getTime() - dh_start; |
897 console.debug("DH: complete, time = %dms", dh_time); |
897 console.debug("DH: complete, time = %dms", dh_time); |
898 } |
898 } |
899 else |
899 else |
900 { |
900 { |
901 var crypt_key = logindata.key_aes; |
901 var crypt_key = logindata.key_aes; |
902 } |
902 } |
903 |
903 |
904 ajaxLoginSetStatus(AJAX_STATUS_LOGGING_IN); |
904 ajaxLoginSetStatus(AJAX_STATUS_LOGGING_IN); |
905 |
905 |
906 // Encrypt the password and username |
906 // Encrypt the password and username |
907 var userinfo = { |
907 var userinfo = { |
908 username: username, |
908 username: username, |
909 password: password |
909 password: password |
910 }; |
910 }; |
911 |
911 |
912 eval(setHook('login_build_userinfo')); |
912 eval(setHook('login_build_userinfo')); |
913 |
913 |
914 userinfo = toJSONString(userinfo); |
914 userinfo = toJSONString(userinfo); |
915 var crypt_key_ba = hexToByteArray(crypt_key); |
915 var crypt_key_ba = hexToByteArray(crypt_key); |
916 userinfo = stringToByteArray(userinfo); |
916 userinfo = stringToByteArray(userinfo); |
917 |
917 |
918 userinfo = rijndaelEncrypt(userinfo, crypt_key_ba, 'ECB'); |
918 userinfo = rijndaelEncrypt(userinfo, crypt_key_ba, 'ECB'); |
919 userinfo = byteArrayToHex(userinfo); |
919 userinfo = byteArrayToHex(userinfo); |
920 // Encrypted username and password (serialized with JSON) are now in the userinfo string |
920 // Encrypted username and password (serialized with JSON) are now in the userinfo string |
921 |
921 |
922 // Collect other needed information |
922 // Collect other needed information |
923 if ( logindata.captcha_hash ) |
923 if ( logindata.captcha_hash ) |
924 { |
924 { |
925 var captcha_hash = logindata.captcha_hash; |
925 var captcha_hash = logindata.captcha_hash; |
926 var captcha_code = captcha; |
926 var captcha_code = captcha; |
927 } |
927 } |
928 else |
928 else |
929 { |
929 { |
930 var captcha_hash = false; |
930 var captcha_hash = false; |
931 var captcha_code = false; |
931 var captcha_code = false; |
932 } |
932 } |
933 |
933 |
934 // Ship it across the 'net |
934 // Ship it across the 'net |
935 if ( do_dh ) |
935 if ( do_dh ) |
936 { |
936 { |
937 var json_packet = { |
937 var json_packet = { |
938 mode: 'login_dh', |
938 mode: 'login_dh', |
939 userinfo: userinfo, |
939 userinfo: userinfo, |
940 captcha_code: captcha_code, |
940 captcha_code: captcha_code, |
941 captcha_hash: captcha_hash, |
941 captcha_hash: captcha_hash, |
942 dh_public_key: logindata.key_dh, |
942 dh_public_key: logindata.key_dh, |
943 dh_client_key: dh_pub, |
943 dh_client_key: dh_pub, |
944 dh_secret_hash: secret_hash, |
944 dh_secret_hash: secret_hash, |
945 level: logindata.user_level, |
945 level: logindata.user_level, |
946 remember: remember_session |
946 remember: remember_session |
947 } |
947 } |
948 } |
948 } |
949 else |
949 else |
950 { |
950 { |
951 var json_packet = { |
951 var json_packet = { |
952 mode: 'login_aes', |
952 mode: 'login_aes', |
953 userinfo: userinfo, |
953 userinfo: userinfo, |
954 captcha_code: captcha_code, |
954 captcha_code: captcha_code, |
955 captcha_hash: captcha_hash, |
955 captcha_hash: captcha_hash, |
956 key_aes: hex_md5(crypt_key), |
956 key_aes: hex_md5(crypt_key), |
957 level: logindata.user_level, |
957 level: logindata.user_level, |
958 remember: remember_session |
958 remember: remember_session |
959 } |
959 } |
960 } |
960 } |
961 } |
961 } |
962 catch(e) |
962 catch(e) |
963 { |
963 { |
964 ajaxLoginSetStatus(AJAX_STATUS_ERROR); |
964 ajaxLoginSetStatus(AJAX_STATUS_ERROR); |
965 console.error('Exception caught in login process; backtrace follows'); |
965 console.error('Exception caught in login process; backtrace follows'); |
966 console.debug(e); |
966 console.debug(e); |
967 return false; |
967 return false; |
968 } |
968 } |
969 // reset this... |
969 // reset this... |
970 window.logindata.early_submit_run = false; |
970 window.logindata.early_submit_run = false; |
971 ajaxLoginPerformRequest(json_packet); |
971 ajaxLoginPerformRequest(json_packet); |
972 } |
972 } |
973 |
973 |
974 window.ajaxLoginShowFriendlyError = function(response) |
974 window.ajaxLoginShowFriendlyError = function(response) |
975 { |
975 { |
976 var text = ajaxLoginGetErrorText(response); |
976 var text = ajaxLoginGetErrorText(response); |
977 if ( text == false ) |
977 if ( text == false ) |
978 return true; |
978 return true; |
979 |
979 |
980 if ( document.getElementById('ajax_login_error_box') ) |
980 if ( document.getElementById('ajax_login_error_box') ) |
981 { |
981 { |
982 // console.info('Reusing existing error-box'); |
982 // console.info('Reusing existing error-box'); |
983 document.getElementById('ajax_login_error_box').innerHTML = text; |
983 document.getElementById('ajax_login_error_box').innerHTML = text; |
984 return true; |
984 return true; |
985 } |
985 } |
986 |
986 |
987 // console.info('Drawing new error-box'); |
987 // console.info('Drawing new error-box'); |
988 |
988 |
989 // calculate position for the top of the box |
989 // calculate position for the top of the box |
990 var mb_bottom = $dynano('messageBoxButtons').Top() + $dynano('messageBoxButtons').Height(); |
990 var mb_bottom = $dynano('messageBoxButtons').Top() + $dynano('messageBoxButtons').Height(); |
991 // if the box isn't done flying in yet, just estimate |
991 // if the box isn't done flying in yet, just estimate |
992 if ( mb_bottom < ( getHeight() / 2 ) ) |
992 if ( mb_bottom < ( getHeight() / 2 ) ) |
993 { |
993 { |
994 mb_bottom = ( getHeight() / 2 ) + 120; |
994 mb_bottom = ( getHeight() / 2 ) + 120; |
995 } |
995 } |
996 var win_bottom = getHeight() + getScrollOffset(); |
996 var win_bottom = getHeight() + getScrollOffset(); |
997 var top = mb_bottom + ( ( win_bottom - mb_bottom ) / 2 ) - 32; |
997 var top = mb_bottom + ( ( win_bottom - mb_bottom ) / 2 ) - 32; |
998 // left position = 0.2 * window_width, seeing as the box is 60% width this works hackishly but nice and quick |
998 // left position = 0.2 * window_width, seeing as the box is 60% width this works hackishly but nice and quick |
999 var left = getWidth() * 0.2; |
999 var left = getWidth() * 0.2; |
1000 |
1000 |
1001 // create the div |
1001 // create the div |
1002 var errbox = document.createElement('div'); |
1002 var errbox = document.createElement('div'); |
1003 errbox.className = 'error-box-mini'; |
1003 errbox.className = 'error-box-mini'; |
1004 errbox.style.position = 'absolute'; |
1004 errbox.style.position = 'absolute'; |
1005 errbox.style.width = '60%'; |
1005 errbox.style.width = '60%'; |
1006 errbox.style.top = top + 'px'; |
1006 errbox.style.top = top + 'px'; |
1007 errbox.style.left = left + 'px'; |
1007 errbox.style.left = left + 'px'; |
1008 errbox.style.zIndex = getHighestZ(); |
1008 errbox.style.zIndex = getHighestZ(); |
1009 errbox.innerHTML = text; |
1009 errbox.innerHTML = text; |
1010 errbox.id = 'ajax_login_error_box'; |
1010 errbox.id = 'ajax_login_error_box'; |
1011 |
1011 |
1012 var body = document.getElementsByTagName('body')[0]; |
1012 var body = document.getElementsByTagName('body')[0]; |
1013 body.appendChild(errbox); |
1013 body.appendChild(errbox); |
1014 } |
1014 } |
1015 |
1015 |
1016 window.ajaxLoginGetErrorText = function(response) |
1016 window.ajaxLoginGetErrorText = function(response) |
1017 { |
1017 { |
1018 if ( response.lockout ) |
1018 if ( response.lockout ) |
1019 { |
1019 { |
1020 // set this pluralality thing |
1020 // set this pluralality thing |
1021 response.lockout.plural = response.lockout.time_rem == 1 ? '' : $lang.get('meta_plural'); |
1021 response.lockout.plural = response.lockout.time_rem == 1 ? '' : $lang.get('meta_plural'); |
1022 } |
1022 } |
1023 |
1023 |
1024 if ( response.mode == 'initial' ) |
1024 if ( response.mode == 'initial' ) |
1025 { |
1025 { |
1026 // Just showing the box for the first time. If there's an error now, it's based on a preexisting lockout. |
1026 // Just showing the box for the first time. If there's an error now, it's based on a preexisting lockout. |
1027 if ( response.lockout.active ) |
1027 if ( response.lockout.active ) |
1028 { |
1028 { |
1029 return $lang.get('user_err_locked_out_initial_' + response.lockout.policy, response.lockout); |
1029 return $lang.get('user_err_locked_out_initial_' + response.lockout.policy, response.lockout); |
1030 } |
1030 } |
1031 return false; |
1031 return false; |
1032 } |
1032 } |
1033 else |
1033 else |
1034 { |
1034 { |
1035 // An attempt was made. |
1035 // An attempt was made. |
1036 switch(response.mode) |
1036 switch(response.mode) |
1037 { |
1037 { |
1038 case 'login_failure': |
1038 case 'login_failure': |
1039 // Generic login user error. |
1039 // Generic login user error. |
1040 var error = '', x; |
1040 var error = '', x; |
1041 if ( (x = $lang.get(response.error)) != response.error || ! (/^[a-z0-9_]+/).test(response.error) ) |
1041 if ( (x = $lang.get(response.error)) != response.error || ! (/^[a-z0-9_]+/).test(response.error) ) |
1042 error = x; |
1042 error = x; |
1043 else |
1043 else |
1044 error = $lang.get('user_err_' + response.error); |
1044 error = $lang.get('user_err_' + response.error); |
1045 if ( response.lockout.active && response.lockout.policy == 'lockout' ) |
1045 if ( response.lockout.active && response.lockout.policy == 'lockout' ) |
1046 { |
1046 { |
1047 // Lockout enforcement was just activated. |
1047 // Lockout enforcement was just activated. |
1048 return $lang.get('user_err_locked_out_initial_' + response.lockout.policy, response.lockout); |
1048 return $lang.get('user_err_locked_out_initial_' + response.lockout.policy, response.lockout); |
1049 } |
1049 } |
1050 else if ( response.lockout.policy != 'disable' && !response.lockout.active && response.lockout.fails > 0 ) |
1050 else if ( response.lockout.policy != 'disable' && !response.lockout.active && response.lockout.fails > 0 ) |
1051 { |
1051 { |
1052 // Lockout is in a warning state. |
1052 // Lockout is in a warning state. |
1053 error += ' ' + $lang.get('user_err_invalid_credentials_' + response.lockout.policy, response.lockout); |
1053 error += ' ' + $lang.get('user_err_invalid_credentials_' + response.lockout.policy, response.lockout); |
1054 } |
1054 } |
1055 return error; |
1055 return error; |
1056 break; |
1056 break; |
1057 case 'api_error': |
1057 case 'api_error': |
1058 // Error in the API. |
1058 // Error in the API. |
1059 return $lang.get('user_err_login_generic_title') + ': ' + $lang.get('user_' + response.error.toLowerCase()); |
1059 return $lang.get('user_err_login_generic_title') + ': ' + $lang.get('user_' + response.error.toLowerCase()); |
1060 break; |
1060 break; |
1061 } |
1061 } |
1062 } |
1062 } |
1063 |
1063 |
1064 return typeof(response.error) == 'string' ? response.error : false; |
1064 return typeof(response.error) == 'string' ? response.error : false; |
1065 } |
1065 } |
1066 |
1066 |
1067 window.ajaxShowCaptcha = function(code) |
1067 window.ajaxShowCaptcha = function(code) |
1068 { |
1068 { |
1069 var mydiv = document.createElement('div'); |
1069 var mydiv = document.createElement('div'); |
1070 mydiv.style.backgroundColor = '#FFFFFF'; |
1070 mydiv.style.backgroundColor = '#FFFFFF'; |
1071 mydiv.style.padding = '10px'; |
1071 mydiv.style.padding = '10px'; |
1072 mydiv.style.position = 'absolute'; |
1072 mydiv.style.position = 'absolute'; |
1073 mydiv.style.top = '0px'; |
1073 mydiv.style.top = '0px'; |
1074 mydiv.id = 'autoCaptcha'; |
1074 mydiv.id = 'autoCaptcha'; |
1075 mydiv.style.zIndex = String( getHighestZ() + 1 ); |
1075 mydiv.style.zIndex = String( getHighestZ() + 1 ); |
1076 var img = document.createElement('img'); |
1076 var img = document.createElement('img'); |
1077 img.onload = function() |
1077 img.onload = function() |
1078 { |
1078 { |
1079 if ( this.loaded ) |
1079 if ( this.loaded ) |
1080 return true; |
1080 return true; |
1081 var mydiv = document.getElementById('autoCaptcha'); |
1081 var mydiv = document.getElementById('autoCaptcha'); |
1082 var width = getWidth(); |
1082 var width = getWidth(); |
1083 var divw = $dynano(mydiv).Width(); |
1083 var divw = $dynano(mydiv).Width(); |
1084 var left = ( width / 2 ) - ( divw / 2 ); |
1084 var left = ( width / 2 ) - ( divw / 2 ); |
1085 mydiv.style.left = left + 'px'; |
1085 mydiv.style.left = left + 'px'; |
1086 fly_in_top(mydiv, false, true); |
1086 fly_in_top(mydiv, false, true); |
1087 this.loaded = true; |
1087 this.loaded = true; |
1088 }; |
1088 }; |
1089 img.src = makeUrlNS('Special', 'Captcha/' + code); |
1089 img.src = makeUrlNS('Special', 'Captcha/' + code); |
1090 img.onclick = function() { this.src = this.src + '/a'; }; |
1090 img.onclick = function() { this.src = this.src + '/a'; }; |
1091 img.style.cursor = 'pointer'; |
1091 img.style.cursor = 'pointer'; |
1092 mydiv.appendChild(img); |
1092 mydiv.appendChild(img); |
1093 domObjChangeOpac(0, mydiv); |
1093 domObjChangeOpac(0, mydiv); |
1094 var body = document.getElementsByTagName('body')[0]; |
1094 var body = document.getElementsByTagName('body')[0]; |
1095 body.appendChild(mydiv); |
1095 body.appendChild(mydiv); |
1096 } |
1096 } |
1097 |
1097 |
1098 window.ajaxInitLogout = function() |
1098 window.ajaxInitLogout = function() |
1099 { |
1099 { |
1100 load_component(['messagebox', 'l10n', 'flyin', 'fadefilter', 'jquery', 'jquery-ui']); |
1100 load_component(['messagebox', 'l10n', 'flyin', 'fadefilter', 'jquery', 'jquery-ui']); |
1101 |
1101 |
1102 var title = $lang.get('user_logout_confirm_title'); |
1102 var title = $lang.get('user_logout_confirm_title'); |
1103 var message = ( auth_level > USER_LEVEL_MEMBER ) ? $lang.get('user_logout_confirm_body_nelev') : $lang.get('user_logout_confirm_body_normal'); |
1103 var message = ( auth_level > USER_LEVEL_MEMBER ) ? $lang.get('user_logout_confirm_body_nelev') : $lang.get('user_logout_confirm_body_normal'); |
1104 var buttons = []; |
1104 var buttons = []; |
1105 buttons.push({ |
1105 buttons.push({ |
1106 text: $lang.get('user_logout_confirm_btn_logout'), |
1106 text: $lang.get('user_logout_confirm_btn_logout'), |
1107 color: 'red', |
1107 color: 'red', |
1108 style: { |
1108 style: { |
1109 fontWeight: 'bold' |
1109 fontWeight: 'bold' |
1110 }, |
1110 }, |
1111 onclick: function() |
1111 onclick: function() |
1112 { |
1112 { |
1113 miniPromptDestroy(this); |
1113 miniPromptDestroy(this); |
1114 window.location = makeUrlNS('Special', 'Logout/' + csrf_token + '/' + window.title); |
1114 window.location = makeUrlNS('Special', 'Logout/' + csrf_token + '/' + window.title); |
1115 return false; |
1115 return false; |
1116 } |
1116 } |
1117 }); |
1117 }); |
1118 if ( auth_level > USER_LEVEL_MEMBER ) |
1118 if ( auth_level > USER_LEVEL_MEMBER ) |
1119 { |
1119 { |
1120 buttons.push({ |
1120 buttons.push({ |
1121 text: $lang.get('user_logout_confirm_btn_deauth'), |
1121 text: $lang.get('user_logout_confirm_btn_deauth'), |
1122 color: 'blue', |
1122 color: 'blue', |
1123 onclick: function() |
1123 onclick: function() |
1124 { |
1124 { |
1125 var mp = miniPromptGetParent(this); |
1125 var mp = miniPromptGetParent(this); |
1126 var whitey = whiteOutMiniPrompt(mp); |
1126 var whitey = whiteOutMiniPrompt(mp); |
1127 |
1127 |
1128 ajaxLoginPerformRequest({ |
1128 ajaxLoginPerformRequest({ |
1129 mode: 'logout', |
1129 mode: 'logout', |
1130 level: auth_level, |
1130 level: auth_level, |
1131 csrf_token: csrf_token |
1131 csrf_token: csrf_token |
1132 }, function(response) |
1132 }, function(response) |
1133 { |
1133 { |
1134 whiteOutReportSuccess(whitey); |
1134 whiteOutReportSuccess(whitey); |
1135 }); |
1135 }); |
1136 return false; |
1136 return false; |
1137 } |
1137 } |
1138 }); |
1138 }); |
1139 } |
1139 } |
1140 buttons.push({ |
1140 buttons.push({ |
1141 text: $lang.get('etc_cancel'), |
1141 text: $lang.get('etc_cancel'), |
1142 onclick: function() |
1142 onclick: function() |
1143 { |
1143 { |
1144 miniPromptDestroy(this); |
1144 miniPromptDestroy(this); |
1145 return false; |
1145 return false; |
1146 } |
1146 } |
1147 }); |
1147 }); |
1148 |
1148 |
1149 miniPromptMessage({ |
1149 miniPromptMessage({ |
1150 title: title, |
1150 title: title, |
1151 message: message, |
1151 message: message, |
1152 buttons: buttons |
1152 buttons: buttons |
1153 }); |
1153 }); |
1154 } |
1154 } |
1155 |
1155 |
1156 window.mb_logout = function() |
1156 window.mb_logout = function() |
1157 { |
1157 { |
1158 ajaxInitLogout(); |
1158 ajaxInitLogout(); |
1159 } |
1159 } |
1160 |
1160 |
1161 window.ajaxStartLogin = function() |
1161 window.ajaxStartLogin = function() |
1162 { |
1162 { |
1163 ajaxLogonToMember(); |
1163 ajaxLogonToMember(); |
1164 } |
1164 } |
1165 |
1165 |
1166 window.ajaxStartAdminLogin = function() |
1166 window.ajaxStartAdminLogin = function() |
1167 { |
1167 { |
1168 // IE <6 pseudo-compatibility |
1168 // IE <6 pseudo-compatibility |
1169 if ( KILL_SWITCH ) |
1169 if ( KILL_SWITCH ) |
1170 return true; |
1170 return true; |
1171 if ( auth_level < USER_LEVEL_ADMIN ) |
1171 if ( auth_level < USER_LEVEL_ADMIN ) |
1172 { |
1172 { |
1173 ajaxLoginInit(function(k) { |
1173 ajaxLoginInit(function(k) { |
1174 ENANO_SID = k; |
1174 ENANO_SID = k; |
1175 auth_level = USER_LEVEL_ADMIN; |
1175 auth_level = USER_LEVEL_ADMIN; |
1176 var loc = makeUrlNS('Special', 'Administration'); |
1176 var loc = makeUrlNS('Special', 'Administration'); |
1177 if ( (ENANO_SID + ' ').length > 1 ) |
1177 if ( (ENANO_SID + ' ').length > 1 ) |
1178 window.location = loc; |
1178 window.location = loc; |
1179 }, USER_LEVEL_ADMIN); |
1179 }, USER_LEVEL_ADMIN); |
1180 return false; |
1180 return false; |
1181 } |
1181 } |
1182 var loc = makeUrlNS('Special', 'Administration'); |
1182 var loc = makeUrlNS('Special', 'Administration'); |
1183 window.location = loc; |
1183 window.location = loc; |
1184 } |
1184 } |
1185 |
1185 |
1186 window.ajaxAdminPage = function() |
1186 window.ajaxAdminPage = function() |
1187 { |
1187 { |
1188 // IE <6 pseudo-compatibility |
1188 // IE <6 pseudo-compatibility |
1189 if ( KILL_SWITCH ) |
1189 if ( KILL_SWITCH ) |
1190 return true; |
1190 return true; |
1191 if ( auth_level < USER_LEVEL_ADMIN ) |
1191 if ( auth_level < USER_LEVEL_ADMIN ) |
1192 { |
1192 { |
1193 ajaxPromptAdminAuth(function(k) { |
1193 ajaxPromptAdminAuth(function(k) { |
1194 ENANO_SID = k; |
1194 ENANO_SID = k; |
1195 auth_level = USER_LEVEL_ADMIN; |
1195 auth_level = USER_LEVEL_ADMIN; |
1196 var loc = String(window.location + ''); |
1196 var loc = String(window.location + ''); |
1197 window.location = append_sid(loc); |
1197 window.location = append_sid(loc); |
1198 var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'PageManager&source=ajax&page_id=' + ajaxEscape(title)); |
1198 var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'PageManager&source=ajax&page_id=' + ajaxEscape(title)); |
1199 if ( (ENANO_SID + ' ').length > 1 ) |
1199 if ( (ENANO_SID + ' ').length > 1 ) |
1200 window.location = loc; |
1200 window.location = loc; |
1201 }, 9); |
1201 }, 9); |
1202 return false; |
1202 return false; |
1203 } |
1203 } |
1204 var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'PageManager&source=ajax&page_id=' + ajaxEscape(title)); |
1204 var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'PageManager&source=ajax&page_id=' + ajaxEscape(title)); |
1205 window.location = loc; |
1205 window.location = loc; |
1206 } |
1206 } |
1207 |
1207 |
1208 window.ajaxLoginNavTo = function(namespace, page_id, min_level, get) |
1208 window.ajaxLoginNavTo = function(namespace, page_id, min_level, get) |
1209 { |
1209 { |
1210 // IE <6 pseudo-compatibility |
1210 // IE <6 pseudo-compatibility |
1211 if ( KILL_SWITCH ) |
1211 if ( KILL_SWITCH ) |
1212 return true; |
1212 return true; |
1213 void(namespace); |
1213 void(namespace); |
1214 void(page_id); |
1214 void(page_id); |
1215 get = get || false; |
1215 get = get || false; |
1216 if ( auth_level < min_level ) |
1216 if ( auth_level < min_level ) |
1217 { |
1217 { |
1218 ajaxPromptAdminAuth(function(k) { |
1218 ajaxPromptAdminAuth(function(k) { |
1219 ENANO_SID = k; |
1219 ENANO_SID = k; |
1220 auth_level = min_level; |
1220 auth_level = min_level; |
1221 var loc = makeUrlNS(namespace, page_id, get); |
1221 var loc = makeUrlNS(namespace, page_id, get); |
1222 if ( (ENANO_SID + ' ').length > 1 ) |
1222 if ( (ENANO_SID + ' ').length > 1 ) |
1223 window.location = loc; |
1223 window.location = loc; |
1224 }, min_level); |
1224 }, min_level); |
1225 return false; |
1225 return false; |
1226 } |
1226 } |
1227 var loc = makeUrlNS(namespace, page_id, get); |
1227 var loc = makeUrlNS(namespace, page_id, get); |
1228 window.location = loc; |
1228 window.location = loc; |
1229 } |
1229 } |
1230 |
1230 |
1231 window.ajaxAdminUser = function(username) |
1231 window.ajaxAdminUser = function(username) |
1232 { |
1232 { |
1233 // IE <6 pseudo-compatibility |
1233 // IE <6 pseudo-compatibility |
1234 if ( KILL_SWITCH ) |
1234 if ( KILL_SWITCH ) |
1235 return true; |
1235 return true; |
1236 if ( auth_level < USER_LEVEL_ADMIN ) |
1236 if ( auth_level < USER_LEVEL_ADMIN ) |
1237 { |
1237 { |
1238 ajaxPromptAdminAuth(function(k) { |
1238 ajaxPromptAdminAuth(function(k) { |
1239 ENANO_SID = k; |
1239 ENANO_SID = k; |
1240 auth_level = USER_LEVEL_ADMIN; |
1240 auth_level = USER_LEVEL_ADMIN; |
1241 var loc = String(window.location + ''); |
1241 var loc = String(window.location + ''); |
1242 window.location = append_sid(loc); |
1242 window.location = append_sid(loc); |
1243 var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'UserManager&src=get&user=' + ajaxEscape(username)); |
1243 var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'UserManager&src=get&user=' + ajaxEscape(username)); |
1244 if ( (ENANO_SID + ' ').length > 1 ) |
1244 if ( (ENANO_SID + ' ').length > 1 ) |
1245 window.location = loc; |
1245 window.location = loc; |
1246 }, 9); |
1246 }, 9); |
1247 return false; |
1247 return false; |
1248 } |
1248 } |
1249 var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'UserManager&src=get&user=' + ajaxEscape(username)); |
1249 var loc = makeUrlNS('Special', 'Administration', 'module=' + namespace_list['Admin'] + 'UserManager&src=get&user=' + ajaxEscape(username)); |
1250 window.location = loc; |
1250 window.location = loc; |
1251 } |
1251 } |
1252 |
1252 |
1253 window.ajaxDynamicReauth = function(adminpage, level) |
1253 window.ajaxDynamicReauth = function(adminpage, level) |
1254 { |
1254 { |
1255 if ( auth_level < USER_LEVEL_MEMBER ) |
1255 if ( auth_level < USER_LEVEL_MEMBER ) |
1256 { |
1256 { |
1257 ajaxStartLogin(); |
1257 ajaxStartLogin(); |
1258 return false; |
1258 return false; |
1259 } |
1259 } |
1260 |
1260 |
1261 var old_sid = ENANO_SID; |
1261 var old_sid = ENANO_SID; |
1262 var targetpage = adminpage; |
1262 var targetpage = adminpage; |
1263 if ( !level ) |
1263 if ( !level ) |
1264 { |
1264 { |
1265 level = USER_LEVEL_ADMIN; |
1265 level = USER_LEVEL_ADMIN; |
1266 } |
1266 } |
1267 |
1267 |
1268 ajaxLogonInit(function(k, response) |
1268 ajaxLogonInit(function(k, response) |
1269 { |
1269 { |
1270 ajaxLoginReplaceSIDInline(k, old_sid, level); |
1270 ajaxLoginReplaceSIDInline(k, old_sid, level); |
1271 window.user_id = response.user_id; |
1271 window.user_id = response.user_id; |
1272 window.user_level = response.user_level; |
1272 window.user_level = response.user_level; |
1273 mb_current_obj.destroy(); |
1273 mb_current_obj.destroy(); |
1274 if ( typeof(targetpage) == 'string' ) |
1274 if ( typeof(targetpage) == 'string' ) |
1275 { |
1275 { |
1276 ajaxPage(targetpage); |
1276 ajaxPage(targetpage); |
1277 } |
1277 } |
1278 else if ( typeof(targetpage) == 'function' ) |
1278 else if ( typeof(targetpage) == 'function' ) |
1279 { |
1279 { |
1280 targetpage(k); |
1280 targetpage(k); |
1281 } |
1281 } |
1282 }, level); |
1282 }, level); |
1283 if ( typeof(adminpage) == 'string' ) |
1283 if ( typeof(adminpage) == 'string' ) |
1284 { |
1284 { |
1285 ajaxLoginShowFriendlyError({ |
1285 ajaxLoginShowFriendlyError({ |
1286 error_code: 'admin_session_timed_out', |
1286 error_code: 'admin_session_timed_out', |
1287 respawn_info: {} |
1287 respawn_info: {} |
1288 }); |
1288 }); |
1289 } |
1289 } |
1290 } |
1290 } |
1291 |
1291 |
1292 window.ajaxRenewSession = function() |
1292 window.ajaxRenewSession = function() |
1293 { |
1293 { |
1294 ajaxDynamicReauth(false); |
1294 ajaxDynamicReauth(false); |
1295 } |
1295 } |
1296 |
1296 |
1297 window.ajaxTrashElevSession = function() |
1297 window.ajaxTrashElevSession = function() |
1298 { |
1298 { |
1299 load_component(['messagebox', 'fadefilter', 'l10n', 'flyin', 'jquery', 'jquery-ui']); |
1299 load_component(['messagebox', 'fadefilter', 'l10n', 'flyin', 'jquery', 'jquery-ui']); |
1300 miniPromptMessage({ |
1300 miniPromptMessage({ |
1301 title: $lang.get('user_logout_confirm_title_elev'), |
1301 title: $lang.get('user_logout_confirm_title_elev'), |
1302 message: $lang.get('user_logout_confirm_body_elev'), |
1302 message: $lang.get('user_logout_confirm_body_elev'), |
1303 buttons: [ |
1303 buttons: [ |
1304 { |
1304 { |
1305 text: $lang.get('user_logout_confirm_btn_logout'), |
1305 text: $lang.get('user_logout_confirm_btn_logout'), |
1306 color: 'red', |
1306 color: 'red', |
1307 style: { |
1307 style: { |
1308 fontWeight: 'bold' |
1308 fontWeight: 'bold' |
1309 }, |
1309 }, |
1310 onclick: function() |
1310 onclick: function() |
1311 { |
1311 { |
1312 ajaxLoginPerformRequest({ |
1312 ajaxLoginPerformRequest({ |
1313 mode: 'logout', |
1313 mode: 'logout', |
1314 level: auth_level, |
1314 level: auth_level, |
1315 csrf_token: csrf_token |
1315 csrf_token: csrf_token |
1316 }); |
1316 }); |
1317 miniPromptDestroy(this); |
1317 miniPromptDestroy(this); |
1318 } |
1318 } |
1319 }, |
1319 }, |
1320 { |
1320 { |
1321 text: $lang.get('etc_cancel'), |
1321 text: $lang.get('etc_cancel'), |
1322 onclick: function() |
1322 onclick: function() |
1323 { |
1323 { |
1324 miniPromptDestroy(this); |
1324 miniPromptDestroy(this); |
1325 } |
1325 } |
1326 } |
1326 } |
1327 ] |
1327 ] |
1328 }); |
1328 }); |
1329 } |
1329 } |
1330 |
1330 |
1331 /** |
1331 /** |
1332 * Take an SID and patch all internal links on the page. |
1332 * Take an SID and patch all internal links on the page. |
1333 * @param string New key. If false, removes keys from the page. |
1333 * @param string New key. If false, removes keys from the page. |