Fixes login form

This commit is contained in:
Mouse Reeve 2021-01-04 10:48:48 -08:00
parent 3fe7b95786
commit 81e60cea16
4 changed files with 9 additions and 8 deletions

View file

@ -35,7 +35,7 @@ class CustomForm(ModelForm):
class LoginForm(CustomForm): class LoginForm(CustomForm):
class Meta: class Meta:
model = models.User model = models.User
fields = ['username', 'password'] fields = ['localname', 'password']
help_texts = {f: None for f in fields} help_texts = {f: None for f in fields}
widgets = { widgets = {
'password': PasswordInput(), 'password': PasswordInput(),

View file

@ -119,15 +119,15 @@
</div> </div>
{% else %} {% else %}
<div class="navbar-item"> <div class="navbar-item">
{% if request.path != '/login' and request.path != '/login/' %} {% if request.path != '/login' and request.path != '/login/' and request.path != '/user-login' %}
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<form name="login" method="post" action="/user-login"> <form name="login" method="post" action="/user-login">
{% csrf_token %} {% csrf_token %}
<div class="field is-grouped"> <div class="field is-grouped">
<div class="control"> <div class="control">
<label class="is-sr-only" for="id_username">Username:</label> <label class="is-sr-only" for="id_localname">Username:</label>
<input type="text" name="username" maxlength="150" class="input" required="" id="id_username" placeholder="username"> <input type="text" name="localname" maxlength="150" class="input" required="" id="id_localname" placeholder="username">
</div> </div>
<div class="control"> <div class="control">
<label class="is-sr-only" for="id_password">Username:</label> <label class="is-sr-only" for="id_password">Username:</label>

View file

@ -11,9 +11,9 @@
<form name="login" method="post" action="/user-login"> <form name="login" method="post" action="/user-login">
{% csrf_token %} {% csrf_token %}
<div class="field"> <div class="field">
<label class="label" for="id_username">Username:</label> <label class="label" for="id_localname">Username:</label>
<div class="control"> <div class="control">
{{ login_form.username }} {{ login_form.localname }}
</div> </div>
</div> </div>
<div class="field"> <div class="field">

View file

@ -30,8 +30,9 @@ def user_login(request):
''' authenticate user login ''' ''' authenticate user login '''
login_form = forms.LoginForm(request.POST) login_form = forms.LoginForm(request.POST)
username = login_form.data['username'] print(login_form.data)
username = '%s@%s' % (username, DOMAIN) localname = login_form.data['localname']
username = '%s@%s' % (localname, DOMAIN)
password = login_form.data['password'] password = login_form.data['password']
user = authenticate(request, username=username, password=password) user = authenticate(request, username=username, password=password)
if user is not None: if user is not None: