Getting session's remaining time for expiry in liferay - session

I am using liferay 6.1, In a particular jsp, when a session expires and when some button is clicked it loads the login page within the jsp instead of redirecting.
My code would look like this,
var liferaySession = Liferay.Session._currentTime;
if(liferaySession == '0'){
// reload page
}
else{
// navigate to othr page.
}
The same was working fine in liferay 5.
THnks in advance

I solved by using the following code.
Liferay.on('sessionExpired',
function(event) {
liferaySession = 0;
} );

Related

`window.location.reload` doesn't reload page in Chrome

I am using following code to let the user log into Magneto with AJAX. If the correct username and password is entered the page will refresh and display the user navbar in the header. The field works in Firefox, Safari and IE but not in Chrome. I have to refresh the page for the navbar to display.
Why does this problem occur?
Code:
AjaxLoginForm.submit = function(button){
if (this.validator.validate()) {
// show ajax image
// button.insert({"after":osc_ajax_loading_small});
AjaxLoginForm.hideLoader();
AjaxLoginForm.insertLoader(button);
$("ajaxlogin_form").request({
onSuccess: function(transport) {
var json = transport.responseText.evalJSON();
if(json.is_forgot_pwd){
if(json.success){
$("ajaxlogin_form_message").update("<div>"+json.success_message+"</div>");
$("ajaxlogin_form_message").show();
}
if(json.error){
$("ajaxlogin_form_message").update("<div>"+json.error_message+"</div>");
$("ajaxlogin_form_message").show();
}
}else{
if(json.success){
// If the correct username and password is entered
// the page will refresh and display user navbar
// in the header
window.location.reload();
}
if(json.error){
$("ajaxlogin_form_message").update("<div>"+json.error_message+"</div>");
$("ajaxlogin_form_message").show();
}
}
AjaxLoginForm.hideLoader();
//setTimeout("AjaxLoginForm.hideResponseMessage()", 5000);
}
});
}
}.bind(AjaxLoginForm);
You can try it with a setTimeout.Also you can simplify the code,currently you are writting json.success and json.error multiple times which should be written once.
setTimeout(function(){
window.location.reload();
},100);
try this, I am preety sure in chrome window.location = self.location; should work, or try location.reload( true ); otherwise by callback some other function to reload your page.
Otherwise you should get some error that prevents reload, you can get a console in success.
For script is in iframe top.location.reload() works for me.

How can i set a session variable in jquery?

Can anyone help me how to set a session variable in Jquery. Actually My requirement is like this:-
I am having a popup in html file. When i click the link, the popup opens. However, if i set the session expire , the popup should not open. So, when i click on the link, if session expires, the popup should not open but should redirect to targeted page. How can i do this?? My TL told me to google this but didn't found actually what i required. He suggested me to set session in Jquery. Is there any alternative for this?? As i am a newbie to Jquery, any code snippets are higly appreciated.please help me..
If you are needing to do this in .NET MVC you can do it as such. Below is a an example:
Controller:
if (Session["pageInitCounter"] == null)
{
Session["pageInitCounter"] = 1;
}
else
{
int counter = Convert.ToInt32(Session["pageInitCounter"]);
counter++;
Session["pageInitCounter"] = counter;
}
View:
#Html.Hidden("pageInitCounter", Session["pageInitCounter"])
Javascript:
alert($("#pageInitCounter").val());
You may try using localStorage like below.
$(document).ready(function() {
var notSeen = localStorage['seen'];
if (!notSeen) {
// open popup
localStorage['seen'] = "yes";
}
});
Alternatively, use may as well try using a hidden field for this purpose.
Please visit the below links for more information. This should satisfy your requirement
http://forums.asp.net/t/1499296.aspx
http://forums.asp.net/t/1672519.aspx/1

Wordpress Create Category AJAX Response

I currently have a plugin that allows a user to activate/deactivate categories to drive a menu. I've created an option for the toggle and have it functioning in the create form and edit form seamlessly. The only place I can't seem to add it is to the AJAX return from wordpress when the category is created. I can create the column when the Categories page is loaded but don't know how to tap into the AJAX Return without modifying the core. Is there a hook that I'm unaware of that allows you to modify this return?
Using Akmal's answer, this is my script to check if the Taxonomy-Category was created or not.
Thanks Akmal.
Wordpress version 3.8.2
$(document).ajaxComplete(function(event, xhr, settings) {
var queryStringArr = settings.data.split('&');
if( $.inArray('action=add-tag', queryStringArr) !== -1){
var xml = xhr.responseXML;
$response = $(xml).find('term_id').text();
if($response!=""){
console.log('This is the action.');
}
}
});
Do you try to run some Javascript after ajax return (after add new category)?
Try to put below code in your code when you create the custom field in category form :
$(document).ajaxComplete(function(event, xhr, settings) {
var queryStringArr = settings.data.split('&');
if ($.inArray('action=add-tag', queryStringArr) !== -1){
your_javascript_function(); //this is your js function
}
});

