]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/newapplication.php
OStatus/FeedSub: tweaked PuSH feed garbage collection so other plugins can declare...
[quix0rs-gnu-social.git] / actions / newapplication.php
index 3d42b657befc0601333900816d44de277e9aed7f..0f819b3499881795e3ce597fd1559846875f7f15 100644 (file)
@@ -114,8 +114,7 @@ class NewApplicationAction extends OwnerDesignAction
     $cur = common_current_user();
 
     if ($this->arg('cancel')) {
-        common_redirect(common_local_url('apps',
-                         array('nickname' => $cur->nickname)), 303);
+        common_redirect(common_local_url('oauthappssettings'), 303);
     } elseif ($this->arg('save')) {
         $this->trySave();
     } else {
@@ -147,7 +146,7 @@ class NewApplicationAction extends OwnerDesignAction
 
     function trySave()
     {
-    $name         = $this->trimmed('name');
+        $name         = $this->trimmed('name');
         $description  = $this->trimmed('description');
         $source_url   = $this->trimmed('source_url');
         $organization = $this->trimmed('organization');
@@ -159,6 +158,9 @@ class NewApplicationAction extends OwnerDesignAction
         if (empty($name)) {
              $this->showForm(_('Name is required.'));
              return;
+        } else if ($this->nameExists($name)) {
+            $this->showForm(_('Name already in use. Try another one.'));
+            return;
         } elseif (mb_strlen($name) > 255) {
             $this->showForm(_('Name is too long (max 255 chars).'));
             return;
@@ -266,13 +268,29 @@ class NewApplicationAction extends OwnerDesignAction
             $app->query('ROLLBACK');
         }
 
-        $this->app->uploadLogo();
+        $app->uploadLogo();
 
         $app->query('COMMIT');
 
-        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)
+    {
+        $app = Oauth_application::staticGet('name', $name);
+        return !empty($app);
     }
 
 }