繁体   English   中英

Yii2 如果其他注册用户在 URL 上,如何阻止对 URL 的访问?

[英]Yii2 how to block access for URL if other registered user is on that URL?

我今天的目标是让其他注册用户无法使用 URL,如果其中一位用户打开了 URL,并在该用户离开时使其可用。 现在我只知道如何阻止它 - 使用缓存,但问题在于解锁,因为用户可以在任何地方 go 甚至只是关闭浏览器。 我知道有设置缓存计时器的选项,但在我的情况下这不是一个选项 - 系统必须知道 URL 中是否有一些用户。有人可以帮我一些想法如何实现这个吗?

我个人唯一能想到的是使用 JWT 或会话来检查登录用户是否在该页面上,然后检查当前用户是否不等于试图进入该页面的用户的条件,如果不是'匹配只是将该用户重定向到其他地方。

 export const blockAccess = expressAsyncHandler(async (req, res, next) => { //check if the user is currently on the page if (req.session.promoPage) { //if they are, redirect new user's that're trying to access the page to the home page if (req.session.promoPage.userId.== req.user.id) { res.redirect('/') } } next() //next here is a function that tells the program to move on to the next middleware function or route etc.... })

暂无
暂无

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

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