fixes #30

Merged
s470631 merged 1 commits from fix/latest-fixes into master 2022-01-31 21:02:18 +01:00
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="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="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> <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> </form>
<div class="linkDefault"> <div class="linkDefault">
<a href="{% url 'account' %}">Wróć</a> <a href="{% url 'account' %}">Wróć</a>

View File

@ -17,12 +17,18 @@
</p> </p>
{% endfor %} {% endfor %}
<input type="submit" value="Zaloguj się"> <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"> <div class="linkDefault">
<a href="{% url 'resetPassword' %}">Zapomniałem hasła</a> <a href="{% url 'resetPassword' %}">Zapomniałem hasła</a>
</div> </div>
<div class="linkDefault"> <div class="linkDefault">
<a href="{% url 'welcome' %}">Wróć</a> <a href="{% url 'welcome' %}">Wróć</a>
</div> </div>
</form> </form>
{% endblock %} {% endblock %}

View File

@ -262,7 +262,7 @@ class TestModelViewSet(viewsets.ModelViewSet):
class TestTemplateView(TemplateView): class TestTemplateView(TemplateView):
PASSED = "Zaliczony" PASSED = "Zaliczony"
FAILED = "Nie zaliczony" FAILED = "Niezaliczony"
UNKNOWN = "nieznany" UNKNOWN = "nieznany"
PASSED = { 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 django.contrib.auth import logout as django_logout
from rest_framework.renderers import TemplateHTMLRenderer from rest_framework.renderers import TemplateHTMLRenderer
from rest_framework.views import APIView from rest_framework.views import APIView
from django.contrib.auth.hashers import make_password
class UserModelViewSet(viewsets.ModelViewSet): class UserModelViewSet(viewsets.ModelViewSet):
@ -106,20 +107,23 @@ def login_success(request):
def login(request): def login(request):
context = {} try:
if request.POST: context = {}
form = AuthenticationForm(request.POST) if request.POST:
username = request.POST.get("username") form = AuthenticationForm(request.POST)
password = request.POST.get("password") username = request.POST.get("username")
password = request.POST.get("password")
user = SettingsBackend().authenticate(request, email=username, password=password) user = SettingsBackend().authenticate(request, email=username, password=password)
if user is not None: if user is not None:
auth_login(request, user) auth_login(request, user)
return redirect('home') return redirect('home')
context['login_form'] = form context['login_form'] = form
else: else:
form = AuthenticationForm() form = AuthenticationForm()
context['login_form'] = form 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) return render(request, 'login.html', context)
@ -162,11 +166,16 @@ def changePassword(request):
oldPassword = request.POST.get("oldPassword") oldPassword = request.POST.get("oldPassword")
newPassword = request.POST.get("newPassword") newPassword = request.POST.get("newPassword")
repeatPassword = request.POST.get("repeatPassword") 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 if newPassword != repeatPassword:
# u.first_name = firstName message = {"Nowe hasła nie są identyczne.": ""}
# u.last_name = lastName return render(request, 'changePassword.html', {"messages": message})
# u.save()
request.user.password = make_password(newPassword)
request.user.save()
return redirect('account') return redirect('account')
return render(request, 'changePassword.html') return render(request, 'changePassword.html')
@ -216,7 +225,7 @@ class ResetPasswordConfirm(generics.GenericAPIView):
def post(self, request): def post(self, request):
serializer = UserPasswordResetConfirmSerializer(data=request.data) serializer = UserPasswordResetConfirmSerializer(data=request.data)
serializer.is_valid() serializer.is_valid()
return redirect('/users/login.html') return redirect('/users/login')
def resetPasswordConfirm(request): def resetPasswordConfirm(request):