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