]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
move redirect-to-openid code to OpenID plugin
authorEvan Prodromou <evan@controlyourself.ca>
Tue, 4 Aug 2009 17:17:43 +0000 (13:17 -0400)
committerEvan Prodromou <evan@controlyourself.ca>
Tue, 4 Aug 2009 17:17:43 +0000 (13:17 -0400)
classes/User.php
lib/settingsaction.php
plugins/OpenID/OpenIDPlugin.php
plugins/OpenID/User_openid.php

index bea47a3b058c8b70e74230ab5bce6c1b27667517..104dfbacb7888b82d26a4760e9488d7f1ea16c15 100644 (file)
@@ -670,17 +670,6 @@ class User extends Memcached_DataObject
         return $profile;
     }
 
-    function hasOpenID()
-    {
-        $oid = new User_openid();
-
-        $oid->user_id = $this->id;
-
-        $cnt = $oid->find();
-
-        return ($cnt > 0);
-    }
-
     function getDesign()
     {
         return Design::staticGet('id', $this->design_id);
index 4cf9b80c4a59e09f166b6e12a038408c5e7689a0..a923a98b2dd9862a6125973714d6bec9fb1e4862 100644 (file)
@@ -78,11 +78,7 @@ class SettingsAction extends CurrentUserDesignAction
             common_set_returnto($this->selfUrl());
             $user = common_current_user();
             if (Event::handle('RedirectToLogin', array($this, $user))) {
-                if ($user->hasOpenID()) {
-                    common_redirect(common_local_url('openidlogin'), 303);
-                } else {
-                    common_redirect(common_local_url('login'), 303);
-                }
+                common_redirect(common_local_url('login'), 303);
             }
         } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $this->handlePost();
index a395f910772bfb3eca78eb555fcf79491c5d6493..ec261d7f7f8eddb792a1ba7ca1f819a444e6671e 100644 (file)
@@ -156,4 +156,19 @@ class OpenIDPlugin extends Plugin
         $action->element('meta', array('http-equiv' => 'X-XRDS-Location',
                                        'content' => common_local_url('publicxrds')));
     }
+
+    /**
+     * Redirect to OpenID login if they have an OpenID
+     *
+     * @return boolean whether to continue
+     */
+
+    function onRedirectToLogin($action, $user)
+    {
+        if (!empty($user) && User_openid::hasOpenID($user->id)) {
+            common_redirect(common_local_url('openidlogin'), 303);
+            return false;
+        }
+        return true;
+    }
 }
index f4fda1c72e48985e09cc0657994cf42a4377c446..338e0f6e92c441990e30f2a9af672e06dddc645e 100644 (file)
@@ -4,7 +4,7 @@
  */
 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
 
-class User_openid extends Memcached_DataObject 
+class User_openid extends Memcached_DataObject
 {
     ###START_AUTOCODE
     /* the code below is auto generated do not remove the above tag */
@@ -22,4 +22,15 @@ class User_openid extends Memcached_DataObject
 
     /* the code above is auto generated do not remove the tag below */
     ###END_AUTOCODE
+
+    static function hasOpenID($user_id)
+    {
+        $oid = new User_openid();
+
+        $oid->user_id = $user_id;
+
+        $cnt = $oid->find();
+
+        return ($cnt > 0);
+    }
 }