0
我使用了附帶基於表單的驗證模塊的示例質詢處理程序。我按照我的要求對其進行了修改。在我的應用程序中,我有一個着陸(主頁)頁面,其中有鏈接到登錄頁面。現在我希望它在用戶點擊登錄按鈕時起作用。 我在這裏遇到的各種問題:工作燈:質詢處理程序未按預期工作
- 在上登錄按鈕第一次點擊,它確實與WL 服務器進行身份驗證,但隨後無法繼續還用於執行登錄 功能邏輯。
- 第一次點擊後,我必須第二次點擊 登錄按鈕。在第二次登錄時,請點擊它完美地執行登錄功能 。
- 當我註銷時,要麼是不是 從服務器刪除會話或什麼?它只執行註銷 功能代碼(在下面給出)。但是,在指定的會話 超時後,它會提示第二次/第三次並顯示「超時消息」。 雖然用戶沒有再次進入。他已經註銷了。
目的:我想應用程序只能登錄時對數的按鈕,但只需點擊一下用戶點擊。當我註銷或超時時,它不應該使會話保持活動狀態,或者再次在指定的時間後再顯示「會話超時」消息&。
我的質詢處理程序:
var aahadAppRealmChallengeHandler = WL.Client.createChallengeHandler("myAppRealm");
var isLandingPage=false , islogout=false;
aahadAppRealmChallengeHandler.isCustomResponse = function(response) {
WL.Logger.debug("I am here >> 1");
if (!response || response.responseText === null) { return false; }
var indicatorIdx = response.responseText.search('j_security_check');
if (indicatorIdx >= 0){ WL.Logger.debug("return true "); return true; }
else {
if(isLandingPage && $.trim($('#fldloginUserID').val()) !="" && $.trim($('#fldloginUserPassword').val()) !="") {
WL.Logger.debug("WL.Client.isUserAuthenticated()=" + WL.Client.isUserAuthenticated("myAppRealm"));
if(WL.Client.isUserAuthenticated("myAppRealm")) { WL.Logger.debug("return false "); return false; }
else { WL.Logger.debug("return true "); return true; }
}
WL.Logger.debug("return false "); return false;
}
};
aahadAppRealmChallengeHandler.handleChallenge = function(response) {
WL.Logger.debug("I am here >> 2");
var indicatorIdx = response.responseText.search('j_security_check');
var suc = response.responseText.search('success');
WL.Logger.debug("I am here >> 3 - indicatorIdx =" + indicatorIdx + " Success =" + suc + " - isLandingPage=" + isLandingPage +" islogout=" +islogout);
if (isLandingPage){
if (suc >= 0){
WL.Logger.debug("I am here >> 4 - isLandingPage=" + isLandingPage +" suc="+suc);
var reqURL = '/j_security_check'; var options = {};
options.parameters = {
j_username : $.trim($('#fldloginUserID').val().toLowerCase()),
j_password : $.trim($('#fldloginUserPassword').val())
};
options.headers = {};
aahadAppRealmChallengeHandler.submitLoginForm(reqURL, options, aahadAppRealmChallengeHandler.submitLoginFormCallback);
}else {
WL.Logger.debug("I am here >> 5");
WL.SimpleDialog.show(DialogMessages_en.SessionExpired_Tile, DialogMessages_en.SessionExpired_Description ,
[ { text : 'Close', handler : function() {
if(busyIndicator.isVisible())
busyIndicator.hide();
isLandingPage = false; userLogout();islogout=true;
$.mobile.changePage("#landingPage" , { transition: "slide"});
} } ]);
}
}
else {
WL.Logger.debug("I am here >> 6 - isLandingPage=" + isLandingPage +" re-Login Again");
if(indicatorIdx < 1) {
var reqURL = '/j_security_check'; var options = {};
options.parameters = {
j_username : $.trim($('#fldloginUserID').val().toLowerCase()),
j_password : $.trim($('#fldloginUserPassword').val())
};
options.headers = {};
aahadAppRealmChallengeHandler.submitLoginForm(reqURL, options, aahadAppRealmChallengeHandler.submitLoginFormCallback);
}
}
};
aahadAppRealmChallengeHandler.submitLoginFormCallback = function(response) {
var isLoginFormResponse = aahadAppRealmChallengeHandler.isCustomResponse(response);
if (isLoginFormResponse){ isLandingPage=false; aahadAppRealmChallengeHandler.handleChallenge(response); }
else {isLandingPage=true; aahadAppRealmChallengeHandler.submitSuccess(); WL.Logger.debug("aahadAppRealmChallengeHandler.submitSuccess()"); }
};
$('#logindone').bind('click', function() {
WL.Logger.debug(" Button Clicked -Before isLandingPage=" +isLandingPage);
isLandingPage=true;
var reqURL = '/j_security_check'; var options = {};
options.parameters = {
j_username : $.trim($('#fldloginUserID').val().toLowerCase()),
j_password : $.trim($('#fldloginUserPassword').val())
};
options.headers = {};
aahadAppRealmChallengeHandler.submitLoginForm(reqURL, options, aahadAppRealmChallengeHandler.submitLoginFormCallback);
loginAuthenticateUser();
});
我的登錄功能
function loginAuthenticateUser() {
WL.Logger.debug("Calling loginAuthenticateUser()....");
busyIndicator.show();
if ($.trim($("#fldloginUserID").val()) !="" && $.trim($("#fldloginUserPassword").val()) !="") {
authenticateLDAPUsers($.trim($("#fldloginUserID").val().toLowerCase()) , $.trim($("#fldloginUserPassword").val()));
}else {
if(busyIndicator.isVisible())
busyIndicator.hide();
simpleDialogDemo(DialogMessages_en.LoginFailed_MsgTitle , DialogMessages_en.LoginFailed_MsgDescription);
}
}
註銷功能
function userLogout() {
WL.Logger.debug("Logout....");
WL.TabBar.setVisible(false);
WL.Client.logout('myAppRealm', {onSuccess: function(){} });
$.mobile.changePage("#landingPage" , { transition: "slide"});
var options = {onSuccess: function() {WL.Logger.debug("collection closed");}, onFailure: function() { WL.Logger.debug("collection closing failed"); } };
WL.JSONStore.closeAll(options);
}
authenticationConfig.xml(國度)
<realm loginModule="Strongme" name="myAppRealm">
<className>com.worklight.core.auth.ext.FormBasedAuthenticator</className>
<parameter name="login-page" value="login.html" />
</realm>
Worklight.properties
serverSessionTimeout=5
任何建議請。
感謝
你能提供任何有關你正在使用的服務器的反饋嗎?網絡跟蹤有助於理解封面下面發生的事情(如Wireshark和TCPMon)。 – Mike 2013-05-16 15:26:09
@Mike,感謝您的回覆至少:)。我正在使用IBM WAS v8,WL Server 5.0.5,Oracle和Windows操作系統。對於跟蹤日誌,我應該共享設備日誌嗎?我可以打印來自挑戰處理程序的isCustomResponse&handleChallenge功能的所有「響應」。或任何你需要WAS日誌? – AAhad 2013-05-16 15:46:43