registration fixes

This commit is contained in:
Alicja Cięciwa
2020-11-15 13:32:50 +01:00
parent 0525450a90
commit 3ffce6c7c3
15 changed files with 117 additions and 63 deletions

8
.idea/workspace.xml generated
View File

@@ -3,7 +3,13 @@
<component name="ChangeListManager">
<list default="true" id="15f590a5-5017-44f1-a85e-17dfe3fc5379" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/static/css/main.css" beforeDir="false" afterPath="$PROJECT_DIR$/static/css/main.css" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Lib/site-packages/django/contrib/auth/forms.py" beforeDir="false" afterPath="$PROJECT_DIR$/Lib/site-packages/django/contrib/auth/forms.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Lib/site-packages/django/contrib/auth/password_validation.py" beforeDir="false" afterPath="$PROJECT_DIR$/Lib/site-packages/django/contrib/auth/password_validation.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/accounts/forms.py" beforeDir="false" afterPath="$PROJECT_DIR$/accounts/forms.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/accounts/views.py" beforeDir="false" afterPath="$PROJECT_DIR$/accounts/views.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/urls.py" beforeDir="false" afterPath="$PROJECT_DIR$/config/urls.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/base.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/base.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/work/views.py" beforeDir="false" afterPath="$PROJECT_DIR$/work/views.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />

View File

