2015-05-27 20:10:06 +00:00
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
|
|
|
|
# more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License version 3
|
|
|
|
# along with this program; if not, write to the Free Software Foundation, Inc., 51
|
|
|
|
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# (c) 2015 Valentin Samir
|
2015-05-27 19:56:39 +00:00
|
|
|
"""forms for the app"""
|
2015-05-30 17:45:59 +00:00
|
|
|
from .default_settings import settings
|
2015-05-17 21:24:41 +00:00
|
|
|
|
2015-05-16 21:43:46 +00:00
|
|
|
from django import forms
|
2015-05-22 15:55:00 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2015-05-16 21:43:46 +00:00
|
|
|
|
2015-06-21 16:56:16 +00:00
|
|
|
import cas_server.utils as utils
|
|
|
|
import cas_server.models as models
|
2015-05-16 21:43:46 +00:00
|
|
|
|
2016-06-03 12:19:43 +00:00
|
|
|
|
2016-06-03 12:11:07 +00:00
|
|
|
class WarnForm(forms.Form):
|
|
|
|
service = forms.CharField(widget=forms.HiddenInput(), required=False)
|
|
|
|
renew = forms.BooleanField(widget=forms.HiddenInput(), required=False)
|
|
|
|
gateway = forms.CharField(widget=forms.HiddenInput(), required=False)
|
|
|
|
method = forms.CharField(widget=forms.HiddenInput(), required=False)
|
|
|
|
warned = forms.BooleanField(widget=forms.HiddenInput(), required=False)
|
|
|
|
lt = forms.CharField(widget=forms.HiddenInput(), required=False)
|
2015-06-12 16:10:52 +00:00
|
|
|
|
2016-06-03 12:19:43 +00:00
|
|
|
|
2015-05-16 21:43:46 +00:00
|
|
|
class UserCredential(forms.Form):
|
2015-05-27 19:56:39 +00:00
|
|
|
"""Form used on the login page to retrive user credentials"""
|
2015-05-22 15:55:00 +00:00
|
|
|
username = forms.CharField(label=_('login'))
|
2015-06-11 21:04:26 +00:00
|
|
|
service = forms.CharField(label=_('service'), widget=forms.HiddenInput(), required=False)
|
2015-05-22 15:55:00 +00:00
|
|
|
password = forms.CharField(label=_('password'), widget=forms.PasswordInput)
|
2015-06-09 20:04:05 +00:00
|
|
|
lt = forms.CharField(widget=forms.HiddenInput(), required=False)
|
2015-05-16 21:43:46 +00:00
|
|
|
method = forms.CharField(widget=forms.HiddenInput(), required=False)
|
2015-05-22 15:55:00 +00:00
|
|
|
warn = forms.BooleanField(label=_('warn'), required=False)
|
2015-05-16 21:43:46 +00:00
|
|
|
|
2015-06-12 21:57:11 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2015-05-16 21:43:46 +00:00
|
|
|
super(UserCredential, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
cleaned_data = super(UserCredential, self).clean()
|
2015-05-30 17:45:59 +00:00
|
|
|
auth = utils.import_attr(settings.CAS_AUTH_CLASS)(cleaned_data.get("username"))
|
2015-05-16 21:43:46 +00:00
|
|
|
if auth.test_password(cleaned_data.get("password")):
|
2015-06-12 21:57:11 +00:00
|
|
|
cleaned_data["username"] = auth.username
|
2015-05-16 21:43:46 +00:00
|
|
|
else:
|
2015-05-23 17:03:37 +00:00
|
|
|
raise forms.ValidationError(_(u"Bad user"))
|
2015-05-16 21:43:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TicketForm(forms.ModelForm):
|
2015-05-27 19:56:39 +00:00
|
|
|
"""Form for Tickets in the admin interface"""
|
2015-05-16 21:43:46 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.Ticket
|
|
|
|
exclude = []
|
2015-06-11 21:04:26 +00:00
|
|
|
service = forms.CharField(label=_('service'), widget=forms.TextInput)
|