Case: anonymous user is collecting products in his shopping cart, then signs in and the shopping cart need to be transferred to the loggen in user. This can be done in Mendix < 7 with the sign in microflow, works perfectly.
Mendix 7: from the upgrade documentation:
4.6 Sign-In Microflows
Sign-in microflows are no longer supported, because they do not add any functionality. In a future version, the state will be automatically transferred from the anonymous user to the signed-in user by the client. In Mendix 7, having a sign-in microflow selected will result in a consistency check error. When this is solved by setting the microflow to None, the property will automatically disappear from the UI.
It seems Mendix removed this feature without giving an alternative. "Do not add any functionality" is not correct, see my example case.
I'm hoping that i'm wrong and that there are work arounds for this. I was hoping that the session was reused when signing in from anonymous to logged in user. But that is also not the case.
So how am I going to transfer data from anonymous to logged in user in Mendix 7?
Update 09-06: It seems that there is no simpel work around. I filed a ticket since Mendix removed this feature based on a wrong assumption ('Do not add any functionality')
Update 22-06: In the end we had a very generic and simple fix where Mendix came up with. You don't have to add requesthandler, you don't need custom login pages, or cookies, e.t.c. Actually it's pretty simple and you don't have to do all kind of refactoring. I'll submit this as a more generic module to the app store as well. Will be in the appstore within 1-2 weeks. But for anybody needing it right now, below the code structure you'll need.
You've to replace the LoginAction of Mendix with a custom login action. Note this might conflict with other modules which are replacing the default LoginAction as well, like IPRange, then you have to combine the two login actions. Replace it like this in a java action which is called After startup:
LoginActionListener loginActionListener = new LoginActionListener(LoginAction.class);
loginActionListener.addReplaceEvent(TransferDataLoginAction.class.getName());
Core.addUserAction(TransferDataLoginAction.class);
Core.addListener(loginActionListener);
The TransferDataLoginAction has the following content. What it does: it first calls a microflow to retrieve an object related to the anonymous user (ophalenUserActionAnonymous). For example a shoppping cart, in our case (which you see in the code below) it's an instance of the entity UserAction. The second part is to link the UserAction (or shopping cart, or whatever) to the signed in user by the MF: linkUserActionNaarIngelogdeGebruiker.
ISession newSession = null;
ISession oldSession = Core.getSessionById(UUID.fromString(currentSessionId));
if(currentSessionId != null && currentSessionId != "" && oldSession != null){
UserAction useraction = Microflows.ophalenUserActionAnonymous(oldSession.createContext());
newSession = super.execute();
if(useraction != null)
Microflows.linkUserActionNaarIngelogdeGebruiker(newSession.createContext(), useraction);
}
else newSession = super.execute();
return newSession;