Add Remember Me option (on by default) for oath access key
authorDave Stubbs <osm@randomjunk.co.uk>
Sun, 2 May 2010 15:39:37 +0000 (15:39 +0000)
committerDave Stubbs <osm@randomjunk.co.uk>
Sun, 2 May 2010 15:39:37 +0000 (15:39 +0000)
net/systemeD/potlatch2/save/OAuthPanel.mxml
net/systemeD/potlatch2/save/SaveManager.as

index ea8d1e1fe4588b18c12d09c50bc22d04d87314c0..5f892117b013c05e15fb4c6580c3fc74158a7fd6 100644 (file)
@@ -4,7 +4,7 @@
        layout="vertical"
        horizontalAlign="center" title="Authorisation Required"
        creationComplete="getRequestToken()"
-       height="250">
+       height="290">
        
        <mx:ViewStack id="contentStack" width="100%" height="100%">
        
@@ -26,6 +26,9 @@
            <mx:Text styleName="failText" visible="false" id="deniedLabel">
              <mx:text><![CDATA[<b>Access was denied, please check, and try again</b>]]></mx:text>
            </mx:Text>
+           <mx:HBox width="100%" horizontalAlign="right">
+             <mx:CheckBox id="rememberMe" label="Remember authorisation" selected="true"/>
+           </mx:HBox>
          </mx:VBox>
        </mx:VBox>
        
             return _accessToken;
         }
         
+        public function get shouldRemember():Boolean {
+            return rememberMe.selected;
+        }
+        
         private function accessTokenError(event:IOErrorEvent):void {
             if ( lastHTTPStatus == 401 ) {
                 deniedLabel.htmlText = "<b>Access was denied, please check, and try again</b>";
index 18d97cd7ec1a78bcfa152b64a2202744f87ed596..d591d67b22d29cbe05cd6f991837dc488f16ab19 100644 (file)
@@ -1,6 +1,7 @@
 package net.systemeD.potlatch2.save {
 
     import flash.events.*;
+    import flash.net.*;
     import mx.managers.PopUpManager;
     import mx.core.Application;
     import net.systemeD.halcyon.connection.*;
@@ -33,6 +34,12 @@ package net.systemeD.potlatch2.save {
             var key:String = Connection.getParam("oauth_token", null);
             var secret:String = Connection.getParam("oauth_token_secret", null);
             
+            if ( key == null || secret == null ) {
+                var data:Object = SharedObject.getLocal("access_token", "/potlatch2.swf").data;
+                key = data["oauth_token"];
+                secret = data["oauth_token_secret"];
+            }
+            
             if ( key == null || secret == null )
                 return null;
             else    
@@ -56,6 +63,12 @@ package net.systemeD.potlatch2.save {
             
             var listener:Function = function(event:Event):void {
                 accessToken = oauthPanel.accessToken;
+                if ( oauthPanel.shouldRemember ) {
+                    var obj:SharedObject = SharedObject.getLocal("access_token", "/potlatch2.swf");
+                    obj.setProperty("oauth_token", accessToken.key);
+                    obj.setProperty("oauth_token_secret", accessToken.secret);
+                    obj.flush();
+                }
                 onCompletion();
             }
             oauthPanel.addEventListener(OAuthPanel.ACCESS_TOKEN_EVENT, listener);