简体   繁体   English

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

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

My today goal is to make URL unavailable to other registered users if one of the user opened that URL and make it available when this user leaves it.我今天的目标是让其他注册用户无法使用 URL,如果其中一位用户打开了 URL,并在该用户离开时使其可用。 Right now I have only idea how to block it - using cache, but problem is with unblocking as user can go everywhere or even just close the browser.现在我只知道如何阻止它 - 使用缓存,但问题在于解锁,因为用户可以在任何地方 go 甚至只是关闭浏览器。 I know that there is option for set cache timer, but in my case this is NOT an option - system must know if there is some user in that URL. Can someone help me with some ideas how to achieve this?我知道有设置缓存计时器的选项,但在我的情况下这不是一个选项 - 系统必须知道 URL 中是否有一些用户。有人可以帮我一些想法如何实现这个吗?

Only thing I can personally think of is using JWT or sessions to check if a logged in user is on that page, then a condition to check if the current user is not equal user that is trying to get on the page, and if it doesn't match just redirect that user to somewhere else.我个人唯一能想到的是使用 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