Pandora - Sample - Validate User Session

From SmartWiki
Revision as of 11:39, 3 December 2012 by Cameron (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This procedure can be used to ensure a valid user session still exists.

If the session has timed-out it will give the user a chance to open a new tab and re-authenticate to the SmartSimple server rather than losing their work.

  • Because the confirmusersession function is called in the savefunc and returns false if it fails the page will not be submitted to the server and the page will not be refreshed.


</script>
<script type="text/javascript" language="javaScript" src="/Ajax/uta/uta.js"></SCRIPT>
<script language="javaScript">

// savefunc is called on most pages within SmartSimple at the time that the page is saved, saved draft or submitted.
function savefunc(frm){

  //the next line passes the userid of the user that loaded the page to the confirmusersession function.
  // it cancels the save and has an error alert message if the user session no longer exists, or has been taken over by a different user.
  if (!confirmusersession('@me.userid@')) {
      alert('You are no longer logged in, or your login session has been replaced by another user account\n\nPlease open a new window or tab, log back in and re-submit this form');
      return false;
      }

 return true;
}


function confirmusersession(initialuserid){
  ss_developer_key="123456-7qY6n7hLlCsdlhasdlhkdhklgFk=";
  var rs=session_getuser(false,'','userid');
  currentuserid=rs.getfieldbyname(1,"userid");
  if(currentuserid!=initialuserid) return false;
  return true;
}

See Also