@@ -85,19 +85,19 @@ class UserCreationForm(forms.ModelForm):
password.
"""
error_messages = {
'password_mismatch': _('The two password fields didnt match.'),
'password_mismatch': _('Hasła się nie zgadzają'),
}
password1 = forms.CharField(
label=_("Password"),
label="",
strip=False,
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
help_text=password_validation.password_validators_help_text_html(),
help_text=None,
)
password2 = forms.CharField(
label=_("Password confirmation"),
label="",
widget=forms.PasswordInput(attrs={'autocomplete': 'new-password'}),
strip=False,
help_text=_("Enter the same password as before, for verification."),
help_text=None,
)
class Meta:
@@ -109,6 +109,32 @@ class UserCreationForm(forms.ModelForm):
super().__init__(*args, **kwargs)
if self._meta.model.USERNAME_FIELD in self.fields:
self.fields[self._meta.model.USERNAME_FIELD].widget.attrs['autofocus'] = True
self.fields['username'].help_text = None
self.fields['username'] = forms.CharField(
widget=forms.TextInput(attrs={
'placeholder': 'Nazwa użytkownika'
}),
error_messages={
'required': 'Wpisz nazwę użytkownika',
})
self.fields['password1'] = forms.CharField(
widget=forms.PasswordInput(attrs={
'placeholder': 'Hasło'
}),
error_messages={
'required': 'Podaj hasło',
})
self.fields['password2'] = forms.CharField(
widget=forms.PasswordInput(attrs={
'placeholder': 'Powtórz hasło'
}),
error_messages={
'required': 'Podaj hasło',
})
for field in ['username', 'password1', 'password2']:
self.fields[field].help_text = None
self.fields[field].label = ''
def clean_password2(self):
password1 = self.cleaned_data.get("password1")

View File

@@ -99,8 +99,8 @@ class MinimumLengthValidator:
if len(password) < self.min_length:
raise ValidationError(
ngettext(
"This password is too short. It must contain at least %(min_length)d character.",
"This password is too short. It must contain at least %(min_length)d characters.",
"Hasło jest zbyt krótkie - musi zawierać przynajmniej %(min_length)d znaków.",
"Hasło jest zbyt krótkie - musi zawierać przynajmniej %(min_length)d znaków.",
self.min_length
),
code='password_too_short',
@@ -109,8 +109,8 @@ class MinimumLengthValidator:
def get_help_text(self):
return ngettext(
"Your password must contain at least %(min_length)d character.",
"Your password must contain at least %(min_length)d characters.",
"Hasło musi zawierać przynajmniej %(min_length)d znaków.",
"Hasło musi zawierać przynajmniej %(min_length)d znaków.",
self.min_length
) % {'min_length': self.min_length}
@@ -148,7 +148,7 @@ class UserAttributeSimilarityValidator:
except FieldDoesNotExist:
verbose_name = attribute_name
raise ValidationError(
_("The password is too similar to the %(verbose_name)s."),
_("Hasło jest zbyt podobne do %(verbose_name)s."),
code='password_too_similar',
params={'verbose_name': verbose_name},
)
@@ -180,7 +180,7 @@ class CommonPasswordValidator:
def validate(self, password, user=None):
if password.lower().strip() in self.passwords:
raise ValidationError(
_("This password is too common."),
_("To hasło jest zbyt powszechne."),
code='password_too_common',
)

View File

@@ -3,40 +3,40 @@ from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class RegisterForm(UserCreationForm):
class Meta:
model = User
fields = ['username', 'password1', 'password2']
def __init__(self, *args, **kwargs):
super(RegisterForm, self).__init__(*args, **kwargs)
self.fields['username'] = forms.CharField(
widget=forms.TextInput(attrs={
'placeholder': 'Nazwa użytkownika'
}),
error_messages={
'required': 'Wpisz nazwę użytkownika',
})
self.fields['password1'] = forms.CharField(
widget=forms.PasswordInput(attrs={
'placeholder': 'Hasło'
}),
error_messages={
'required': 'Podaj hasło',
})
self.fields['password2'] = forms.CharField(
widget=forms.PasswordInput(attrs={
'placeholder': 'Powtórz hasło'
}),
error_messages={
'required': 'Podaj hasło',
})
for field in ['username', 'password1', 'password2']:
self.fields[field].help_text = None
self.fields[field].label = ''
# class RegisterForm(UserCreationForm):
#
# class Meta:
# model = User
# fields = ['username', 'password1', 'password2']
#
# def __init__(self, *args, **kwargs):
# super(RegisterForm, self).__init__(*args, **kwargs)
# self.fields['username'] = forms.CharField(
# widget=forms.TextInput(attrs={
# 'placeholder': 'Nazwa użytkownika'
# }),
# error_messages={
# 'required': 'Wpisz nazwę użytkownika',
# })
# self.fields['password1'] = forms.CharField(
# widget=forms.PasswordInput(attrs={
# 'placeholder': 'Hasło'
# }),
# error_messages={
# 'required': 'Podaj hasło',
# })
# self.fields['password2'] = forms.CharField(
# widget=forms.PasswordInput(attrs={
# 'placeholder': 'Powtórz hasło'
# }),
# error_messages={
# 'required': 'Podaj hasło',
# })
#
# for field in ['username', 'password1', 'password2']:
# self.fields[field].help_text = None
# self.fields[field].label = ''
#

View File

@@ -1,14 +1,21 @@
from django.shortcuts import render, redirect
from .forms import RegisterForm
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout
def register(response):
@login_required
def sign_up(request):
title = "Rejestracja"
if response.method == "POST":
form = RegisterForm(response.POST)
form = UserCreationForm(request.POST or None)
if request.method == "POST":
if form.is_valid():
form.save()
return redirect("/")
else:
form = RegisterForm()
return render(response, "registration/signup.html", {"form": form, 'title': title})
user = form.save()
return redirect("/")
return render(request, 'registration/signup.html', {"form": form, 'title': title})
def logout_view(request):
logout(request)
return redirect('/accounts/login')

View File

@@ -15,14 +15,23 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path, include
from work import views
from work import views as work_views
from accounts import views as accounts_views
from django.contrib.auth import views
# from django.contrib.auth import views as auth_views
from django.conf.urls import url
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('django.contrib.auth.urls')),
path('', views.get_basic_workdata, name='home'),
path('register/', accounts_views.register, name='register'),
path('', work_views.get_basic_workdata, name='home'),
path('accounts/sign_up/', accounts_views.sign_up, name='sign-up'),
path('accounts/login/', views.LoginView.as_view(), name='login'),
path('accounts/logout/', accounts_views.logout_view, name='logout'),
# path('accounts/logout/', views.LogoutView.as_view(), name='logout'),
]

View File

@@ -42,14 +42,14 @@
</li>
<!--Dodaj godziny-->
<li class="nav-item">
<a class="nav-link" href="/">Dodaj godziny</a>
<a class="nav-link" href="{% url 'home' %}">Dodaj godziny</a>
</li>
{% load auth_extras %}
{% if request.user|has_group:"moderators" %}
<!--Dodaj pracownika-->
<li class="nav-item">
<a class="nav-link" href="/register">Dodaj pracownika</a>
<a class="nav-link" href="{% url 'sign-up' %}">Dodaj pracownika</a>
</li>
{% endif %}
</ul>
@@ -62,7 +62,7 @@
<!-- <div class="text-right">-->
<img src="{% static 'img/usericon.png' %}" width="17" alt="user"
class="d-inline-block mr-1"> {{ user.username }}
<a href="{% url 'login' %}" class="btn btn-sm btn-secondary text-nowrap btn-logout">Wyloguj</a>
<a href="{% url 'logout' %}" class="btn btn-sm btn-secondary text-nowrap btn-logout">Wyloguj</a>
<!-- </div>-->
{% endif %}
</li>

View File

@@ -1,10 +1,16 @@
from django.http import HttpResponseRedirect
from django.shortcuts import render
from work.forms import HoursInputForm
from django.contrib.auth.decorators import login_required
#
# @login_required
# def index(request):
# return render(request,'registration/login.html')
@login_required
def get_basic_workdata(request):
title = None
title = "Godziny"
if request.method == 'POST':
form = HoursInputForm(request.POST)
if form.is_valid():