📄 authentication.js
字号:
/*
* Copyright 2001-2007 Hippo (www.hippo.nl)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var REQUEST_STATUS_LOADING = 1;
var REQUEST_STATUS_SUCCESS = 2;
var REQUEST_STATUS_FAILURE = 3;
var REQUEST_STATUS_TIMED_OUT = 4;
function AuthenticationManager() {
if ( !Cfx.Class.IsDefined( AuthenticationManager ) ) {
Cfx.Class.New( AuthenticationManager, baseComponent );
if ( Cfx.Class.IsInitializing( AuthenticationManager ) ) {
AuthenticationManager.Method(init);
AuthenticationManager.Method(start);
AuthenticationManager.Method(restart);
AuthenticationManager.Method(stopAll); //stop is a keyword
AuthenticationManager.Method(isConnected);
AuthenticationManager.Method(reconnect);
AuthenticationManager.Method(disconnect);
return;
}
}
this.InitInstance();
this._alive= false;
this._forcedStop = false;
this._retries = 0;
this._returnedError = 0;
return this;
function init(){
if(this.log.debugging()){
this.log.debug("init(): keepAliveURI=" + this.config.keepAliveURI);
}
this.start();
}
function isConnected(){
return this._alive;
}
function start(sync) {
if(this._forcedStop) {
return;
}
if(this.log.debugging()){
this.log.debug('start() called');
}
var _this = this;
var _interval = this.config.checkInterval;
var _synchronized = false;
if (sync != undefined) {
_synchronized = sync;
}
var requestStatus = REQUEST_STATUS_LOADING;
var succ = function(request) {
if (requestStatus != REQUEST_STATUS_TIMED_OUT){
requestStatus = REQUEST_STATUS_SUCCESS;
_this._retries = 0;
try{
var code = request.responseXML.documentElement.getAttribute("code");
if(_this.log.debugging()) {
_this.log.debug("server response=" + code);
}
if(code==200 || (code==500 && _this.config.ignoreErrors)) {
c = 0;
_this._alive = true;
_this.sm.lookup("framework.eventmanager").executeDelayedEvents();
window.setTimeout(function(){_this.start()}, _interval*1000);
}
else if(code==500 && _this._returnedError < _this.config.retryAfterError) {
_this._returnedError++;
window.setTimeout(function(){_this.start()}, _this.config.intervalAfterError*1000);
}
else {
_this._returnedError = 0;
_this._alive = false;
}
}catch(e){
//_this.log.error(e)
}
}
}
var fail = function(request) {
if (requestStatus != REQUEST_STATUS_TIMED_OUT){
requestStatus = REQUEST_STATUS_FAILURE;
_this._retries = 0;
_this._returnedError = 0;
_this._alive = false;
}
}
var checkTimeOut = function() {
if (requestStatus == REQUEST_STATUS_LOADING){
requestStatus = REQUEST_STATUS_TIMED_OUT;
if(_this._retries < _this.config.retryAfterTimeout){
_this._retries++;
_this._alive = true;
if(_this.log.debugging())
_this.log.debug("Retrying authentication (" + _this._retries+")");
window.setTimeout(function(){_this.start()}, _interval*1000);
}else {
if(_this.log.debugging())
_this.log.debug("Timed out at least " + _this.config.retryAfterTimeout+" times. Session expired.");
_this._alive = false;
_this._retries = 0;
}
}
}
var uri = this.config.keepAliveURI;
if(this.log.debugging()){
this.log.debug("about to send Ajax.Request: " + uri + ", sync=" + _synchronized);
}
new Ajax.Request(uri, {onSuccess:succ, onFailure: fail});
window.setTimeout(checkTimeOut, this.config.requestTimeout*1000);
}
function reconnect(){
//lock application during reconnection
this.context.put("UIlocked", true);
var url = "/login_popup";
var name = "login"
var width = "310"
var height = "270"
var options = "scrollbars=no,toolbar=no,location=no";
var myWin = window.open(url,name,'width=' + width + ',height=' + height + ',' + options);
myWin.focus();
}
function restart(){
this.start(true);
}
function stopAll() {
if(this.log.debugging()) {
this.log.debug("Forced stop!");
}
this._forcedStop = true;
}
function disconnect(){
if(this.log.debugging()) {
this.log.debug("Set alive to false");
}
this._alive = false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -