This commit is contained in:
Hubert Jankowski 2022-01-31 21:00:29 +01:00
parent 8d3de9283e
commit 999ae564b8
4 changed files with 39 additions and 19 deletions

View File

@ -9,6 +9,11 @@
<input type="password" id="newPassword" name="newPassword" class="form-control" placeholder="Nowe hasło" required><br><br>
<input type="password" id="repeatPassword" name="repeatPassword" class="form-control" placeholder="Powtórz hasło" required><br><br>
<input type="submit" value="Zmień hasło"><br><br>
{% if messages %}
{% for message in messages %}
<div class="alert {% if message.tags %} alert-{{ message.tags }}{% endif %}">{{ message|safe }}</div>
{% endfor %}
{% endif %}
</form>
<div class="linkDefault">
<a href="{% url 'account' %}">Wróć</a>

View File

@ -17,12 +17,18 @@
</p>
{% endfor %}
<input type="submit" value="Zaloguj się">
{% if messages %}
{% for message in messages %}
<div class="alert {% if message.tags %} alert-{{ message.tags }}{% endif %}">{{ message|safe }}</div>
{% endfor %}
{% endif %}
<div class="linkDefault">
<a href="{% url 'resetPassword' %}">Zapomniałem hasła</a>
</div>
<div class="linkDefault">
<a href="{% url 'welcome' %}">Wróć</a>
</div>
</form>
{% endblock %}

View File

@ -262,7 +262,7 @@ class TestModelViewSet(viewsets.ModelViewSet):
class TestTemplateView(TemplateView):
PASSED = "Zaliczony"
FAILED = "Nie zaliczony"
FAILED = "Niezaliczony"
UNKNOWN = "nieznany"
PASSED = {

View File

@ -18,6 +18,7 @@ from django.contrib.auth.decorators import login_required
from django.contrib.auth import logout as django_logout
from rest_framework.renderers import TemplateHTMLRenderer
from rest_framework.views import APIView
from django.contrib.auth.hashers import make_password
class UserModelViewSet(viewsets.ModelViewSet):
@ -106,20 +107,23 @@ def login_success(request):
def login(request):
context = {}
if request.POST:
form = AuthenticationForm(request.POST)
username = request.POST.get("username")
password = request.POST.get("password")
try:
context = {}
if request.POST:
form = AuthenticationForm(request.POST)
username = request.POST.get("username")
password = request.POST.get("password")
user = SettingsBackend().authenticate(request, email=username, password=password)
if user is not None:
auth_login(request, user)
return redirect('home')
context['login_form'] = form
else:
form = AuthenticationForm()
context['login_form'] = form
user = SettingsBackend().authenticate(request, email=username, password=password)
if user is not None:
auth_login(request, user)
return redirect('home')
context['login_form'] = form
else:
form = AuthenticationForm()
context['login_form'] = form
except:
return render(request, 'login.html', {"messages": {"Podano błędne dane logowania lub użytkownik nie istnieje.": ""}})
return render(request, 'login.html', context)
@ -162,11 +166,16 @@ def changePassword(request):
oldPassword = request.POST.get("oldPassword")
newPassword = request.POST.get("newPassword")
repeatPassword = request.POST.get("repeatPassword")
if not request.user.check_password(oldPassword):
message = {"Błędne hasło użytkownika.": ""}
return render(request, 'changePassword.html', {"messages": message})
# u = request.user
# u.first_name = firstName
# u.last_name = lastName
# u.save()
if newPassword != repeatPassword:
message = {"Nowe hasła nie są identyczne.": ""}
return render(request, 'changePassword.html', {"messages": message})
request.user.password = make_password(newPassword)
request.user.save()
return redirect('account')
return render(request, 'changePassword.html')
@ -216,7 +225,7 @@ class ResetPasswordConfirm(generics.GenericAPIView):
def post(self, request):
serializer = UserPasswordResetConfirmSerializer(data=request.data)
serializer.is_valid()
return redirect('/users/login.html')
return redirect('/users/login')
def resetPasswordConfirm(request):