]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
needLogin renamed checkLogin and made a property
authorMikael Nordfeldth <mmn@hethane.se>
Mon, 2 Sep 2013 09:58:47 +0000 (11:58 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Mon, 2 Sep 2013 09:58:47 +0000 (11:58 +0200)
Action extended classes now can set 'needLogin' as a protected property,
which is defaulted to 'false'. However, FormAction defaults this to 'true'
because most of the form actions will require a current login to be valid.

NewgroupAction, NewmessageAction, NewnoticeAction are all affected by this
commit and in the future we will migrate each potential formaction to the
proper class parent tree. :)

actions/newgroup.php
actions/newmessage.php
actions/newnotice.php
lib/action.php
lib/formaction.php

index d78683f705b77963810c709607249f1cacd9d223..dd264ce055da25be0c62e97e2979f34a466bb52d 100644 (file)
@@ -24,6 +24,7 @@
  * @author    Evan Prodromou <evan@status.net>
  * @author    Sarven Capadisli <csarven@status.net>
  * @copyright 2008-2009 StatusNet, Inc.
+ * @copyright 2013 Free Software Foundation, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
@@ -58,11 +59,6 @@ class NewgroupAction extends FormAction
     {
         parent::prepare($args);
 
-        if (!common_logged_in()) {
-            // TRANS: Client error displayed trying to create a group while not logged in.
-            $this->clientError(_('You must be logged in to create a group.'), 403);
-        }
-
         // $this->scoped is the current user profile
         if (!$this->scoped->hasRight(Right::CREATEGROUP)) {
             // TRANS: Client exception thrown when a user tries to create a group while banned.
index 4ff9d8e9e93f627b96e060026f914095b97d1f63..5d097188fc0b3af822186dbc8afd92fc4704f547 100644 (file)
  * @author    Zach Copley <zach@status.net>
  * @author    Sarven Capadisli <csarven@status.net>
  * @copyright 2008-2009 StatusNet, Inc.
+ * @copyright 2013 Free Software Foundation, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET') && !defined('LACONICA')) {
+if (!defined('STATUSNET')) {
     exit(1);
 }
 
@@ -77,10 +78,6 @@ class NewmessageAction extends FormAction
     {
         parent::prepare($args);
 
-        if (!common_logged_in()) {
-            $this->needLogin();
-        }
-
         $user = $this->scoped->getUser();
 
         $this->content = $this->trimmed('content');
index ad06c7e266b99cd11e2cf4c5934baf2773d760d8..7e2de90cf8b81d654ec2b1a52ba142848322d451 100644 (file)
@@ -63,31 +63,6 @@ class NewnoticeAction extends FormAction
         return _m('TITLE','New notice');
     }
 
-    /**
-     * Handle input, produce output
-     *
-     * Switches based on GET or POST method. On GET, shows a form
-     * for posting a notice. On POST, saves the results of that form.
-     *
-     * Results may be a full page, or just a single notice list item,
-     * depending on whether AJAX was requested.
-     *
-     * @param array $args $_REQUEST contents
-     *
-     * @return void
-     */
-    protected function prepare(array $args=array())
-    {
-        parent::prepare($args);
-
-        if (!common_logged_in()) {
-            // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
-            $this->clientError(_('Not logged in.'), 403);
-        }
-
-        return true;
-    }
-
     /**
      * This handlePost saves a new notice, based on arguments
      *
index 09a15a4435a80d41985d64d2c1bc86347ebd7f41..d3c25be19eb5bcc5d76a04f6d2d8f60dbe44034b 100644 (file)
@@ -62,6 +62,7 @@ class Action extends HTMLOutputter // lawsuit
     protected $action = false;
     protected $ajax   = false;
     protected $menus  = true;
+    protected $needLogin = false;
 
     // The currently scoped profile
     protected $scoped = null;
@@ -142,6 +143,10 @@ class Action extends HTMLOutputter // lawsuit
             StatusNet::setAjax(true);
         }
 
+        if ($this->needLogin) {
+            $this->checkLogin(); // if not logged in, this redirs/excepts
+        }
+
         $this->scoped = Profile::current();
 
         return true;
@@ -1377,15 +1382,25 @@ class Action extends HTMLOutputter // lawsuit
     }
 
     /**
-     * Redirect to login page (with returnto)
+     * If not logged in, take appropriate action (redir or exception)
      *
-     * @return nothing
+     * @param boolean $redir Redirect to login if not logged in
+     *
+     * @return boolean true if logged in (never returns if not)
      */
-    function needLogin()
+    public function checkLogin($redir=true)
     {
-        // this might be updated with a login check before redirecting
-        common_set_returnto($_SERVER['REQUEST_URI']);
-        common_redirect(common_local_url('login'));
+        if (common_logged_in()) {
+            return true;
+        }
+
+        if ($redir==true) {
+            common_set_returnto($_SERVER['REQUEST_URI']);
+            common_redirect(common_local_url('login'));
+        }
+
+        // TRANS: Error message displayed when trying to perform an action that requires a logged in user.
+        $this->clientError(_('Not logged in.'), 403);
     }
 
     /**
index fda66007d87ba829df7c894dca3efcd674ea88f3..8f300d3a63053c18e9f168e89219d2bb921066a7 100644 (file)
@@ -45,6 +45,7 @@ class FormAction extends Action
 {
     protected $form = null;
     protected $type = null;
+    protected $needLogin = true;
 
     protected function prepare(array $args=array()) {
         parent::prepare($args);