Commit | Line | Data |
---|---|---|
88a9662b JW |
1 | # GNU MediaGoblin -- federated, autonomous media hosting |
2 | # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. | |
3 | # | |
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. | |
8 | # | |
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. | |
13 | # | |
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/>. | |
16 | ||
17 | import wtforms | |
18 | ||
19 | from urlparse import urlparse | |
20 | ||
21 | from mediagoblin.tools.extlib.wtf_html5 import URLField | |
665b9c42 | 22 | from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ |
88a9662b JW |
23 | |
24 | ||
25 | class AuthorizationForm(wtforms.Form): | |
77c85224 JW |
26 | client_id = wtforms.HiddenField(u'', |
27 | validators=[wtforms.validators.Required()]) | |
28 | next = wtforms.HiddenField(u'', validators=[wtforms.validators.Required()]) | |
88a9662b JW |
29 | allow = wtforms.SubmitField(_(u'Allow')) |
30 | deny = wtforms.SubmitField(_(u'Deny')) | |
31 | ||
32 | ||
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)], | |
315ac0a2 | 38 | description=_('''This will be visible to users allowing your |
5ee1ab2a | 39 | application to authenticate as them.''')) |
88a9662b JW |
40 | type = wtforms.SelectField(_('Type'), |
41 | [wtforms.validators.Required()], | |
42 | choices=[ | |
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).''')) | |
51 | ||
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.''')) | |
56 | ||
57 | def __init__(self, *args, **kw): | |
58 | wtforms.Form.__init__(self, *args, **kw) | |
59 | ||
60 | def validate(self): | |
61 | if not wtforms.Form.validate(self): | |
62 | return False | |
63 | ||
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')) | |
67 | return False | |
68 | ||
69 | return True |