We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 4b0cf99e authored by Evan Prodromou's avatar Evan Prodromou

Convert use of common_server_error and common_user_error to methods on Action

parent eaa81d25
...@@ -38,7 +38,7 @@ class AccesstokenAction extends Action ...@@ -38,7 +38,7 @@ class AccesstokenAction extends Action
common_debug('printing the access token', __FILE__); common_debug('printing the access token', __FILE__);
print $token; print $token;
} catch (OAuthException $e) { } catch (OAuthException $e) {
common_server_error($e->getMessage()); $this->serverError($e->getMessage());
} }
} }
} }
...@@ -33,14 +33,14 @@ class AllAction extends StreamAction ...@@ -33,14 +33,14 @@ class AllAction extends StreamAction
$user = User::staticGet('nickname', $nickname); $user = User::staticGet('nickname', $nickname);
if (!$user) { if (!$user) {
$this->client_error(_('No such user.')); $this->clientError(_('No such user.'));
return; return;
} }
$profile = $user->getProfile(); $profile = $user->getProfile();
if (!$profile) { if (!$profile) {
common_server_error(_('User has no profile.')); $this->serverError(_('User has no profile.'));
return; return;
} }
......
...@@ -34,7 +34,7 @@ class AllrssAction extends Rss10Action ...@@ -34,7 +34,7 @@ class AllrssAction extends Rss10Action
$this->user = User::staticGet('nickname', $nickname); $this->user = User::staticGet('nickname', $nickname);
if (!$this->user) { if (!$this->user) {
common_user_error(_('No such user.')); $this->clientError(_('No such user.'));
return false; return false;
} else { } else {
return true; return true;
......
...@@ -103,10 +103,10 @@ class ApiAction extends Action ...@@ -103,10 +103,10 @@ class ApiAction extends Action
call_user_func(array($action_obj, $this->api_method), $_REQUEST, $apidata); call_user_func(array($action_obj, $this->api_method), $_REQUEST, $apidata);
} else { } else {
common_user_error("API method not found!", $code=404); $this->clientError("API method not found!", $code=404);
} }
} else { } else {
common_user_error("API method not found!", $code=404); $this->clientError("API method not found!", $code=404);
} }
} }
......
...@@ -26,28 +26,28 @@ class AvatarbynicknameAction extends Action ...@@ -26,28 +26,28 @@ class AvatarbynicknameAction extends Action
parent::handle($args); parent::handle($args);
$nickname = $this->trimmed('nickname'); $nickname = $this->trimmed('nickname');
if (!$nickname) { if (!$nickname) {
$this->client_error(_('No nickname.')); $this->clientError(_('No nickname.'));
return; return;
} }
$size = $this->trimmed('size'); $size = $this->trimmed('size');
if (!$size) { if (!$size) {
$this->client_error(_('No size.')); $this->clientError(_('No size.'));
return; return;
} }
$size = strtolower($size); $size = strtolower($size);
if (!in_array($size, array('original', '96', '48', '24'))) { if (!in_array($size, array('original', '96', '48', '24'))) {
$this->client_error(_('Invalid size.')); $this->clientError(_('Invalid size.'));
return; return;
} }
$user = User::staticGet('nickname', $nickname); $user = User::staticGet('nickname', $nickname);
if (!$user) { if (!$user) {
$this->client_error(_('No such user.')); $this->clientError(_('No such user.'));
return; return;
} }
$profile = $user->getProfile(); $profile = $user->getProfile();
if (!$profile) { if (!$profile) {
$this->client_error(_('User has no profile.')); $this->clientError(_('User has no profile.'));
return; return;
} }
if ($size == 'original') { if ($size == 'original') {
......
...@@ -30,28 +30,28 @@ class BlockAction extends Action ...@@ -30,28 +30,28 @@ class BlockAction extends Action
parent::prepare($args); parent::prepare($args);
if (!common_logged_in()) { if (!common_logged_in()) {
$this->client_error(_('Not logged in.')); $this->clientError(_('Not logged in.'));
return false; return false;
} }
$token = $this->trimmed('token'); $token = $this->trimmed('token');
if (!$token || $token != common_session_token()) { if (!$token || $token != common_session_token()) {
$this->client_error(_('There was a problem with your session token. Try again, please.')); $this->clientError(_('There was a problem with your session token. Try again, please.'));
return; return;
} }
$id = $this->trimmed('blockto'); $id = $this->trimmed('blockto');
if (!$id) { if (!$id) {
$this->client_error(_('No profile specified.')); $this->clientError(_('No profile specified.'));
return false; return false;
} }
$this->profile = Profile::staticGet('id', $id); $this->profile = Profile::staticGet('id', $id);
if (!$this->profile) { if (!$this->profile) {
$this->client_error(_('No profile with that ID.')); $this->clientError(_('No profile with that ID.'));
return false; return false;
} }
...@@ -119,14 +119,14 @@ class BlockAction extends Action ...@@ -119,14 +119,14 @@ class BlockAction extends Action
$cur = common_current_user(); $cur = common_current_user();
if ($cur->hasBlocked($this->profile)) { if ($cur->hasBlocked($this->profile)) {
$this->client_error(_('You have already blocked this user.')); $this->clientError(_('You have already blocked this user.'));
return; return;
} }
$result = $cur->block($this->profile); $result = $cur->block($this->profile);
if (!$result) { if (!$result) {
$this->server_error(_('Failed to save block information.')); $this->serverError(_('Failed to save block information.'));
return; return;
} }
......
...@@ -32,26 +32,26 @@ class ConfirmaddressAction extends Action ...@@ -32,26 +32,26 @@ class ConfirmaddressAction extends Action
} }
$code = $this->trimmed('code'); $code = $this->trimmed('code');
if (!$code) { if (!$code) {
$this->client_error(_('No confirmation code.')); $this->clientError(_('No confirmation code.'));
return; return;
} }
$confirm = Confirm_address::staticGet('code', $code); $confirm = Confirm_address::staticGet('code', $code);
if (!$confirm) { if (!$confirm) {
$this->client_error(_('Confirmation code not found.')); $this->clientError(_('Confirmation code not found.'));
return; return;
} }
$cur = common_current_user(); $cur = common_current_user();
if ($cur->id != $confirm->user_id) { if ($cur->id != $confirm->user_id) {
$this->client_error(_('That confirmation code is not for you!')); $this->clientError(_('That confirmation code is not for you!'));
return; return;
} }
$type = $confirm->address_type; $type = $confirm->address_type;
if (!in_array($type, array('email', 'jabber', 'sms'))) { if (!in_array($type, array('email', 'jabber', 'sms'))) {
$this->server_error(sprintf(_('Unrecognized address type %s'), $type)); $this->serverError(sprintf(_('Unrecognized address type %s'), $type));
return; return;
} }
if ($cur->$type == $confirm->address) { if ($cur->$type == $confirm->address) {
$this->client_error(_('That address has already been confirmed.')); $this->clientError(_('That address has already been confirmed.'));
return; return;
} }
...@@ -71,7 +71,7 @@ class ConfirmaddressAction extends Action ...@@ -71,7 +71,7 @@ class ConfirmaddressAction extends Action
if (!$result) { if (!$result) {
common_log_db_error($cur, 'UPDATE', __FILE__); common_log_db_error($cur, 'UPDATE', __FILE__);
$this->server_error(_('Couldn\'t update user.')); $this->serverError(_('Couldn\'t update user.'));
return; return;
} }
...@@ -83,7 +83,7 @@ class ConfirmaddressAction extends Action ...@@ -83,7 +83,7 @@ class ConfirmaddressAction extends Action
if (!$result) { if (!$result) {
common_log_db_error($confirm, 'DELETE', __FILE__); common_log_db_error($confirm, 'DELETE', __FILE__);
$this->server_error(_('Couldn\'t delete email confirmation.')); $this->serverError(_('Couldn\'t delete email confirmation.'));
return; return;
} }
......
...@@ -24,7 +24,7 @@ class DeleteprofileAction extends Action ...@@ -24,7 +24,7 @@ class DeleteprofileAction extends Action
function handle($args) function handle($args)
{ {
parent::handle($args); parent::handle($args);
$this->server_error(_('Code not yet ready.')); $this->serverError(_('Code not yet ready.'));
return; return;
if ('POST' === $_SERVER['REQUEST_METHOD']) { if ('POST' === $_SERVER['REQUEST_METHOD']) {
$this->handle_post(); $this->handle_post();
......
...@@ -28,7 +28,7 @@ class DisfavorAction extends Action ...@@ -28,7 +28,7 @@ class DisfavorAction extends Action
parent::handle($args); parent::handle($args);
if (!common_logged_in()) { if (!common_logged_in()) {
common_user_error(_('Not logged in.')); $this->clientError(_('Not logged in.'));
return; return;
} }
...@@ -46,7 +46,7 @@ class DisfavorAction extends Action ...@@ -46,7 +46,7 @@ class DisfavorAction extends Action
$token = $this->trimmed('token-'.$notice->id); $token = $this->trimmed('token-'.$notice->id);
if (!$token || $token != common_session_token()) { if (!$token || $token != common_session_token()) {
$this->client_error(_("There was a problem with your session token. Try again, please.")); $this->clientError(_("There was a problem with your session token. Try again, please."));
return; return;
} }
...@@ -54,7 +54,7 @@ class DisfavorAction extends Action ...@@ -54,7 +54,7 @@ class DisfavorAction extends Action
$fave->user_id = $this->id; $fave->user_id = $this->id;
$fave->notice_id = $notice->id; $fave->notice_id = $notice->id;
if (!$fave->find(true)) { if (!$fave->find(true)) {
$this->client_error(_('This notice is not a favorite!')); $this->clientError(_('This notice is not a favorite!'));
return; return;
} }
...@@ -62,7 +62,7 @@ class DisfavorAction extends Action ...@@ -62,7 +62,7 @@ class DisfavorAction extends Action
if (!$result) { if (!$result) {
common_log_db_error($fave, 'DELETE', __FILE__); common_log_db_error($fave, 'DELETE', __FILE__);
$this->server_error(_('Could not delete favorite.')); $this->serverError(_('Could not delete favorite.'));
return; return;
} }
......
...@@ -28,7 +28,7 @@ class DocAction extends Action ...@@ -28,7 +28,7 @@ class DocAction extends Action
$title = $this->trimmed('title'); $title = $this->trimmed('title');
$filename = INSTALLDIR.'/doc/'.$title; $filename = INSTALLDIR.'/doc/'.$title;
if (!file_exists($filename)) { if (!file_exists($filename)) {
common_user_error(_('No such document.')); $this->clientError(_('No such document.'));
return; return;
} }
$c = file_get_contents($filename); $c = file_get_contents($filename);
......
...@@ -182,7 +182,7 @@ class EmailsettingsAction extends SettingsAction ...@@ -182,7 +182,7 @@ class EmailsettingsAction extends SettingsAction
if ($result === false) { if ($result === false) {
common_log_db_error($user, 'UPDATE', __FILE__); common_log_db_error($user, 'UPDATE', __FILE__);
common_server_error(_('Couldn\'t update user.')); $this->serverError(_('Couldn\'t update user.'));
return; return;
} }
...@@ -232,7 +232,7 @@ class EmailsettingsAction extends SettingsAction ...@@ -232,7 +232,7 @@ class EmailsettingsAction extends SettingsAction
if ($result === false) { if ($result === false) {
common_log_db_error($confirm, 'INSERT', __FILE__); common_log_db_error($confirm, 'INSERT', __FILE__);
common_server_error(_('Couldn\'t insert confirmation code.')); $this->serverError(_('Couldn\'t insert confirmation code.'));
return; return;
} }
...@@ -260,7 +260,7 @@ class EmailsettingsAction extends SettingsAction ...@@ -260,7 +260,7 @@ class EmailsettingsAction extends SettingsAction
if (!$result) { if (!$result) {
common_log_db_error($confirm, 'DELETE', __FILE__); common_log_db_error($confirm, 'DELETE', __FILE__);
$this->server_error(_('Couldn\'t delete email confirmation.')); $this->serverError(_('Couldn\'t delete email confirmation.'));
return; return;
} }
...@@ -286,7 +286,7 @@ class EmailsettingsAction extends SettingsAction ...@@ -286,7 +286,7 @@ class EmailsettingsAction extends SettingsAction
$result = $user->updateKeys($original); $result = $user->updateKeys($original);
if (!$result) { if (!$result) {
common_log_db_error($user, 'UPDATE', __FILE__); common_log_db_error($user, 'UPDATE', __FILE__);
common_server_error(_('Couldn\'t update user.')); $this->serverError(_('Couldn\'t update user.'));
return; return;
} }
$user->query('COMMIT'); $user->query('COMMIT');
...@@ -308,7 +308,7 @@ class EmailsettingsAction extends SettingsAction ...@@ -308,7 +308,7 @@ class EmailsettingsAction extends SettingsAction
if (!$user->updateKeys($orig)) { if (!$user->updateKeys($orig)) {
common_log_db_error($user, 'UPDATE', __FILE__); common_log_db_error($user, 'UPDATE', __FILE__);
$this->server_error(_("Couldn't update user record.")); $this->serverError(_("Couldn't update user record."));
} }
$this->show_form(_('Incoming email address removed.'), true); $this->show_form(_('Incoming email address removed.'), true);
...@@ -323,7 +323,7 @@ class EmailsettingsAction extends SettingsAction ...@@ -323,7 +323,7 @@ class EmailsettingsAction extends SettingsAction
if (!$user->updateKeys($orig)) { if (!$user->updateKeys($orig)) {
common_log_db_error($user, 'UPDATE', __FILE__); common_log_db_error($user, 'UPDATE', __FILE__);
$this->server_error(_("Couldn't update user record.")); $this->serverError(_("Couldn't update user record."));
} }
$this->show_form(_('New incoming email address added.'), true); $this->show_form(_('New incoming email address added.'), true);
......
...@@ -53,7 +53,7 @@ class FacebookremoveAction extends FacebookAction ...@@ -53,7 +53,7 @@ class FacebookremoveAction extends FacebookAction
if (!$result) { if (!$result) {
common_log_db_error($flink, 'DELETE', __FILE__); common_log_db_error($flink, 'DELETE', __FILE__);
common_server_error(_('Couldn\'t remove Facebook user.')); $this->serverError(_('Couldn\'t remove Facebook user.'));
return; return;
} }
......
...@@ -29,7 +29,7 @@ class FavorAction extends Action ...@@ -29,7 +29,7 @@ class FavorAction extends Action
parent::handle($args); parent::handle($args);
if (!common_logged_in()) { if (!common_logged_in()) {
common_user_error(_('Not logged in.')); $this->clientError(_('Not logged in.'));
return; return;
} }
...@@ -48,19 +48,19 @@ class FavorAction extends Action ...@@ -48,19 +48,19 @@ class FavorAction extends Action
$token = $this->trimmed('token-'.$notice->id); $token = $this->trimmed('token-'.$notice->id);
if (!$token || $token != common_session_token()) { if (!$token || $token != common_session_token()) {
$this->client_error(_("There was a problem with your session token. Try again, please.")); $this->clientError(_("There was a problem with your session token. Try again, please."));
return; return;
} }
if ($user->hasFave($notice)) { if ($user->hasFave($notice)) {
$this->client_error(_('This notice is already a favorite!')); $this->clientError(_('This notice is already a favorite!'));
return; return;
} }
$fave = Fave::addNew($user, $notice); $fave = Fave::addNew($user, $notice);
if (!$fave) { if (!$fave) {
$this->server_error(_('Could not create favorite.')); $this->serverError(_('Could not create favorite.'));
return; return;
} }
......
...@@ -34,7 +34,7 @@ class FavoritesrssAction extends Rss10Action ...@@ -34,7 +34,7 @@ class FavoritesrssAction extends Rss10Action
$this->user = User::staticGet('nickname', $nickname); $this->user = User::staticGet('nickname', $nickname);
if (!$this->user) { if (!$this->user) {
common_user_error(_('No such user.')); $this->clientError(_('No such user.'));
return false; return false;
} else { } else {
return true; return true;
......
...@@ -28,7 +28,7 @@ class FinishaddopenidAction extends Action ...@@ -28,7 +28,7 @@ class FinishaddopenidAction extends Action
{ {
parent::handle($args); parent::handle($args);
if (!common_logged_in()) { if (!common_logged_in()) {
common_user_error(_('Not logged in.')); $this->clientError(_('Not logged in.'));
} else { } else {
$this->try_login(); $this->try_login();
} }
......
...@@ -28,7 +28,7 @@ class FinishopenidloginAction extends Action ...@@ -28,7 +28,7 @@ class FinishopenidloginAction extends Action
{ {
parent::handle($args); parent::handle($args);
if (common_logged_in()) { if (common_logged_in()) {
common_user_error(_('Already logged in.')); $this->clientError(_('Already logged in.'));
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') { } else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$token = $this->trimmed('token'); $token = $this->trimmed('token');
if (!$token || $token != common_session_token()) { if (!$token || $token != common_session_token()) {
...@@ -179,7 +179,7 @@ class FinishopenidloginAction extends Action ...@@ -179,7 +179,7 @@ class FinishopenidloginAction extends Action
# FIXME: save invite code before redirect, and check here # FIXME: save invite code before redirect, and check here
if (common_config('site', 'closed') || common_config('site', 'inviteonly')) { if (common_config('site', 'closed') || common_config('site', 'inviteonly')) {
common_user_error(_('Registration not allowed.')); $this->clientError(_('Registration not allowed.'));
return; return;
} }
...@@ -205,7 +205,7 @@ class FinishopenidloginAction extends Action ...@@ -205,7 +205,7 @@ class FinishopenidloginAction extends Action
list($display, $canonical, $sreg) = $this->get_saved_values(); list($display, $canonical, $sreg) = $this->get_saved_values();
if (!$display || !$canonical) { if (!$display || !$canonical) {
common_server_error(_('Stored OpenID not found.')); $this->serverError(_('Stored OpenID not found.'));
return; return;
} }
...@@ -214,7 +214,7 @@ class FinishopenidloginAction extends Action ...@@ -214,7 +214,7 @@ class FinishopenidloginAction extends Action
$other = oid_get_user($canonical); $other = oid_get_user($canonical);
if ($other) { if ($other) {
common_server_error(_('Creating new account for OpenID that already has a user.')); $this->serverError(_('Creating new account for OpenID that already has a user.'));
return; return;
} }
...@@ -274,14 +274,14 @@ class FinishopenidloginAction extends Action ...@@ -274,14 +274,14 @@ class FinishopenidloginAction extends Action
list($display, $canonical, $sreg) = $this->get_saved_values(); list($display, $canonical, $sreg) = $this->get_saved_values();
if (!$display || !$canonical) { if (!$display || !$canonical) {
common_server_error(_('Stored OpenID not found.')); $this->serverError(_('Stored OpenID not found.'));
return; return;
} }
$result = oid_link_user($user->id, $canonical, $display); $result = oid_link_user($user->id, $canonical, $display);
if (!$result) { if (!$result) {
common_server_error(_('Error connecting user to OpenID.')); $this->serverError(_('Error connecting user to OpenID.'));
return; return;
} }
......
...@@ -30,14 +30,14 @@ class FinishremotesubscribeAction extends Action ...@@ -30,14 +30,14 @@ class FinishremotesubscribeAction extends Action
parent::handle($args); parent::handle($args);