diff --git a/lib/Alchemy/Phrasea/Application/OAuth2.php b/lib/Alchemy/Phrasea/Application/OAuth2.php index cd7e16f4a0..c8a5c5a400 100644 --- a/lib/Alchemy/Phrasea/Application/OAuth2.php +++ b/lib/Alchemy/Phrasea/Application/OAuth2.php @@ -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']; diff --git a/lib/classes/API/OAuth2/Form/DevAppDesktop.class.php b/lib/classes/API/OAuth2/Form/DevAppDesktop.class.php new file mode 100644 index 0000000000..91fab448f6 --- /dev/null +++ b/lib/classes/API/OAuth2/Form/DevAppDesktop.class.php @@ -0,0 +1,170 @@ +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; + } + +} \ No newline at end of file diff --git a/lib/classes/API/OAuth2/Form/DevAppInternet.class.php b/lib/classes/API/OAuth2/Form/DevAppInternet.class.php new file mode 100644 index 0000000000..67d356cb55 --- /dev/null +++ b/lib/classes/API/OAuth2/Form/DevAppInternet.class.php @@ -0,0 +1,170 @@ +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; + } + +} diff --git a/templates/web/api/auth/application_dev_new.twig b/templates/web/api/auth/application_dev_new.twig index df460e556e..402b17a902 100644 --- a/templates/web/api/auth/application_dev_new.twig +++ b/templates/web/api/auth/application_dev_new.twig @@ -59,14 +59,16 @@ {% trans 'Application web' %} - + {% trans 'Application desktop' %} - - - - - {{ _self.input("callback", callback|default("http://"), violations) }} + + {% if request.get("type") == "web" %} + + + {{ _self.input("callback", callback|default("http://"), violations) }} + + {% endif %}