summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2010-02-01 20:58:29 +0000
committerZach Copley <zach@status.net>2010-02-05 03:18:43 +0000
commitdc183f23cf3bd8e0fbd604ad2af4b12f77837bf2 (patch)
tree6ef34516981741977af603b96166a651ee48fd32
parent8a0a89196043bc12e1fafea6d4638db5e61a181a (diff)
OAuth app names should be unique.
-rw-r--r--actions/editapplication.php24
-rw-r--r--actions/newapplication.php20
-rw-r--r--classes/statusnet.ini3
-rw-r--r--db/statusnet.sql2
4 files changed, 47 insertions, 2 deletions
diff --git a/actions/editapplication.php b/actions/editapplication.php
index 9cc3e3cea..029b622e8 100644
--- a/actions/editapplication.php
+++ b/actions/editapplication.php
@@ -179,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;
@@ -260,5 +263,26 @@ class EditApplicationAction extends OwnerDesignAction
common_redirect(common_local_url('oauthappssettings'), 303);
}
+ /**
+ * Does the app name already exist?
+ *
+ * Checks the DB to see someone has already registered and 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 (!$newapp) {
+ return false;
+ } else {
+ return $newapp->id != $this->app->id;
+ }
+ }
+
}
diff --git a/actions/newapplication.php b/actions/newapplication.php
index c499fe7c7..ba1cca5c9 100644
--- a/actions/newapplication.php
+++ b/actions/newapplication.php
@@ -158,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;
@@ -273,5 +276,22 @@ class NewApplicationAction extends OwnerDesignAction
}
+ /**
+ * Does the app name already exist?
+ *
+ * Checks the DB to see someone has already registered and 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 ($app !== false);
+ }
+
}
diff --git a/classes/statusnet.ini b/classes/statusnet.ini
index e28424ce2..a535159e8 100644
--- a/classes/statusnet.ini
+++ b/classes/statusnet.ini
@@ -353,7 +353,7 @@ notice_id = K
id = 129
owner = 129
consumer_key = 130
-name = 130
+name = 2
description = 2
icon = 130
source_url = 2
@@ -367,6 +367,7 @@ modified = 384
[oauth_application__keys]
id = N
+name = U
[oauth_application_user]
profile_id = 129
diff --git a/db/statusnet.sql b/db/statusnet.sql
index 17de4fd0d..71a6e724c 100644
--- a/db/statusnet.sql
+++ b/db/statusnet.sql
@@ -214,7 +214,7 @@ create table oauth_application (
id integer auto_increment primary key comment 'unique identifier',
owner integer not null comment 'owner of the application' references profile (id),
consumer_key varchar(255) not null comment 'application consumer key' references consumer (consumer_key),
- name varchar(255) not null comment 'name of the application',
+ name varchar(255) unique key comment 'name of the application',
description varchar(255) comment 'description of the application',
icon varchar(255) not null comment 'application icon',
source_url varchar(255) comment 'application homepage - used for source link',