Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> idleTimeout - Prośba o sprawdzenie
topcio
post 18.03.2018, 13:42:26
Post #1





Grupa: Zarejestrowani
Postów: 140
Pomógł: 0
Dołączył: 14.01.2017

Ostrzeżenie: (0%)
-----


Wielka prośba, aby pomóc mi znaleźć błąd w poniższym skrypcie
Problem polega na tym, że jak odblokuje interfejs i odświeżę stronę to mnie wylogowuje, dziwne bo skoro hasło zostało przyjęte po ID sesji i user_ID to nie powinno mnie wylogować.
Jest tu jeszcze jeden bubel, ale nie ma to w tej chwili znaczenia, otóż muszę ajax request zrobić, aby zmienna zapisująca id bieżącej sesji była zapisywana w mysql jako json array, aby potem przy odblokowywaniu usuwać tylko jedno id z arraya a nie opróżniać cały, tak by działało to w kliku domenach jednocześnie.

[JAVASCRIPT] pobierz, plaintext
  1. (function($) {
  2.  
  3. $.fn.idleTimeout = function(userRuntimeConfig) {
  4. //## Public Configuration Variables
  5. var defaultConfig = {
  6. redirectUrl: '/logout', // redirect to this url on logout. Set to "redirectUrl: false" to disable redirect
  7.  
  8. // idle settings
  9. idleTimeLimit: 180, // 'No activity' time limit in seconds. 1200 = 20 Minutes
  10. idleCheckHeartbeat: 1, // Frequency to check for idle timeouts in seconds
  11.  
  12. // optional custom callback to perform before logout
  13. customCallback: false, // set to false for no customCallback
  14. // customCallback: function () { // define optional custom js function
  15. // perform custom action before logout
  16. // },
  17.  
  18. // configure which activity events to detect
  19. activityEvents: 'click keypress scroll wheel mousewheel mousemove', // separate each event with a space
  20.  
  21. // warning dialog box configuration
  22. enableDialog: true, // set to false for logout without warning dialog
  23. dialogDisplayLimit: 180, // Time to display the warning dialog before logout (and optional callback) in seconds. 180 = 3 Minutes
  24. dialogTitle: 'Session Expiration Warning', // also displays on browser title bar
  25. dialogText: 'Because you have been inactive, your session is about to expire.',
  26. dialogTimeRemaining: 'Time remaining',
  27. dialogStayLoggedInButton: 'Stay Logged In',
  28. dialogLogOutNowButton: 'Log Out Now',
  29. userInfo: 'Z Powodu Zbyt Długiej Nieaktywności,<br>Konto Zostało Zablokowane.',
  30.  
  31. // error message if https://github.com/marcuswestin/store.js not enabled
  32. errorAlertMessage: 'Please disable "Private Mode", or upgrade to a modern browser. Or perhaps a dependent file missing. Please see: https://github.com/marcuswestin/store.js',
  33.  
  34. // server-side session keep-alive timer
  35. sessionKeepAliveTimer: 60, // ping the server at this interval in seconds. 600 = 10 Minutes. Set to false to disable pings
  36. sessionKeepAliveUrl: window.location.href // set URL to ping - does not apply if sessionKeepAliveTimer: false
  37. },
  38.  
  39. //## Private Variables
  40. currentConfig = $.extend(defaultConfig, userRuntimeConfig), // merge default and user runtime configuration
  41. origTitle = document.title, // save original browser title
  42. activityDetector,
  43. startKeepSessionAlive, stopKeepSessionAlive, keepSession, keepAlivePing, // session keep alive
  44. idleTimer, remainingTimer, checkIdleTimeout, checkIdleTimeoutLoop, startIdleTimer, stopIdleTimer, // idle timer
  45. openWarningDialog, dialogTimer, checkDialogTimeout, startDialogTimer, stopDialogTimer, isDialogOpen, destroyWarningDialog, countdownDisplay, // warning dialog
  46. logoutUser;
  47. //## Public Functions
  48. // trigger a manual user logout
  49. // use this code snippet on your site's Logout button: $.fn.idleTimeout().logout();
  50. this.logout = function() {
  51. store.set('idleTimerLoggedOut', true);
  52. };
  53. //## Private Functions
  54.  
  55. //----------- KEEP SESSION ALIVE FUNCTIONS --------------//
  56. startKeepSessionAlive = function() {
  57.  
  58. keepSession = function() {
  59. $.get(currentConfig.sessionKeepAliveUrl);
  60. startKeepSessionAlive();
  61. };
  62. keepAlivePing = setTimeout(keepSession, (currentConfig.sessionKeepAliveTimer * 1000));
  63. };
  64.  
  65. stopKeepSessionAlive = function() {
  66. clearTimeout(keepAlivePing);
  67. };
  68. //----------- ACTIVITY DETECTION FUNCTION --------------//
  69. activityDetector = function() {
  70. $('body').on(currentConfig.activityEvents, function() {
  71. if (!currentConfig.enableDialog || (currentConfig.enableDialog && isDialogOpen() !== true)) {
  72. startIdleTimer();
  73. }
  74. });
  75. };
  76. //----------- IDLE TIMER FUNCTIONS --------------//
  77. checkIdleTimeout = function() {
  78. var timeIdleTimeout = (store.get('idleTimerLastActivity') + (currentConfig.idleTimeLimit * 1000));
  79. if ($.now() > timeIdleTimeout) {
  80. if (!currentConfig.enableDialog) { // warning dialog is disabled
  81. logoutUser(); // immediately log out user when user is idle for idleTimeLimit
  82. } else if (currentConfig.enableDialog && isDialogOpen() !== true) {
  83. openWarningDialog();
  84. startDialogTimer(); // start timing the warning dialog
  85. }
  86. } else if (store.get('idleTimerLoggedOut') === true) { //a 'manual' user logout?
  87. logoutUser();
  88. } else {
  89. if (currentConfig.enableDialog && isDialogOpen() === true) {
  90. destroyWarningDialog();
  91. stopDialogTimer();
  92. }
  93. }
  94. };
  95. startIdleTimer = function() {
  96. stopIdleTimer();
  97. store.set('idleTimerLastActivity', $.now());
  98. checkIdleTimeoutLoop();
  99. };
  100.  
  101. checkIdleTimeoutLoop = function() {
  102. checkIdleTimeout();
  103. idleTimer = setTimeout(checkIdleTimeoutLoop, (currentConfig.idleCheckHeartbeat * 1000));
  104. };
  105.  
  106. stopIdleTimer = function() {
  107. clearTimeout(idleTimer);
  108. };
[JAVASCRIPT] pobierz, plaintext



końcówka skryptu
[php]
//----------- WARNING DIALOG FUNCTIONS --------------//
openWarningDialog = function() {

$('#blockUI').fadeIn(500);
$('#user_info').html(currentConfig.userInfo);
$.post('../php_function/user/user.php', {
ajax_test: "user_session_frozen"
});
$('#unblock_UI_confirm').click(function() {
passVerification(this);
});
console.log(timeIdleTimeout);
// var dialogContent = "<div id='idletimer_warning_dialog'><p>" + currentConfig.dialogText + "</p><p style='display:inline'>" + currentConfig.dialogTimeRemaining + ": <div style='display:inline' id='countdownDisplay'></div></p></div>";
/* $(dialogContent).dialog({
buttons: [{
text: currentConfig.dialogStayLoggedInButton,
click: function () {
destroyWarningDialog();
stopDialogTimer();
startIdleTimer();
}
},
{
text: currentConfig.dialogLogOutNowButton,
click: function () {
logoutUser();
}
}
],
closeOnEscape: false,
modal: true,
title: currentConfig.dialogTitle,
open: function () {
$(this).closest('.ui-dialog').find('.ui-dialog-titlebar-close').hide();
}
}); */
countdownDisplay();
document.title = currentConfig.dialogTitle;
if (currentConfig.sessionKeepAliveTimer) {
stopKeepSessionAlive();
}
};
passVerification = function(elem) {
event.preventDefault();
event.stopPropagation();
$.post('../php_function/user/user.php', $(elem).parents("form").serializeArray(),
function(ret) {
if (ret == true) {
$.post('../php_function/user/user.php', {
ajax_test: "user_session_unfrozen"
});
console.log(dialogTimer);
stopDialogTimer();
startIdleTimer();
destroyWarningDialog();
}
if (ret == false) {}
console.log(ret);
startIdleTimer();
console.log(startIdleTimer());
});
};
checkDialogTimeout = function() {
var timeDialogTimeout = (store.get('idleTimerLastActivity') + (currentConfig.idleTimeLimit * 1000) + (currentConfig.dialogDisplayLimit * 1000));

if (($.now() > timeDialogTimeout) || (store.get('idleTimerLoggedOut') === true)) {
logoutUser();
}
};

startDialogTimer = function() {
dialogTimer = setInterval(checkDialogTimeout, (currentConfig.idleCheckHeartbeat * 1000));
};
stopDialogTimer = function() {
clearInterval(dialogTimer);
clearInterval(remainingTimer);
};
isDialogOpen = function() {
// var dialogOpen = $("#idletimer_warning_dialog").is(":visible");
var dialogOpen = $('#blockUI').css('display') == 'block';
if (dialogOpen === true) {
$(document).on('keydown', function(e) {
if (e.keyCode == 9 || e.which == 9) e.preventDefault();
if ((e.which || e.keyCode) == 116 || (e.which || e.keyCode) == 82) e.preventDefault();
})
return true;
}
$(document).unbind('keydown');
return false;
};
destroyWarningDialog = function() {
$('#blockUI').fadeOut(500);
document.title = origTitle;
if (currentConfig.sessionKeepAliveTimer) {
startKeepSessionAlive();
}
};
countdownDisplay = function() {
var dialogDisplaySeconds = currentConfig.dialogDisplayLimit,
mins, secs;
remainingTimer = setInterval(function() {
mins = Math.floor(dialogDisplaySeconds / 60); // minutes
if (mins < 10) {
mins = '0' + mins;
}
secs = dialogDisplaySeconds - (mins * 60); // seconds
if (secs < 10) {
secs = '0' + secs;
}
$('#countdownDisplay').html(mins + ':' + secs);
dialogDisplaySeconds -= 1;
}, 1000);
};
//----------- LOGOUT USER FUNCTION --------------//
logoutUser = function() {
store.set('idleTimerLoggedOut', true);
if (currentConfig.sessionKeepAliveTimer) {
stopKeepSessionAlive();
}
if (currentConfig.customCallback) {
currentConfig.customCallback();
}
if (currentConfig.redirectUrl) {
window.location.href = currentConfig.redirectUrl;
}
};
return this.each(function() {
if (store.enabled) {
store.set('idleTimerLastActivity', $.now());
store.set('idleTimerLoggedOut', false);
activityDetector();
if (currentConfig.sessionKeepAliveTimer) {
startKeepSessionAlive();
}
startIdleTimer();
} else {
alert(currentConfig.errorAlertMessage);
}
});
};
}(jQuery));
[php]

Niestety nie mogę tej końcówki umieścić w tagach, bo tekst jest za długi smile.gif


Problem prawdopodobnie leży w startDialogTimer i stopDialogTimer, bo w konsoli licznik się nie zeruje, ale nie potrafię tego ugryźć.

Ten post edytował topcio 18.03.2018, 13:25:55
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 28.03.2024 - 09:20