fix oauth app creation bug

This commit is contained in:
Nicolas Le Goff
2012-02-22 16:55:50 +01:00
parent 35d6d86756
commit 33b225a290
6 changed files with 179 additions and 167 deletions

View File

@@ -300,19 +300,18 @@ return call_user_func(function()
if ($submit) if ($submit)
{ {
$application = \API_OAuth2_Application::create($app['appbox'], $app['user'], $request->get('name')); $application = \API_OAuth2_Application::create($app['appbox'], $app['user'], $post->getName());
$application->set_description($request->get('description')) $application->set_description($post->getDescription())
->set_redirect_uri($request->get('callback')) ->set_redirect_uri($post->getSchemeCallback().$post->getCallback())
->set_type($request->get('type')) ->set_type($post->getType())
->set_website($request->get('website')); ->set_website($post->getSchemeWebsite().$post->getWebsite());
return $app->redirect("/api/oauthv2/applications/dev/" . $application->get_id() . "/show"); return $app->redirect("/api/oauthv2/applications/dev/" . $application->get_id() . "/show");
} }
$var = array( $var = array(
"violations" => $violations, "violations" => $violations,
"form" => $post, "form" => $post
"request" => $request
); );
return $app['response']('api/auth/application_dev_new.twig', $var); return $app['response']('api/auth/application_dev_new.twig', $var);

View File

@@ -51,6 +51,14 @@ class API_OAuth2_Form_DevAppDesktop
*/ */
public $callback; public $callback;
/**
*
* @var string
*/
public $type;
public $scheme_website;
public $urlwebsite;
/** /**
* *
* @param Request $request * @param Request $request
@@ -58,10 +66,14 @@ class API_OAuth2_Form_DevAppDesktop
*/ */
public function __construct(Request $request) public function __construct(Request $request)
{ {
$this->name = $request->get('name', null); $this->name = $request->get('name', '');
$this->description = $request->get('description', null); $this->description = $request->get('description', '');
$this->website = $request->get('website', null); $this->scheme_website = $request->get('scheme-website', 'http://');
$this->callback = $request->get('callback', null); $this->website = $request->get('website', '');
$this->callback = API_OAuth2_Application::NATIVE_APP_REDIRECT_URI;
$this->type = API_OAuth2_Application::DESKTOP_TYPE;
$this->urlwebsite = $this->scheme_website . $this->website;
return $this; return $this;
} }
@@ -75,18 +87,6 @@ class API_OAuth2_Form_DevAppDesktop
return $this->name; return $this->name;
} }
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/** /**
* *
* @return string * @return string
@@ -96,18 +96,6 @@ class API_OAuth2_Form_DevAppDesktop
return $this->description; return $this->description;
} }
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/** /**
* *
* @return string * @return string
@@ -117,18 +105,6 @@ class API_OAuth2_Form_DevAppDesktop
return $this->website; return $this->website;
} }
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setWebsite($website)
{
$this->website = $website;
return $this;
}
/** /**
* *
* @return string * @return string
@@ -140,17 +116,29 @@ class API_OAuth2_Form_DevAppDesktop
/** /**
* *
* @param string $callback * @return string
* @return API_OAuth2_Form_DevApp
*/ */
public function setCallback($callback) public function getType()
{ {
$this->callback = $callback; return $this->type;
return $this;
} }
/** public function getSchemeWebsite()
{
return $this->scheme_website;
}
public function getUrlwebsite()
{
return $this->urlwebsite;
}
public function getSchemeCallback()
{
return '';
}
/**
* *
* @param ClassMetadata $metadata * @param ClassMetadata $metadata
* @return API_OAuth2_Form_DevApp * @return API_OAuth2_Form_DevApp
@@ -162,8 +150,8 @@ class API_OAuth2_Form_DevAppDesktop
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank)); $metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank)); $metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('website', new Constraints\NotBlank($blank)); $metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('website', new Constraints\Url($url)); $metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
return; return;
} }

View File

@@ -50,6 +50,12 @@ class API_OAuth2_Form_DevAppInternet
* @var string * @var string
*/ */
public $callback; public $callback;
public $scheme_website;
public $scheme_callback;
public $urlwebsite;
public $urlcallback;
/** /**
* *
@@ -58,11 +64,17 @@ class API_OAuth2_Form_DevAppInternet
*/ */
public function __construct(Request $request) public function __construct(Request $request)
{ {
$this->name = $request->get('name', null); $this->name = $request->get('name', '');
$this->description = $request->get('description', null); $this->description = $request->get('description', '');
$this->website = $request->get('website', null); $this->website = $request->get('website', '');
$this->callback = $request->get('callback', null); $this->callback = $request->get('callback', '');
$this->scheme_website = $request->get('scheme-website', 'http://');
$this->scheme_callback = $request->get('scheme-callback', 'http://');
$this->type = API_OAuth2_Application::WEB_TYPE;
$this->urlwebsite = $this->scheme_website.$this->website;
$this->urlcallback = $this->scheme_callback.$this->callback;
return $this; return $this;
} }
@@ -75,18 +87,6 @@ class API_OAuth2_Form_DevAppInternet
return $this->name; return $this->name;
} }
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/** /**
* *
* @return string * @return string
@@ -96,18 +96,6 @@ class API_OAuth2_Form_DevAppInternet
return $this->description; return $this->description;
} }
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/** /**
* *
* @return string * @return string
@@ -117,18 +105,6 @@ class API_OAuth2_Form_DevAppInternet
return $this->website; return $this->website;
} }
/**
*
* @param string $callback
* @return API_OAuth2_Form_DevApp
*/
public function setWebsite($website)
{
$this->website = $website;
return $this;
}
/** /**
* *
* @return string * @return string
@@ -140,17 +116,34 @@ class API_OAuth2_Form_DevAppInternet
/** /**
* *
* @param string $callback * @return string
* @return API_OAuth2_Form_DevApp
*/ */
public function setCallback($callback) public function getType()
{ {
$this->callback = $callback; return $this->type;
return $this;
} }
/** public function getSchemeWebsite()
{
return $this->scheme_website;
}
public function getSchemeCallback()
{
return $this->scheme_callback;
}
public function getUrlwebsite()
{
return $this->urlwebsite;
}
public function getUrlcallback()
{
return $this->urlcallback;
}
/**
* *
* @param ClassMetadata $metadata * @param ClassMetadata $metadata
* @return API_OAuth2_Form_DevApp * @return API_OAuth2_Form_DevApp
@@ -162,8 +155,10 @@ class API_OAuth2_Form_DevAppInternet
$metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank)); $metadata->addPropertyConstraint('name', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank)); $metadata->addPropertyConstraint('description', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('website', new Constraints\NotBlank($blank)); $metadata->addPropertyConstraint('urlwebsite', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('website', new Constraints\Url($url)); $metadata->addPropertyConstraint('urlwebsite', new Constraints\Url($url));
$metadata->addPropertyConstraint('urlcallback', new Constraints\NotBlank($blank));
$metadata->addPropertyConstraint('urlcallback', new Constraints\Url($url));
return; return;
} }

View File

@@ -1,82 +1,94 @@
{% macro input(name, value, violations, type, size) %} {% macro input(name, value, violations, property, type, size) %}
{% if violations is none %} {% if violations is none %}
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" /> <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" />
{% else %} {% else %}
{% set hasError = "false" %} {% set hasError = "false" %}
{% for violation in violations %} {% for violation in violations %}
{% if violation.getPropertyPath == name and hasError == "false" %} {% if violation.getPropertyPath == property and hasError == "false" %}
{% set hasError = "true" %} {% set hasError = "true" %}
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ violation.getInvalidValue }}" size="{{ size|default(20) }}" /> <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value }}" size="{{ size|default(20) }}" />
<div style="color:red" > {{violation.getMessage}} </div> <div style="color:red" > {{ violation.getInvalidValue }} - {{violation.getMessage}} </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if hasError == "false" %} {% if hasError == "false" %}
<input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" /> {% endif %} <input type="{{ type|default('text') }}" name="{{ name }}" value="{{ value|e }}" size="{{ size|default(20) }}" /> {% endif %}
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
{% macro textarea(name, value, violations, rows, cols) %} {% macro textarea(name, value, violations,property, rows, cols) %}
{% if violations is none %} {% if violations is none %}
<textarea name="{{ name }}" rows="{{ rows|default(4)}}" cols="{{cols|default(20)}}" >{{ value|e}}</textarea> <textarea name="{{ name }}" rows="{{ rows|default(4)}}" cols="{{cols|default(20)}}" >{{ value|e}}</textarea>
{% else %} {% else %}
{% set hasError = "false" %} {% set hasError = "false" %}
{% for violation in violations %} {% for violation in violations %}
{% if violation.getPropertyPath == name and hasError == "false" %} {% if violation.getPropertyPath == property and hasError == "false" %}
{% set hasError = "true" %} {% set hasError = "true" %}
<textarea name="{{ name }}" rows="{{ rows|default(4)}}" cols="{{cols|default(20)}}" >{{ violation.getInvalidValue}}</textarea> <textarea name="{{ name }}" rows="{{ rows|default(4)}}" cols="{{cols|default(20)}}" >{{ violation.getInvalidValue}}</textarea>
<div style="color:red" > {{violation.getMessage}} </div> <div style="color:red" > {{violation.getMessage}} </div>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if hasError == "false" %} {% if hasError == "false" %}
<textarea name="{{ name }}" rows="{{ rows|default(4)}}" cols="{{cols|default(20)}}" >{{ value|e}}</textarea> <textarea name="{{ name }}" rows="{{ rows|default(4)}}" cols="{{cols|default(20)}}" >{{ value|e}}</textarea>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
{% block dev %} {% block dev %}
<form id="form_create" action="/api/oauthv2/applications/dev/create" method="POST"> <form id="form_create" action="/api/oauthv2/applications/dev/create" method="POST">
{% if form is none %} {% if form is none %}
{% set name, description, website, callback = '', '', '', ''%} {% set name, description, website, callback = '', '', '', ''%}
{% set app_type = 'web'%}
{% else %} {% else %}
{% set name = form.name %} {% set name = form.name %}
{% set description = form.description %} {% set description = form.description %}
{% set website = form.website %} {% set website = form.website %}
{% set callback = form.callback %} {% set callback = form.callback %}
{% set app_type = form.type %}
{% endif %} {% endif %}
<table id = "app-dev-create"> <table id = "app-dev-create">
<tr> <tr>
<td><label for="name">{% trans 'Nom' %}</label></td> <td><label for="name">{% trans 'Nom' %}</label></td>
<td>{{ _self.input("name", name, violations) }}</td> <td>{{ _self.input("name", name, violations, 'name') }}</td>
</tr> </tr>
<tr> <tr>
<td><label for="description">{% trans 'Description' %}</label></td> <td><label for="description">{% trans 'Description' %}</label></td>
<td>{{ _self.textarea("description", description, violations,5,17) }}</td> <td>{{ _self.textarea("description", description, 'description', violations, 5, 17) }}</td>
</tr> </tr>
<tr> <tr>
<td><label for="website">{% trans 'Site web' %}</label></td> <td><label for="website">{% trans 'Site web' %}</label></td>
<td>{{ _self.input("website", website|default("http://"), violations) }}</td> <td class="url-td">
</tr> <select name="scheme-website">
<tr> <option value="http://">http://</option>
<td><label for="type">{% trans 'Type d\'application' %}</label></td> <option value="https://">https://</option>
<td>{% trans 'Application web' %} </select>
<input type="radio" name="type" value="web" {{ request.get("type") == "web" ? "checked='checked'" : "" }}/> {{ _self.input("website", website, violations, 'urlwebsite') }}</td>
</tr>
<tr>
<td><label for="type">{% trans 'Type d\'application' %}</label></td>
<td>{% trans 'Application web' %}
<input type="radio" name="type" value="web" {{ app_type == "web" ? "checked='checked'" : "" }}/>
{% trans 'Application desktop' %} {% trans 'Application desktop' %}
<input type="radio" name="type" value="desktop" {{ request.get("type") == "desktop" ? "checked='checked'" : "" }}/></td> <input type="radio" name="type" value="desktop" {{ app_type == "desktop" ? "checked='checked'" : "" }}/></td>
</tr> </tr>
{% if request.get("type") == "web" %} {% if app_type == "web" %}
<tr class="callback" style="height:25px;"> <tr class="callback" style="height:25px;">
<td><label for="callback">{% trans 'URL de callback' %} <br/></label></td> <td><label for="callback">{% trans 'URL de callback' %} <br/></label></td>
<td>{{ _self.input("callback", callback|default("http://"), violations) }}</td> <td class="url-td">
<select name="scheme-callback">
<option value="http://">http://</option>
<option value="https://">https://</option>
</select>
{{ _self.input("callback", callback, violations, 'urlcallback') }}</td>
</tr> </tr>
{% endif %} {% endif %}
<tr> <tr>
<td></td> <td></td>
<td><button class="app_submit" type="button">{% trans 'boutton::valider' %}</button</td> <td><button class="app_submit" type="button">{% trans 'boutton::valider' %}</button</td>
</tr> </tr>
</table> </table>
</form> </form>
<div style="text-align:left"> <div style="text-align:left">
<a class="dev_back link" href="/api/oauthv2/applications/dev"><button>{% trans 'boutton::retour' %}</button></a> <a class="dev_back link" href="/api/oauthv2/applications/dev"><button>{% trans 'boutton::retour' %}</button></a>
<div> <div>
{% endblock %} {% endblock %}

View File

@@ -2,14 +2,14 @@
<h1 style='text-align:left'>{% trans 'Application' %}</h1> <h1 style='text-align:left'>{% trans 'Application' %}</h1>
<input type="hidden" value="{{app.get_id}}" name="app_id"/> <input type="hidden" value="{{app.get_id}}" name="app_id"/>
<div> <div>
<ul class='app-list'> <ul class='app-list'>
<li> <li>
<div> <div>
<span class='app-row'><strong><a class="link" id="app_dev_new" href="/api/oauthv2/applications/dev/{{app.get_id}}/show">{{app.get_name}}</a></strong></span> <span class='app-row'><strong><a class="link" id="app_dev_new" href="/api/oauthv2/applications/dev/{{app.get_id}}/show">{{app.get_name}}</a></strong></span>
<span class='app-row'>{{app.get_description }}</span> <span class='app-row'>{{app.get_description }}</span>
</div> </div>
</li> </li>
</ul> </ul>
</div> </div>
<h1 style='text-align:left'>{% trans 'settings OAuth' %}</h1> <h1 style='text-align:left'>{% trans 'settings OAuth' %}</h1>
<p style='text-align:left'>{% trans 'Les parametres oauth de votre application.' %}</p> <p style='text-align:left'>{% trans 'Les parametres oauth de votre application.' %}</p>
@@ -25,7 +25,16 @@
</tr> </tr>
<tr> <tr>
<td>{% trans 'URL de callback' %}</td> <td>{% trans 'URL de callback' %}</td>
<td class="url_callback"><span class="url_callback_input">{{app.get_redirect_uri}}</span> <button type="button" class="save_callback" style="display:none;">save</button><button type="button" class="modifier_callback" style="display:none;">modifier</button></td> {% if app.get_type == constant('API_OAuth2_Application::DESKTOP_TYPE') %}
<td>
<span>{{app.get_redirect_uri}}</span>
</td>
{% else %}
<td class="url_callback"><span class="url_callback_input">{{app.get_redirect_uri}}</span>
<button type="button" class="save_callback" style="display:none;">save</button>
<button type="button" class="modifier_callback" style="display:none;">modifier</button>
</td>
{%endif%}
</tr> </tr>
<tr> <tr>
<td>Authorize endpoint</td> <td>Authorize endpoint</td>
@@ -45,25 +54,25 @@
<tr> <tr>
<td style='width:25%'> <td style='width:25%'>
{% trans 'Token' %} {% trans 'Token' %}
</td> </td>
<td> <td>
<span id="my_access_token"> <span id="my_access_token">
{% if not token is none %} {% if not token is none %}
{{token|default('')}} {{token|default('')}}
{% else %} {% else %}
{% trans 'Le token n\'a pas encore ete genere' %} {% trans 'Le token n\'a pas encore ete genere' %}
{% endif %} {% endif %}
</span> </span>
</td> </td>
</tr> </tr>
<tr> <tr>
<td style='width:25%'></td> <td style='width:25%'></td>
<td><button id="generate_access" type="button" value="{{app.get_id}}">{% trans 'boutton::generer' %}</button></td> <td><button id="generate_access" type="button" value="{{app.get_id}}">{% trans 'boutton::generer' %}</button></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<div style='text-align:left'> <div style='text-align:left'>
<a class="dev_back link" href="/api/oauthv2/applications/dev"><button>{% trans 'boutton::retour' %}</button></a> <a class="dev_back link" href="/api/oauthv2/applications/dev"><button>{% trans 'boutton::retour' %}</button></a>
</div> </div>
{% endblock %} {% endblock %}

View File

@@ -332,8 +332,9 @@
width:100%; width:100%;
} }
#app-dev-create td input[type=text], #app-dev-create td textarea{ #app-dev-create td input[type=text], #app-dev-create td textarea, #app-dev-create td select{
width:100%; display:inline-block;
width:95%;
border: 1px solid #CCCCCC; border: 1px solid #CCCCCC;
border-radius: 4px 4px 4px 4px; border-radius: 4px 4px 4px 4px;
box-shadow: 0 1px 1px #EEEEEE; box-shadow: 0 1px 1px #EEEEEE;
@@ -341,6 +342,14 @@
padding: 6px; padding: 6px;
} }
#app-dev-create td input[name=callback], #app-dev-create td input[name=website]{
width:85%;
}
#app-dev-create .url-td select{
width:12%;
}
#app-dev-create td{ #app-dev-create td{
text-align:left; text-align:left;
} }