Skip to content

Instantly share code, notes, and snippets.

@jamierumbelow
Created April 23, 2009 18:58
Show Gist options
  • Save jamierumbelow/100692 to your computer and use it in GitHub Desktop.
Save jamierumbelow/100692 to your computer and use it in GitHub Desktop.
/*
Jitterbug
auth.js - basic authentication
by Jamie Rumbelow
Thanks for checking out the source!
Copyright (c)2009 JR and JG. Init.
*/
function auth() {
if ($SESSION) {
return true;
}
else {
if (widget.preferenceForKey('jitterbug_user')) {
var user = widget.preferenceForKey('jitterbug_user'),
pin = widget.preferenceForKey('jitterbug_pin'),
url = $api.url + "userAuthenticate" + "?" + obj2query({'id': user, 'pin': pin});
getJSONP(url, function(response){
$SESSION = response.session_id;
return true;
});
while ($SESSION == "") { }
}
else {
var url = $api.url + "userCreate";
getJSONP(url, function(response){
$SESSION = response.session_id;
widget.setPreferenceForKey(response.user_id, 'jitterbug_user');
widget.setPreferenceForKey(response.user_pin, 'jitterbug_pin');
return true;
});
while ($SESSION == "") { }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment