Move the one-off setting of the access token to p2 startup
authorAndy Allan <gravitystorm@gmail.com>
Tue, 19 Oct 2010 10:10:32 +0000 (10:10 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Tue, 19 Oct 2010 10:10:32 +0000 (10:10 +0000)
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/potlatch2/save/SaveManager.as
potlatch2.mxml

index a73f876..9047c5e 100755 (executable)
@@ -361,12 +361,14 @@ package net.systemeD.halcyon.connection {
            }
            
            public function setAuthToken(id:Object):void {}
+        public function setAccessToken(key:String, secret:String):void {}
            public function createChangeset(tags:Object):void {}
                public function closeChangeset():void {}
            public function uploadChanges():void {}
         public function fetchUserTraces(refresh:Boolean=false):void {}
         public function fetchTrace(id:Number, callback:Function):void {}
-        public function getAccessToken(data:Object):OAuthToken { return null; } //todo make private and remove import org.ioshtan etc
+        public function getAccessToken():OAuthToken { return null; } //todo make private and remove import org.ioshtan etc
+        public function hasAccessToken():Boolean { return false; }
     }
 
 }
index 28a3577..25b69aa 100644 (file)
@@ -56,18 +56,23 @@ package net.systemeD.halcyon.connection {
                authToken = OAuthToken(id);
            }
 
-        /* Get the stored access token, or try setting it up from loader params or passed SharedObject */
+        override public function hasAccessToken():Boolean {
+            return !(getAccessToken() == null);
+        }
+
+        override public function setAccessToken(key:String, secret:String):void {
+            if(key && secret) {
+              authToken = new OAuthToken(key, secret);
+            }
+        }
+
+        /* Get the stored access token, or try setting it up from loader params */
         /* todo: make this private */
-        override public function getAccessToken(data:Object):OAuthToken {
+        override public function getAccessToken():OAuthToken {
             if (authToken == null) {
               var key:String = getParam("oauth_token", null);
               var secret:String = getParam("oauth_token_secret", null);
 
-              if ( key == null || secret == null ) {
-                  key = data["oauth_token"];
-                  secret = data["oauth_token_secret"];
-              }
-
               if ( key != null && secret != null ) {
                   authToken = new OAuthToken(key, secret);
               }
index 7536302..c488956 100644 (file)
@@ -30,7 +30,7 @@ package net.systemeD.potlatch2.save {
         private function save(callback:Function):void {
             var conn:Connection = Connection.getConnectionInstance();
             if ( accessToken == null )
-                accessToken = conn.getAccessToken(SharedObject.getLocal("access_token").data);
+                accessToken = conn.getAccessToken();
         
             if ( accessToken == null )
                 getNewToken(callback);
index 8622136..0f00d58 100755 (executable)
             conn.addEventListener(Connection.DATA_CLEAN, onDataClean);
                        conn.addEventListener(MapEvent.ERROR, onMapError);
 
+            // set the access token from saved cookie
+            var tokenObject:SharedObject = SharedObject.getLocal("access_token");
+            conn.setAccessToken(tokenObject.data["key"], tokenObject.data["secret"]);
+
                        // create GPS trackloader
                        trackLoader=new TrackLoader(theMap,conn.apiBase);