fixes
This commit is contained in:
parent
8d3de9283e
commit
999ae564b8
@ -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>
|
||||||
|
@ -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 %}
|
||||||
|
|
||||||
|
@ -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,6 +107,7 @@ def login_success(request):
|
|||||||
|
|
||||||
|
|
||||||
def login(request):
|
def login(request):
|
||||||
|
try:
|
||||||
context = {}
|
context = {}
|
||||||
if request.POST:
|
if request.POST:
|
||||||
form = AuthenticationForm(request.POST)
|
form = AuthenticationForm(request.POST)
|
||||||
@ -120,6 +122,8 @@ def login(request):
|
|||||||
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):
|
||||||
|
Loading…
Reference in New Issue
Block a user