1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from urlparse
import urlparse
21 from mediagoblin
.tools
.extlib
.wtf_html5
import URLField
22 from mediagoblin
.tools
.translate
import fake_ugettext_passthrough
as _
25 class AuthorizationForm(wtforms
.Form
):
26 client_id
= wtforms
.HiddenField(u
'',
27 validators
=[wtforms
.validators
.Required()])
28 next
= wtforms
.HiddenField(u
'', validators
=[wtforms
.validators
.Required()])
29 allow
= wtforms
.SubmitField(_(u
'Allow'))
30 deny
= wtforms
.SubmitField(_(u
'Deny'))
33 class ClientRegistrationForm(wtforms
.Form
):
34 name
= wtforms
.TextField(_('Name'), [wtforms
.validators
.Required()],
35 description
=_('The name of the OAuth client'))
36 description
= wtforms
.TextAreaField(_('Description'),
37 [wtforms
.validators
.Length(min=0, max=500)],
38 description
=_('''This will be visible to users allowing your
39 application to authenticate as them.'''))
40 type = wtforms
.SelectField(_('Type'),
41 [wtforms
.validators
.Required()],
43 ('confidential', 'Confidential'),
44 ('public', 'Public')],
45 description
=_('''<strong>Confidential</strong> - The client can
46 make requests to the GNU MediaGoblin instance that can not be
47 intercepted by the user agent (e.g. server-side client).<br />
48 <strong>Public</strong> - The client can't make confidential
49 requests to the GNU MediaGoblin instance (e.g. client-side
50 JavaScript client).'''))
52 redirect_uri
= URLField(_('Redirect URI'),
53 [wtforms
.validators
.Optional(), wtforms
.validators
.URL()],
54 description
=_('''The redirect URI for the applications, this field
55 is <strong>required</strong> for public clients.'''))
57 def __init__(self
, *args
, **kw
):
58 wtforms
.Form
.__init
__(self
, *args
, **kw
)
61 if not wtforms
.Form
.validate(self
):
64 if self
.type.data
== 'public' and not self
.redirect_uri
.data
:
65 self
.redirect_uri
.errors
.append(
66 _('This field is required for public clients'))