Actionscript - Cookies - Login, Get Person, Logout
Actionscript - Login for cookie, send cookie to get/person, logout
protected function button_clickHandler( event:MouseEvent ):void { //set up url var username:String = "sterling_archer@ikanow.com"; var hashedpassword:String = "WZRHGrsBESr8wYFZ9sx0tPURuZgG2lmzyvWpwXPKz8U%3D"; //don't forget to URLEncode your arguments var address:String = "http://infinite.ikanow.com/api/auth/login/" + username + "/" + hashedpassword; //send login request var httpService:HTTPService = new HTTPService(); httpService.addEventListener( ResultEvent.RESULT, httpResultHandler ); httpService.addEventListener( FaultEvent.FAULT, httpFaultHandler ); httpService.url = address; httpService.send(); } protected function httpResultHandler( event:ResultEvent ):void { //convert result json string to an as3 object using the as3corelib library //available at: https://github.com/mikechambers/as3corelib var jsonObject:Object = JSON.decode( event.result.toString(), true ); if ( jsonObject.response.success == true ) { //successfully logged in, cookies are automatically stored in flash so no need to handle them //send request for our person object (will print out in httpPersonResultHandler) var httpService:HTTPService = new HTTPService(); httpService.addEventListener( ResultEvent.RESULT, httpPersonResultHandler ); httpService.addEventListener( FaultEvent.FAULT, httpFaultHandler ); httpService.url = "http://infinite.ikanow.com/api/social/person/get"; httpService.send(); } } protected function httpPersonResultHandler( event:ResultEvent ):void { //just print out person result json Alert.show( event.result.toString() ); //logout var httpService:HTTPService = new HTTPService(); httpService.url = "http://infinite.ikanow.com/api/auth/logout"; httpService.send(); } protected function httpFaultHandler( event:FaultEvent ):void { Alert.show( "Http Request had an error: " + event.message ); }