fix desktop application creation issue

This commit is contained in:
Nicolas Le Goff
2012-02-16 15:14:38 +01:00
parent 843eb82014
commit 792d00efcb
4 changed files with 363 additions and 12 deletions

View File

@@ -282,7 +282,15 @@ return call_user_func(function()
$app->post($route, function() use ($app)
{
$submit = false;
$post = new \API_OAuth2_Form_DevApp($app['request']);
if ($app['request']->get("type") == "desktop")
{
$post = new \API_OAuth2_Form_DevAppDesktop($app['request']);
}
else
{
$post = new \API_OAuth2_Form_DevAppInternet($app['request']);
}
$violations = $app['validator']->validate($post);
if ($violations->count() == 0)
@@ -303,7 +311,8 @@ return call_user_func(function()
$var = array(
"violations" => $violations,
"form" => $post
"form" => $post,
"request" => $request
);
return $app['response']('api/auth/application_dev_new.twig', $var);
@@ -339,7 +348,7 @@ return call_user_func(function()
}
catch (Exception $e)
{
}
$Serializer = $app['Core']['Serializer'];
@@ -374,7 +383,7 @@ return call_user_func(function()
}
catch (Exception $e)
{
}
$Serializer = $app['Core']['Serializer'];
@@ -400,7 +409,7 @@ return call_user_func(function()
}
catch (Exception $e)
{
}
$Serializer = $app['Core']['Serializer'];
@@ -424,7 +433,7 @@ return call_user_func(function()
}
catch (\Exception $e)
{
}
$Serializer = $app['Core']['Serializer'];

View File

@@ -0,0 +1,170 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
*
* @package OAuth2 Connector
*
* @see http://oauth.net/2/
* @uses http://code.google.com/p/oauth2-php/
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints;
class API_OAuth2_Form_DevAppDesktop
{
/**
*
* @var string
*/
public $name;
/**
*
* @var string
*/
public $description;
/**
*
* @var string
*/
public $website;
/**
*
* @var string
*/
public $callback;
/**
*
* @param Request $request
* @return API_OAuth2_Form_DevApp
*/
public function __construct(Request $request)
{
$this->name = $request->get('name', null);
$this->description = $request->get('description', null);
$this->website = $request->get('website', null);
$this->callback = $request->get('callback', null);
return $this;
}
/**
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
*
* @return string
*/
public function getWebsite()
{
return $this->website;
}
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setWebsite($website)
{
$this->website = $website;
return $this;
}
/**
*
* @return string
*/
public function getCallback()
{
return $this->callback;
}
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setCallback($callback)
{
$this->callback = $callback;
return $this;
}
/**
*
* @param ClassMetadata $metadata
* @return API_OAuth2_Form_DevApp
*/
static public function loadValidatorMetadata(ClassMetadata $metadata)
{
$blank = array('message' => _('Cette valeur ne peut être vide'));
$url = array('message' => _('Url non valide'));
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('website', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('website', new Constraints\Url($url));
return;
}
}

View File

@@ -0,0 +1,170 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
*
*
* @package OAuth2 Connector
*
* @see http://oauth.net/2/
* @uses http://code.google.com/p/oauth2-php/
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints;
class API_OAuth2_Form_DevAppInternet
{
/**
*
* @var string
*/
public $name;
/**
*
* @var string
*/
public $description;
/**
*
* @var string
*/
public $website;
/**
*
* @var string
*/
public $callback;
/**
*
* @param Request $request
* @return API_OAuth2_Form_DevApp
*/
public function __construct(Request $request)
{
$this->name = $request->get('name', null);
$this->description = $request->get('description', null);
$this->website = $request->get('website', null);
$this->callback = $request->get('callback', null);
return $this;
}
/**
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
*
* @return string
*/
public function getWebsite()
{
return $this->website;
}
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setWebsite($website)
{
$this->website = $website;
return $this;
}
/**
*
* @return string
*/
public function getCallback()
{
return $this->callback;
}
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setCallback($callback)
{
$this->callback = $callback;
return $this;
}
/**
*
* @param ClassMetadata $metadata
* @return API_OAuth2_Form_DevApp
*/
static public function loadValidatorMetadata(ClassMetadata $metadata)
{
$blank = array('message' => _('Cette valeur ne peut être vide'));
$url = array('message' => _('Url non valide'));
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('website', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('website', new Constraints\Url($url));
return;
}
}

View File

@@ -59,14 +59,16 @@
<tr>
<td><label for="type">{% trans 'Type d\'application' %}</label></td>
<td>{% trans 'Application web' %}
<input type="radio" name="type" value="web" checked="checked"/>
<input type="radio" name="type" value="web" {{ request.get("type") == "web" ? "checked='checked'" : "" }}/>
{% trans 'Application desktop' %}
<input type="radio" name="type" value="desktop"/></td>
</tr>
<tr class="callback" style="height:25px;">
<td><label for="callback">{% trans 'URL de callback' %} <br/></label></td>
<td>{{ _self.input("callback", callback|default("http://"), violations) }}</td>
<input type="radio" name="type" value="desktop" {{ request.get("type") == "desktop" ? "checked='checked'" : "" }}/></td>
</tr>
{% if request.get("type") == "web" %}
<tr class="callback" style="height:25px;">
<td><label for="callback">{% trans 'URL de callback' %} <br/></label></td>
<td>{{ _self.input("callback", callback|default("http://"), violations) }}</td>
</tr>
{% endif %}
<tr>
<td></td>
<td><button class="app_submit" type="button">{% trans 'boutton::valider' %}</button</td>