diff --git a/actions/newgroup.php b/actions/newgroup.php index d78683f705..dd264ce055 100644 --- a/actions/newgroup.php +++ b/actions/newgroup.php @@ -24,6 +24,7 @@ * @author Evan Prodromou * @author Sarven Capadisli * @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. diff --git a/actions/newmessage.php b/actions/newmessage.php index 4ff9d8e9e9..5d097188fc 100644 --- a/actions/newmessage.php +++ b/actions/newmessage.php @@ -25,11 +25,12 @@ * @author Zach Copley * @author Sarven Capadisli * @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'); diff --git a/actions/newnotice.php b/actions/newnotice.php index ad06c7e266..7e2de90cf8 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -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 * diff --git a/lib/action.php b/lib/action.php index 09a15a4435..d3c25be19e 100644 --- a/lib/action.php +++ b/lib/action.php @@ -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); } /** diff --git a/lib/formaction.php b/lib/formaction.php index fda66007d8..8f300d3a63 100644 --- a/lib/formaction.php +++ b/lib/formaction.php @@ -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);