简体   繁体   English

通过控制台关闭引导程序模式

[英]Closing bootstrap modal through console

I am using java servlets and jsp to create a website and one of my requirements is that if any anonymous user tries to visit any page that needs authentication/login a modal should appear above the page and the modal cannot close until you login or sign up (As in case of quora). 我正在使用Java Servlet和JSP创建网站,我的要求之一是,如果任何匿名用户尝试访问任何需要身份验证/登录的页面,则该模式应出现在页面上方,并且该模式只有在您登录或注册后才能关闭(如法定人数)。 So i am checking whether the user is logged in by checking the session attribute in every jsp and if the session attribute is not present i am showing the login modal with backdrop= static using java script. 因此,我通过检查每个jsp中的session属性来检查用户是否已登录,并且如果不存在session属性,我将使用java脚本显示background = static的登录模式。

I have a query, what if someone hides the login modal through console using $("#id").modal("hide") (As i am using bootstrap modal). 我有一个查询,如果有人使用$(“#id”)。modal(“ hide”)通过控制台隐藏登录模式,那该怎么办(因为我正在使用引导模式)。 Is there anyway i can handle this or do i have to take care of this at the backend? 无论如何,我可以处理这个问题,还是必须在后端解决这个问题?

You should take care of it at the back-end as after all the user can disable javascript, instead do it this way: 您应该在后端照顾它,因为毕竟所有用户都可以禁用javascript,而改为这样做:

if(loggedIn)
    //show content for authenticated users

else
    // display the login form

Update: 更新:

As in this PHP Fiddle - hit RUN to show the result - it is the same above idea but in PHP, if you alter the value of $loggedIn to true it will show the content which needs authentication, if $loggedIn is false it will show a login form 就像这个PHP小提琴一样 - 点击RUN以显示结果 -与上面的想法相同,但是在PHP中,如果将$loggedIn的值更改为true ,它将显示需要身份验证的内容,如果$loggedInfalse ,则将显示登录表单

I suppose you could assign an event handler to the hide event. 我想您可以将事件处理程序分配给hide事件。

http://getbootstrap.com/javascript/#modals-events http://getbootstrap.com/javascript/#modals-events

$('#id').on('hide.bs.modal', function (e) {
  // if some condition, dont let them hide it
})

but if a user can get into things they aren't meant to by invoking this js, they could also just inspect the dom and delete this html element. 但是,如果用户可以通过调用此js来完成他们不想要的事情,那么他们也可以仅检查dom并删除此html元素。

Having code like this could help keep people honest but if its a security issue I would make sure to handle it on the server as well. 拥有这样的代码可以帮助人们保持诚实,但是如果遇到安全问题,我也将确保在服务器上也进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM