From f9226e7debd7d409f934472159c52772262de53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez=20Garc=C3=ADa?= Date: Fri, 19 Feb 2016 08:37:22 +0100 Subject: [PATCH] Fixed login fail messages for django 1.9 --- server/src/uds/REST/methods/services_pools.py | 2 +- server/src/uds/__init__.py | 5 +++-- server/src/uds/web/forms/LoginForm.py | 15 --------------- server/src/uds/web/views/login.py | 6 +++--- 4 files changed, 7 insertions(+), 21 deletions(-) diff --git a/server/src/uds/REST/methods/services_pools.py b/server/src/uds/REST/methods/services_pools.py index 448f66786..76af99aa4 100644 --- a/server/src/uds/REST/methods/services_pools.py +++ b/server/src/uds/REST/methods/services_pools.py @@ -105,7 +105,7 @@ class ServicesPools(ModelHandler): 'user_services_count': item.userServices.count(), 'restrained': item.isRestrained(), 'show_transports': item.show_transports, - 'allowAccessByDefault': ALLOW if item.fallbackAccessAllow is True else DENY, + 'allowAccessByDefault': item.fallbackAccess, 'permission': permissions.getEffectivePermission(self._user, item), 'info': Services.serviceInfo(item.service), } diff --git a/server/src/uds/__init__.py b/server/src/uds/__init__.py index f550ca3e2..1674fee65 100644 --- a/server/src/uds/__init__.py +++ b/server/src/uds/__init__.py @@ -69,12 +69,13 @@ class UDSAppConfig(AppConfig): # We have to take care with this, because it's supposed to be executed # with ANY command from manage. logger.debug('Initializing app (ready) ***************') + + # Now, ensures that all dynamic elements are loadad and present from . import services # to make sure that the packages are initialized at this point from . import auths # To make sure that the packages are initialized at this point from . import osmanagers # To make sure that packages are initialized at this point from . import transports # To make sure that packages are initialized at this point - from . import dispatchers - from . import models + from . import dispatchers # Ensure all dischatchers all also available from . import plugins # To make sure plugins are loaded on memory from . import REST # To make sure REST initializes all what it needs diff --git a/server/src/uds/web/forms/LoginForm.py b/server/src/uds/web/forms/LoginForm.py index 49d6445ed..f24e0444f 100644 --- a/server/src/uds/web/forms/LoginForm.py +++ b/server/src/uds/web/forms/LoginForm.py @@ -36,7 +36,6 @@ from django.utils.translation import ugettext_lazy as _, ugettext from django import forms from django.utils.safestring import mark_safe from django.forms.forms import NON_FIELD_ERRORS -# from django.forms.util import ErrorDict from uds.models import Authenticator import logging @@ -57,20 +56,6 @@ class CustomSelect(forms.Select): res += '' return mark_safe('
' + res + '
') - -# class BaseForm(forms.Form): -# -# def __init__(self, *args, **kwargs): -# super(BaseForm, self).__init__(*args, **kwargs) -# -# def add_form_error(self, message): -# if not self._errors: -# self._errors = ErrorDict() -# if NON_FIELD_ERRORS not in self._errors: -# self._errors[NON_FIELD_ERRORS] = self.error_class() -# self._errors[NON_FIELD_ERRORS].append(message) - - class LoginForm(forms.Form): user = forms.CharField(label=_('Username'), max_length=64, widget=forms.TextInput()) password = forms.CharField(label=_('Password'), widget=forms.PasswordInput(attrs={'title': _('Password')}), required=False) diff --git a/server/src/uds/web/views/login.py b/server/src/uds/web/views/login.py index 2ca304b43..e7aa8f1a4 100644 --- a/server/src/uds/web/views/login.py +++ b/server/src/uds/web/views/login.py @@ -49,7 +49,7 @@ import uds.web.errors as errors import logging logger = logging.getLogger(__name__) -__updated__ = '2015-11-16' +__updated__ = '2016-02-19' def login(request, tag=None): @@ -98,7 +98,7 @@ def login(request, tag=None): if tries is None: tries = 0 if authenticator.getInstance().blockUserOnLoginFailures is True and tries >= GlobalConfig.MAX_LOGIN_TRIES.getInt(): - form.add_form_error('Too many authentication errors. User temporarily blocked.') + form.add_error(None, 'Too many authentication errors. User temporarily blocked.') authLogLogin(request, authenticator, userName, 'Temporarily blocked') else: password = form.cleaned_data['password'] @@ -112,7 +112,7 @@ def login(request, tag=None): logger.debug("Invalid credentials for user {0}".format(userName)) tries += 1 cache.put(cacheKey, tries, GlobalConfig.LOGIN_BLOCK.getInt()) - form.add_form_error(ugettext('Invalid credentials')) + form.add_error(None, ugettext('Invalid credentials')) authLogLogin(request, authenticator, userName, 'Invalid credentials') else: logger.debug('User {} has logged in'.format(userName))