Redirecting to and from the login page from within the controller

The chartsearch module is almost making all it’s calls to the server using ajax and one issue i noticed is that the more idle it takes after the user has loaded the page, he/she is automatically signed out out openmrs, I therefore need a way of redirecting to the login page just in-case the user is logged, and back to the previous page after a successful login. I have tried to look around and so no controller where such a thing is done in the same way.

Here is for-example one of my controller method that i call into using ajax

public String getResultsFromTheServer(FragmentModel model, @RequestParam(value = "phrase", required = false) SearchPhrase search_phrase,
                                      @RequestParam("patientId") Patient patient,
                                      @RequestParam(value = "categories[]", required = false) String[] categories) {
	SearchAPI searchAPIInstance = SearchAPI.getInstance();
	ChartsearchPageController.searchAndReturnResults(search_phrase, patient, categories, searchAPIInstance, false);
	return GeneratingJson.generateJson(false);

Basically i would need something like;

if(Context.getAuthenticatedUser() == null) {
		//redirect to login page here

The vitals app is an example of a form that will popup a login dialog box if you try submitting after the session has expired. The code responsible for this is at:

In the above, you could look at:

htmlForm.submitHtmlForm = function(),
htmlForm.loginThenSubmitHtmlForm = function(), var
checkIfLoggedInAndErrorsCallback = function(isLoggedIn)

Those are the lines: 175, 184, 59, and more…

1 Like