这些都在Bob 的指南中,但基本上你要做的是检查用户是否有 ID 或用户名,如果没有,他们没有登录。
您可能需要进行一些挖掘,看看是否可以在插件中实现重定向,而不是在可能是 onRequest 事件的片段中实现 - 所以在发现用户需要重定向之前,您不会呈现页面/资源。
There are various methods. One easy method is to use this code:
if ($modx->user->get('username') == '(anonymous)') {
/* user is not logged in */
}
Here is the official method for seeing if the user is logged in to the current context:
if ($modx->user->hasSessionContext($modx->context->get('key'))) {
/* user is logged in */
}
If you know the name of the current context (e.g., web), you can use this method. The name of the context is required:
if $modx->user->isAuthenticated('web') {
/* user is logged in to web context */
}