Browse Source

Sign in form somehow works.

Rafał Pitoń 11 years ago
parent
commit
ec34accf61
3 changed files with 23 additions and 6 deletions
  1. 8 2
      misago/templates/misago/login.html
  2. 13 2
      misago/users/forms/auth.py
  3. 2 2
      misago/users/views/auth.py

+ 8 - 2
misago/templates/misago/login.html

@@ -22,14 +22,20 @@
 
 
           <div class="form-body no-fieldsets">
           <div class="form-body no-fieldsets">
 
 
+            {% for error in form.non_field_errors %}
+            <p class="lead text-center text-danger">
+              {{ error }}
+            </p>
+            {% endfor %}
+
             <div class="form-group">
             <div class="form-group">
               <div class="control-input">
               <div class="control-input">
-                <input type="email" class="form-control input-lg" placeholder="{% trans "Username or e-mail" %}">
+                <input type="text" name="username" class="form-control input-lg" placeholder="{% trans "Username or e-mail" %}" {% if form.username.value %}value="{{ form.username.value }}"{% endif %}>
               </div>
               </div>
             </div>
             </div>
             <div class="form-group">
             <div class="form-group">
               <div class="control-input">
               <div class="control-input">
-                <input type="password" class="form-control input-lg" placeholder="{% trans "Password" %}">
+                <input type="password" name="password" class="form-control input-lg" placeholder="{% trans "Password" %}">
               </div>
               </div>
             </div>
             </div>
 
 

+ 13 - 2
misago/users/forms/auth.py

@@ -11,10 +11,14 @@ class AuthenticationForm(forms.Form, BaseAuthenticationForm):
     Base class for authenticating users, Floppy-forms and
     Base class for authenticating users, Floppy-forms and
     Misago login field comliant
     Misago login field comliant
     """
     """
-    username = forms.CharField(label=_("Username or e-mail"), max_length=254)
-    password = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
+    username = forms.CharField(label=_("Username or e-mail"),
+                               required=False,
+                               max_length=254)
+    password = forms.CharField(label=_("Password"), required=False,
+                               widget=forms.PasswordInput)
 
 
     error_messages = {
     error_messages = {
+        'empty_data': _("You have to fill out both fields."),
         'invalid_login': _("Your login or password is incorrect. Please try again."),
         'invalid_login': _("Your login or password is incorrect. Please try again."),
         'inactive': _("This account is inactive."),
         'inactive': _("This account is inactive."),
     }
     }
@@ -33,6 +37,11 @@ class AuthenticationForm(forms.Form, BaseAuthenticationForm):
                 )
                 )
             else:
             else:
                 self.confirm_login_allowed(self.user_cache)
                 self.confirm_login_allowed(self.user_cache)
+        else:
+            raise ValidationError(
+                self.error_messages['empty_data'],
+                code='empty_data',
+            )
 
 
         return self.cleaned_data
         return self.cleaned_data
 
 
@@ -45,6 +54,8 @@ class AdminAuthenticationForm(AuthenticationForm):
             'not_staff': _("Your account does not have admin privileges.")
             'not_staff': _("Your account does not have admin privileges.")
             })
             })
 
 
+        super(AdminAuthenticationForm, self).__init__(*args, **kwargs)
+
     def confirm_login_allowed(self, user):
     def confirm_login_allowed(self, user):
         if not user.is_staff:
         if not user.is_staff:
             raise forms.ValidationError(
             raise forms.ValidationError(

+ 2 - 2
misago/users/views/auth.py

@@ -13,10 +13,10 @@ from misago.users.forms.auth import AuthenticationForm
 @csrf_protect
 @csrf_protect
 @never_cache
 @never_cache
 def login(request):
 def login(request):
-    form = AuthenticationForm()
+    form = AuthenticationForm(request)
 
 
     if request.method == 'POST':
     if request.method == 'POST':
-        form = AuthenticationForm(request.POST)
+        form = AuthenticationForm(request, data=request.POST)
         if form.is_valid():
         if form.is_valid():
             pass
             pass