Transfer data related to the anonymous user to logged in user - not possible anymore in mx7?

17
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: Update 30-6: Module is submitted to the app store. It still needs approval but it will be available soon. The code from Mendix which was in previous revisions of this questions was not complete and didn't include the actual login checking (user/pass match)! Please pull the module from the appstore to avoid security issues.          
asked
4 answers
4

You can create a custom login page (i.e. using an object to capture the user's login information). You now have the user's username, so you can persist all your shopping cart information, associated with the correct user. You then create a session for the user, redirect the user to a request handler to set his cookie and finally, when the user accesses your application with his new session, you retrieve the persisted objects.

If desired, I can share the code for the login, session creation and request handler in Mendix 7.

answered
3

We have fixed the module for Mendix 8.  https://appstore.home.mendix.com/link/app/66443/

thanks for the feedback everyone!

answered
2

Herbert,

Is this on github? I’ve made some fixes for mx8.

OverwriteDefaultLoginAction.java line 33: replace core.addlistener with

Core.getListenersRegistry().addListener(loginActionListener);

TransferDataLoginAction.java

line 66

anoUser = User.load(sysContext, oldSession.getUser(getContext()).getMendixObject().getId());

line 71

User signInUser = User.load(sysContext, newSession.getUser(getContext()).getMendixObject().getId());

 

 

answered
1

There is one trick, for Mx6, I have not yet tested it with Mx7:

In the navigation microflow, create a non-persistent object and link it to the session.

When the anonymous user logs in, the navigation microflow is called again, this time with the logged in user. However, the session is still the same one. At least that is the case in Mx6. Now you can retrieve your NPE from the session and continue with that object.

answered