-
-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding system event OnBeforeInitSession #15944
Adding system event OnBeforeInitSession #15944
Conversation
I'm not sure I follow the problem being addressed by this. A session is determined by the domain, not by a context. Can you describe the issue you are trying to solve in more detail? |
Think of the following situation:
When you look at the code below, it first initialises the session based on the current context and after that the
Hopefully this clarifies things a bit :) |
The problem is that a session is based on domain, so there should be no conflict on contexts representing different domains (or subdomains as long as the session cookie is subdomain-specific). If you are trying to use a single domain for multiple contexts and allow separate logins for each, then, yes, this would be an "issue." But I'm not sure this addresses all of the potential issues of allowing separate login control within a single session cookie. |
This really is an issue, I'm actually talking about a set up containing multiple contexts using different domains. So I'm actually talking about trying to log in (using Login extra) in the frontend and switch context using OnMODXInit event:
Now I can only login in the web context. When on contexts "en" and "de", the login does not work. However, when I initialise the proper context immediately in |
Understood. We are past the feature freeze for the 3.0 release. However, before just pushing off until 3.1, I'd like to solicit input from others here. |
Circling back to this, since there has been no feedback, I'm still unsure how, if each context has its own session, there is a conflict in sessions here. You say the Login extra does not work. Can you provide specifics on how it is not working? When logging in, it should add the context you are logging in to to the existing session so when the next request loads it would be authenticated for that context. I'll try to set up some tests this weekend to explore this in more detail if you can't provide specific errors or details about the conflict you are having. |
@sdrenth would it be possible to have a simple test case to demonstrate this issue? |
@JoshuaLuckers Please see my comment previous comment on how to reproduce: |
I meant to refer to @opengeek's comment/request:
|
I have certainly not been able to reproduce the issue. It would be helpful to have details on the site configuration so it is possible. |
@opengeek wouldn't it be still useful to have this event regardless of the use case? |
@JoshuaLuckers — I don't like just adding more events, especially for something that has never been an issue before. It seems like there is some unique situation here but I am unable to know what that is without more details. Either way, this is not going to happen before 3.1 anyway. |
This should be enough to be able to reproduce the issue without having this fix.
If you can't reproduce the issue, can you tell me how you've tested this? Please have a look at this method in the MODX class:
As you can see Looking at
|
The problem here is you need to initialize the proper context when calling initialize. I do not think adding an event for the session is the way to address that. This needs something before initialize is called or an event that is triggered at the very start of initialize which will handle the logic for determining which context to initialize in the first place. |
@opengeek I understand what you're saying and I also thought about something like that but I think that's going to be tricky with the way MODX works and would require quite a lot of work rebuilding some core parts of MODX. Mainly because when working with a file based plugin, the extension packages will need to be loaded first so it can load the third party file based plugin which handles the context switching. I think, at least for now, this is the best and quickest solution to resolve this. |
The recommended way to do this previously was to modify index.php to add the logic to determine the context. I would think that just allowing a simple include from the index.php, if it exists, could solve this issue without worrying about overwriting your index.php on upgrades. |
@opengeek So something like this?
context_switch.php:
|
Along those lines, yes. I was thinking |
@opengeek That would work for me as well. What do you think @JoshuaLuckers? Only downside of this resolution I can think of is that it is not as flexible as when switching context using a system event, so plugins are not able to hook into this process. This will fix the issue for my use-case though, so I'm fine either way. |
We can still consider the event for 3.1. I'll add this simple optional require for 3.0 final. |
What does it do?
I've added a new system event called "OnBeforeInitSession" which is called prior to starting the session.
I also added some additional checks to verify if the lexicon service has been loaded yet in the modMediaSource class. This was causing conflicts when invoking an event before _initCulture was called (which loads the lexicon service) and when listening to the event using a static plugin file.
Why is it needed?
We use a plugin to switch between contexts which listens to the OnMODXInit system event, but because this event is triggered after the _initSession method, the session is already set for context "web" and this causes conflicts with sessions. For example, not being able to login in the frontend for NON-web contexts.
Until this moment we switch the context in
index.php
, but it would be cleaner if we could do this by using plugins.To resolve this we added this new system event which is triggered before initialising the sessions, allowing the use of plugins to switch context before the session is initialised.
How to test
Now you should be able to login on the non-web context.
Related issue(s)/PR(s)
#14962