X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=actions%2Fapiaccountupdatebackgroundcolor.php;h=1839d7ae24be0edc8e6c707b2c15bbbab35cb2e2;hb=8ad6b8809a8d452ee36de62b73c32cba849ee036;hp=230ff5b5854bbc199f45dae9ae192227a7694aef;hpb=34a6624452e8b7f60b40181441c6ea2c8158379a;p=quix0rs-gnu-social.git
diff --git a/actions/apiaccountupdatebackgroundcolor.php b/actions/apiaccountupdatebackgroundcolor.php
index 230ff5b585..1839d7ae24 100644
--- a/actions/apiaccountupdatebackgroundcolor.php
+++ b/actions/apiaccountupdatebackgroundcolor.php
@@ -20,7 +20,7 @@
* along with this program. If not, see .
*
* @category API
- * @package GNUSocial
+ * @package GNUsocial
* @author Hannes Mannerheim
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://www.gnu.org/software/social/
@@ -32,6 +32,8 @@ class ApiAccountUpdateBackgroundColorAction extends ApiAuthAction
{
var $backgroundcolor = null;
+ protected $needPost = true;
+
/**
* Take arguments for running
*
@@ -39,11 +41,13 @@ class ApiAccountUpdateBackgroundColorAction extends ApiAuthAction
*
* @return boolean success flag
*/
- function prepare($args)
+ protected function prepare(array $args=array())
{
parent::prepare($args);
- $this->user = $this->auth_user;
+ if ($this->format !== 'json') {
+ $this->clientError('This method currently only serves JSON.', 415);
+ }
$this->backgroundcolor = $this->trimmed('backgroundcolor');
return true;
@@ -59,40 +63,23 @@ class ApiAccountUpdateBackgroundColorAction extends ApiAuthAction
*
* @return void
*/
- function handle($args)
+ protected function handle()
{
- parent::handle($args);
-
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- $this->clientError(
- _('This method requires a POST.'),
- 400, $this->format
- );
- return;
+ parent::handle();
+
+ $validhex = preg_match('/^[a-f0-9]{6}$/i',$this->backgroundcolor);
+ if ($validhex === false || $validhex == 0) {
+ $this->clientError(_('Not a valid hex color.'), 400);
}
-
- $validhex = preg_match('/^[a-f0-9]{6}$/i',$this->backgroundcolor);
- if($validhex === false || $validhex == 0) {
- $this->clientError(_('Not a valid hex color.'),404,'json');
- return;
- }
-
- // save the new color
- $original = clone($this->user);
- $this->user->backgroundcolor = $this->backgroundcolor;
- if (!$this->user->update($original)) {
- $this->clientError(_('Error updating user.'),404,'json');
- return;
- }
-
- $profile = $this->user->getProfile();
-
- if (empty($profile)) {
- $this->clientError(_('User has no profile.'),'json');
- return;
+
+ // save the new color
+ $original = clone($this->auth_user);
+ $this->auth_user->backgroundcolor = $this->backgroundcolor;
+ if (!$this->auth_user->update($original)) {
+ $this->clientError(_('Error updating user.'), 404);
}
- $twitter_user = $this->twitterUserArray($profile, true);
+ $twitter_user = $this->twitterUserArray($this->scoped, true);
$this->initDocument('json');
$this->showJsonObjects($twitter_user);