Updating the currentuser object

3
Hi, I have a use case scenario to manually update the current session from anonymous to known user. I can able to update the current session with known user using “ ISession updatedSession = Core.initializeSession(Core.getUser(this.getContext(), Username), this.getContext().getSession().getId().toString());” How can I update the current user object with my known user object. Can anyone guide through this.
asked
2 answers
5

Hi Kamalanathan,

Hope the below code will work for your scenario,

        IMxRuntimeResponse response= this.getContext().getRuntimeResponse().get();

        IContext systemContext = Core.createSystemContext();

        ISession newSession = Core.initializeSession(Core.getUser(systemContext, user.getName()), "");
        response.addCookie("XASSESSIONID", newSession.getId().toString(),"/" ,"" ,-1 );
        response.addCookie("XASID", "0." + Core.getXASId(),"/" ,"" ,-1);

Thanks!

answered
1

I do not believe you can change a user session from anonymous to a real user. Instead, you need to replace the session. Doing this requires a few steps:

  1. A new session is started for the desired user
  2. The new session cookies are returned to the user’s browser

 

This module does that – you might use it for inspiration:https://appstore.home.mendix.com/link/app/107925/

answered