]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/editapplication.php
override linkAttributes() method for groupmembersminilist
[quix0rs-gnu-social.git] / actions / editapplication.php
index a0ed3117a709e8eb22c228a26f768c959a7c5eca..64cf0a5745d134fcceeb7b214844b45dc86111ec 100644 (file)
@@ -45,9 +45,9 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
 
 class EditApplicationAction extends OwnerDesignAction
 {
-    var $msg = null;
-
-    var $app = null;
+    var $msg   = null;
+    var $owner = null;
+    var $app   = null;
 
     function title()
     {
@@ -68,7 +68,14 @@ class EditApplicationAction extends OwnerDesignAction
         }
 
         $id = (int)$this->arg('id');
-        $this->app = Oauth_application::staticGet($id);
+
+        $this->app   = Oauth_application::staticGet($id);
+        $this->owner = User::staticGet($this->app->owner);
+        $cur         = common_current_user();
+
+        if ($cur->id != $this->owner->id) {
+            $this->clientError(_('You are not the owner of this application.'), 401);
+        }
 
         if (!$this->app) {
             $this->clientError(_('No such application.'));
@@ -125,10 +132,7 @@ class EditApplicationAction extends OwnerDesignAction
 
         if ($this->arg('cancel')) {
             common_redirect(common_local_url('showapplication',
-                                             array(
-                                                   'nickname' => $cur->nickname,
-                                                   'id' => $this->app->id)
-                                             ), 303);
+                                             array('id' => $this->app->id)), 303);
         } elseif ($this->arg('save')) {
             $this->trySave();
         } else {
@@ -175,6 +179,9 @@ class EditApplicationAction extends OwnerDesignAction
         } elseif (mb_strlen($name) > 255) {
             $this->showForm(_('Name is too long (max 255 chars).'));
             return;
+        } else if ($this->nameExists($name)) {
+            $this->showForm(_('Name already in use. Try another one.'));
+            return;
         } elseif (empty($description)) {
             $this->showForm(_('Description is required.'));
             return;
@@ -253,8 +260,28 @@ class EditApplicationAction extends OwnerDesignAction
 
         $this->app->uploadLogo();
 
-        common_redirect(common_local_url('apps',
-            array('nickname' => $cur->nickname)), 303);
+        common_redirect(common_local_url('oauthappssettings'), 303);
+    }
+
+    /**
+     * Does the app name already exist?
+     *
+     * Checks the DB to see someone has already registered an app
+     * with the same name.
+     *
+     * @param string $name app name to check
+     *
+     * @return boolean true if the name already exists
+     */
+
+    function nameExists($name)
+    {
+        $newapp = Oauth_application::staticGet('name', $name);
+        if (empty($newapp)) {
+            return false;
+        } else {
+            return $newapp->id != $this->app->id;
+        }
     }
 
 }