OAuth app names should be unique.

This commit is contained in:
Zach Copley 2010-02-01 20:58:29 +00:00
parent 8a0a891960
commit dc183f23cf
4 changed files with 47 additions and 2 deletions

View File

@ -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;
}
}
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -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',