Last active
May 18, 2016 11:13
-
-
Save roe3p/1da920bd1fc674b073af04d14826b2d9 to your computer and use it in GitHub Desktop.
A5 Authentication functions for a PhoneGap app (requires Alpha Apps Server)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//''------------------------- Authentication Functions | |
function authenticate(){ | |
var data = getLoginDetails(); | |
jQuery.ajax({ | |
type: "GET", | |
url: {dialog.object}.appVars.appURL + "ajax.a5w", | |
timeout: 30000, | |
error: function(x,t,m) { | |
debugger; | |
if(t=="timeout"){ | |
var msg = getMessage('AUTH_NOCONNECTION'); | |
message(msg, 'long', 'center'); | |
} | |
else | |
{ | |
message(t + ": " + m); | |
} | |
//alert("x="+ x + ", t=" + t + ", m=" + m); | |
}, | |
processData: false, | |
dataType: "script", | |
data: "_action=login&" + data, | |
//success: function() {alert("successFunction!");} | |
}); | |
} | |
function getLoginDetails() { | |
//Get entered username and password, prep for query | |
var UN = {dialog.Object}.getValue('Username'); | |
var PW = {dialog.Object}.getValue('Password'); | |
var query = "un=" + escape(UN) + "&pw=" + escape(PW); | |
return query; | |
} | |
function resp_auth(res, un, dn, co) { | |
//Called by ajax response from ajax.a5w following authentication call | |
if (typeof(res) == 'boolean') { | |
dbg('resp_auth'); | |
//debugger; | |
if(res==true){ | |
//Authentication successful | |
{dialog.object}.appVars.userId = un; | |
{dialog.object}.appVars.displayName = dn; | |
{dialog.object}.appVars.country = co; | |
$('spanUser').innerHTML = ", " + dn; | |
sun = {dialog.object}.getValue('SEARCH_UserId'); | |
if (sun != un) {dialog.object}.setValue('SEARCH_UserId', un); | |
{dialog.object}.getControl('INCIDENTLIST').searchList({searchMode : 'auto'}); | |
{dialog.object}.setValue('Authenticated', true); | |
{dialog.object}.panelSetActive('PANEL_DETAILS',true); | |
populateUserDetails(); | |
//Check for latest version (silently) | |
//checkVersions(); | |
} else { | |
//Authentication failed | |
{dialog.object}.appVars.userId = ''; | |
{dialog.object}.appVars.displayName = ''; | |
{dialog.object}.setValue('Authenticated', false); | |
var msg = getMessage('AUTH_INCORRECT'); | |
message(msg, 'long', 'center'); | |
//alert('Login failed'); | |
} | |
} | |
} | |
function logout(){ | |
{dialog.object}.setValue('Authenticated',false,false); | |
if({dialog.object}.appVars.testing == false) { | |
{dialog.object}.setValue('Username','',false); | |
{dialog.object}.setValue('Password','',false); | |
} | |
populateUserDetails(); | |
{dialog.object}.panelSetActive('PANEL_LOGIN',true); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment