Custom Log in/ reload web view

0
Greetings. In my project i needed to implement custom log in logic, user should be able to log in in application only via 6-digit code and no user name is required. I implemented this functionality using this approach –> https://www.mattkdaniels.com/blogs/walkthrough-enabling-autologin-functionality-within-your-mendix-app Creating new session with user works as it should, user log in in application its fine, but i faced the issue how to reload view in application so it will start to use new session with logged in user. In link above used JS snippet that call command location.reload() when making a request, but for me this approach worked only 50/50, because some times reload happens before session is updated and user stays anonymous. At this point im using JS timer: setTimeout(function() { location.reload(); }, 1000); This works, and after reload for user us shown his home page, but its totally not the best approach. I’v tried to call a microflow form Java action after creating new session, which will open specific page( normal one, or with JS snippet to reload the page), microflow was called, BUT nothing appears on UI. So the question is how to reload view from Java action?    
asked
1 answers
3

Hi Pavels,

I implemented this functionality recently and ran into the same issue. Are you using the example script in Matt’s blog to call the autologin request handler? I had to make one tweak to it so it didn’t reload the page before the response from the request handler is returned. I also added some handling if the request isn’t returned a 200 it will show the login.html page.

 

callAutologin(); 

function callAutologin() {

		var xhr = new XMLHttpRequest();
		var url = mx.appUrl + "autologin/";
		var params = "loginToken=${loginToken}";
	
		xhr.onreadystatechange = handler; // function to call after response

		xhr.open("POST",url,true);
		xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");

		xhr.send(params);

}


function handler() {
        if (this.readyState === this.DONE) {
            if (this.status === 200) {

				location.reload(); // if reply is 200 then reload and the user will be logged in

            } else {

				window.open("${loginURL}"); // if reply is not 200 then show the login.html page
            }
        }
    }

 

Hope this helps!

answered