如何清除设计会话在浏览器关闭? [英] how to clear devise session on browser close?

查看:105
本文介绍了如何清除设计会话在浏览器关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在rails应用程序的ruby中使用'devise'进行密码验证。一旦我成功登录,我关闭浏览器并打开一个新的浏览器窗口,我仍然登录。说我使用Chrome,我关闭所有的chrome实例,然后打开一个新的。我还在登录,同样的情况下,我也在做IE和Firefox。

I am using 'devise' for password authentication in my ruby on rails app. Once I successfully login and I close my browser and open a new browser window I am still logged in. Lets say I am using Chrome, I close all instances of chrome and then open a new one. I am still logged in. The same is the case when I am doing IE and Firefox too.

我会假设在窗口附近,打开一个新的窗口应该建立一个服务器和浏览器之间的新会话不是吗?如果不是我如何实现呢?

I would assume on close of window and opening a new window should establish a new session between the server and the browser isn't it? If not how do I achieve that?

我曾尝试在浏览器窗口的 onbeforeunload 事件上单击注销按钮,但它不起作用,以任何形式提交或链接点击注销应用程序。

i used tried doing clicking on logout button on browser window's onbeforeunload event, but it does not works as it logout of application on any form submit or link click.

window.onbeforeunload = function() {
  $('#logout_cls').click();
};

并尝试向会话发送 AJAX 控制器销毁操作以清除会话。

and tried sending AJAX request to the sessions controller destroy action for clearing the session.

  jQuery(window).bind(
    "close",
    function(event) {
          $.ajax({
            type: 'DELETE',
            dataType: 'json',
            url: $('#logout_cls').attr('href')
          });
    });

但所有这些都无效。

推荐答案

证明问题是我的session_store配置如何。

Turns out that the problem was how my session_store was configured.

MyApp::Application.config.session_store :active_record_store, 
{:key => '_my_app_session', :secret => '5xb5x1g92e965b95b16e49x79gxx9999', :expire_after => 2.hours}

我删除了选项,问题解决了。

I removed the options and the issue was solved.

我有另外一个问题,那就是删除选项有没有潜在的风险?我没有在会话中存储任何重要的数据,但是放置了我不想要的数据。

I have another question though and that is removing options does it have any potential risks? I am not storing any important data in the session obviously but putting in data I wouldn't want exposed.

我的应用程序将在几天内生效非常有帮助,以获得答案。我在一个小时左右的时间里搜了一下,但没有太多的运气。

My app would be going live in a few days it would be very helpful to get an answer for this. I googled things for an hour or so but didn't have too much luck.

谢谢

这篇关于如何清除设计会话在浏览器关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