]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Work in progress on fixing auth... looks like the iframe doesn't work though. Sigh.
authorBrion Vibber <brion@pobox.com>
Mon, 27 Sep 2010 19:24:10 +0000 (12:24 -0700)
committerBrion Vibber <brion@pobox.com>
Tue, 28 Sep 2010 14:44:25 +0000 (07:44 -0700)
plugins/YammerImport/actions/yammeradminpanel.php
plugins/YammerImport/lib/yammerauthinitform.php
plugins/YammerImport/lib/yammerauthverifyform.php
plugins/YammerImport/lib/yammerrunner.php
plugins/YammerImport/scripts/yammer-import.php

index 56e721d03c6766668c6a303583fffb468e02f6d1..71651cdf5667050ce8738979375f517ab7df1a67 100644 (file)
@@ -33,6 +33,8 @@ if (!defined('STATUSNET')) {
 
 class YammeradminpanelAction extends AdminPanelAction
 {
+    private $runner;
+
     /**
      * Returns the page title
      *
@@ -59,23 +61,29 @@ class YammeradminpanelAction extends AdminPanelAction
 
         $this->init_auth = $this->trimmed('init_auth');
         $this->verify_token = $this->trimmed('verify_token');
+        $this->runner = YammerRunner::init();
 
         return $ok;
     }
 
     function handle($args)
     {
-        if ($this->init_auth) {
-            $url = $runner->requestAuth();
-            $form = new YammerAuthVerifyForm($this, $url);
-            return $this->showAjaxForm($form);
-        } else if ($this->verify_token) {
-            $runner->saveAuthToken($this->verify_token);
-            $form = new YammerAuthProgressForm();
-            return $this->showAjaxForm($form);
+        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+            $this->checkSessionToken();
+            if ($this->init_auth) {
+                $url = $this->runner->requestAuth();
+                $form = new YammerAuthVerifyForm($this, $this->runner);
+                return $this->showAjaxForm($form);
+            } else if ($this->verify_token) {
+                $this->runner->saveAuthToken($this->verify_token);
+                $form = new YammerAuthProgressForm();
+                return $this->showAjaxForm($form);
+            } else {
+                throw new ClientException('Invalid POST');
+            }
+        } else {
+            return parent::handle($args);
         }
-
-        return parent::handle($args);
     }
 
     function showAjaxForm($form)
@@ -99,18 +107,16 @@ class YammeradminpanelAction extends AdminPanelAction
     {
         $this->elementStart('fieldset');
 
-        $runner = YammerRunner::init();
-
-        switch($runner->state())
+        switch($this->runner->state())
         {
             case 'init':
-                $form = new YammerAuthInitForm($this);
+                $form = new YammerAuthInitForm($this, $this->runner);
                 break;
             case 'requesting-auth':
-                $form = new YammerAuthVerifyForm($this, $runner);
+                $form = new YammerAuthVerifyForm($this, $this->runner);
                 break;
             default:
-                $form = new YammerProgressForm($this, $runner);
+                $form = new YammerProgressForm($this, $this->runner);
         }
         $form->show();
 
index 559ec4e7cc0e9831fe27efde208ee72115519047..5a83a06c2132f7c217d3b775b649585797b0c8b1 100644 (file)
@@ -56,6 +56,7 @@ class YammerAuthInitForm extends Form
 
     function formData()
     {
+        $this->out->hidden('init_auth', '1');
     }
 
     /**
index 488b5b8d1f143a8ff732ea476ae78f3b2b35d44c..dc9d2ce1b205d6dd63fee8a63bfa1d2a17e31814 100644 (file)
@@ -2,12 +2,12 @@
 
 class YammerAuthVerifyForm extends Form
 {
-    private $verify_url;
+    private $runner;
 
-    function __construct($out, $auth_url)
+    function __construct($out, YammerRunner $runner)
     {
         parent::__construct($out);
-        $this->verify_url = $auth_url;
+        $this->runner = $runner;
     }
 
     /**
@@ -64,6 +64,9 @@ class YammerAuthVerifyForm extends Form
 
     function formData()
     {
+        $this->out->input('verify_token', _m('Verification code:'), '', _m("Click through and paste the code it gives you below..."));
+        $this->out->element('iframe', array('id' => 'yammer-oauth',
+                                            'src' => $this->runner->getAuthUrl()));
     }
 
     /**
@@ -74,9 +77,6 @@ class YammerAuthVerifyForm extends Form
 
     function formActions()
     {
-        $this->out->input('verify-code', _m('Verification code:'), '', _m("Click through and paste the code it gives you below..."));
         $this->out->submit('submit', _m('Verify code'), 'submit', null, _m('Verification code'));
-        $this->element('iframe', array('id' => 'yammer-oauth',
-                                       'src' => $this->auth_url));
     }
 }
index e0aadff2c3e49dc033355119a7ae5f2813586b55..aee6b17e153a84ef32169b087e03ffecb35f27ed 100644 (file)
@@ -123,7 +123,7 @@ class YammerRunner
     public function requestAuth()
     {
         if ($this->state->state != 'init') {
-            throw ServerError("Cannot request Yammer auth; already there!");
+            throw new ServerException("Cannot request Yammer auth; already there!");
         }
 
         $data = $this->client->requestToken();
@@ -135,7 +135,22 @@ class YammerRunner
         $this->state->modified = common_sql_now();
         $this->state->update($old);
 
-        return $this->client->authorizeUrl($this->state->oauth_token);
+        return $this->getAuthUrl();
+    }
+
+    /**
+     * When already in requesting-auth state, grab the URL to send the user to
+     * to complete OAuth setup.
+     *
+     * @return string URL
+     */
+    function getAuthUrl()
+    {
+        if ($this->state() == 'requesting-auth') {
+            return $this->client->authorizeUrl($this->state->oauth_token);
+        } else {
+            throw new ServerException('Cannot get Yammer auth URL when not in requesting-auth state!');
+        }
     }
 
     /**
@@ -152,7 +167,7 @@ class YammerRunner
     public function saveAuthToken($verifier)
     {
         if ($this->state->state != 'requesting-auth') {
-            throw ServerError("Cannot save auth token in Yammer import state {$this->state->state}");
+            throw new ServerException("Cannot save auth token in Yammer import state {$this->state->state}");
         }
 
         $data = $this->client->accessToken($verifier);
index 1491cfd308c9b0596309ffd38312aa5fcaed2673..b4aa921e50cd2a5dda62b380bfb3a08503a105a4 100644 (file)
@@ -16,6 +16,8 @@ $runner = YammerRunner::init();
 if (have_option('reset')) {
     echo "Resetting Yammer import state...\n";
     $runner->reset();
+    echo "done.\n";
+    exit(0);
 }
 
 switch ($runner->state())