On Session Timeout Login.gsp is rendered within the <body> tag instead of redirecting to a new gsp page

I am new to Grails and working on a project which has just 2 controllers one is for login and the other is for a explorer (similar to a windows explorer with left panel displaying a tree -like structure and the right displays the folders contents as a table)
The application is working as excpected meaning when user accesses the application it displays Login Screen if user hasn't logged in and if he has logged in it displays the explorer screen.
But this is not the case on session Timeout: suppose the session has timed out and the user clicks on a link in the right panel of the explorer screen then the login screen is displayed within the right panel.
I am using SecurityFilter to redirect to login screen.
SecurityFilters.groovy
def filters = {
loginCheck(controller:'*', action:'*') {
before = {
if (!session.idpuser && actionName != "login") {
redirect(controller: "user", action: "login")
return false
}
}
}
}
userController.groovy
def login () {
if (request.get) {
return false
}
......
redirect(controller: "explorer", action: "file")
}
explorerController.groovy
def generateFiles = {
.....
render(template: 'list', model: [ dirList: dirList])
}
UrlMappings.groovy
static mappings = {
"/$controller/$action?/$id?"{
constraints {
// apply constraints here
}
}
"/"(action:"file", controller: "explorer")
"500"(view:'/error')
}
The reason I think login.gsp is being rendered in the right panel is because when a user click on a link in right panel "generateFiles" action is invoked and that is rendering login.gsp as a template within explorer.gsp. But I dont know how to fix it :(
I would appreciate if someone can help me with this issue.
PLEASE HELP!!!!!
Since this is an ajax based site, you need to explicitly handle the "you need to login" response in your ajax response handlers and force the user to the login page if needed.
Looks like I found the solution may not be an efficient way but it works.Based on the response I get from the Ajax call I am redirecting to Login.gsp using
window.location.href = '${createLink(controller='user', action='login')}'
Thank you cdeszaq for the hint. I really appreciate it.

jQuery Mobile cache pages in order

I have a list of a tags that are hidden. I tried using the data-prefetch attribute as described in the jquery mobile docs. The only problem is it fires off an ajax request for all of them at once and there is no garentee of the order that they get loaded in.
The ordering is very important in what pages are shown next via swipe.
So I decided to try and cache the links programatically via this bit of code.
var last_cache_page = false;
function cache_next_page(){
if(last_cache_page == false){
var cache_link = $('.cache').first();
last_cache_page = cache_link;
}
else{
var cache_link = last_cache_page.nextAll('.cache');
last_cache_page = cache_link;
}
//Start Caching any other pages that we want to swip to
$.mobile.loadPage(cache_link.attr('href'), {showLoadMsg: false});
}
So on $(document).on('pageshow') I call cache_next_page(). That part works fine the real problem is that when using $.mobile.loadPage no jquery mobile page related events fire once the first cached page is interested into the dom.
I have tried pageshow, pageinit and pageload but they only fire the first time the page is loaded. Now if I load the first page which starts the caching directly. That is to say with out visiting any other pages in the application it DOES trigger all the expected events such as pageload.
It is only when you start on page_1 and then go to page_2 (which has the code to start the cache) that it fails to have a pageload event triggered when the cached page is inserted into the dom.
I found out there there is a .done on the object that is returned from .loadPage so I have modified my code as follows to allow it to cache my links in order.
var last_cache_page = false;
function start_caching(){
if(last_cache_page == false){
var cache_link = $('.cache').first();
last_cache_page = cache_link;
}
else{
var cache_link = last_cache_page.nextAll('.cache').first();
last_cache_page = cache_link;
}
if(cache_link.length == 1){
//Start Caching any other pages that we want to swipe to
new_page = $.mobile.loadPage(cache_link.attr('href'), {showLoadMsg: false});
new_page.done(function(){
start_caching();
});
}
}

Resources