diff --git a/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc b/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc index 3b77f07..00e5188 100644 Binary files a/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc and b/SocialHelper/homepage/__pycache__/urls.cpython-37.pyc differ diff --git a/SocialHelper/homepage/__pycache__/views.cpython-37.pyc b/SocialHelper/homepage/__pycache__/views.cpython-37.pyc index 14affb7..36c4abb 100644 Binary files a/SocialHelper/homepage/__pycache__/views.cpython-37.pyc and b/SocialHelper/homepage/__pycache__/views.cpython-37.pyc differ diff --git a/SocialHelper/homepage/templates/homepage/edit_user.html b/SocialHelper/homepage/templates/homepage/edit_user.html new file mode 100644 index 0000000..6195942 --- /dev/null +++ b/SocialHelper/homepage/templates/homepage/edit_user.html @@ -0,0 +1,159 @@ +{% extends 'base.html' %} +{% load static %} +{% block content %} + + + + + +
+
+
+

Zmień hasło

+
+
+
+ + + +
+ {% csrf_token %} + {{ form.media }} + {{ form.as_p }} + + +
+
+
+ + +
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+ +
+
+
+ + +
+
+
+ +
+
+
+ +
+
+
+ + +
+
+
+ + + + + + + + + + {% endblock %} diff --git a/SocialHelper/homepage/templates/homepage/my_offer.html b/SocialHelper/homepage/templates/homepage/my_offer.html index a7338ad..013ff42 100644 --- a/SocialHelper/homepage/templates/homepage/my_offer.html +++ b/SocialHelper/homepage/templates/homepage/my_offer.html @@ -62,7 +62,9 @@

No polls are available.

{% endif %} -
+
+ +
diff --git a/SocialHelper/homepage/urls.py b/SocialHelper/homepage/urls.py index 70791ff..d9246cb 100644 --- a/SocialHelper/homepage/urls.py +++ b/SocialHelper/homepage/urls.py @@ -24,5 +24,6 @@ urlpatterns = [ path('delete_user', views.delete_user, name='delete_user'), path('logout_user', views.logout_user, name='logout_user'), path('/delete_user', views.delete_user, name='delete_user'), + path('edit_user', views.edit_user, name='edit_user'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/SocialHelper/homepage/views.py b/SocialHelper/homepage/views.py index 861ee1d..0d132ab 100644 --- a/SocialHelper/homepage/views.py +++ b/SocialHelper/homepage/views.py @@ -361,8 +361,50 @@ def delete_user(request): messages.success(request,'Konto skasowane!') return redirect(index) -def edit_user(request, user_id): - return True +def edit_user(request): + User = get_user_model() + instant = User.objects.filter(id=request.user.id).first() + if request.method == 'POST': + + oldpassword = request.POST['oldpassword'] + newpassword1 = request.POST['newpassword1'] + newpassword2 = request.POST['newpassword2'] + user = authenticate(request, username=instant.username, password=oldpassword, is_active=True) + if user is None: + messages.error(request,'Podałeś złe hasło') + return redirect('edit_user') + + dlugosc = 0 + znak = 0 + duza = 0 + mala = 0 + cyfra = 0 + for i in newpassword1: + if i in "1234567890": + cyfra = 1 + elif i in "QWERTYUIOPASDFGHJKLZXCVBNM": + duza = 1 + elif i in "qwertyuiopasdfghjklzxcvbnm": + mala = 1 + elif i in "!@#$%&*(){}[]<>?": + znak = 1 + if len(newpassword1) >= 8: + dlugosc = 1 + + if dlugosc+znak+mala+duza+cyfra != 5: + messages.error(request,'Podane hasło jest nieprawidłowe. Hasło musi zawierać conajmniej: 1 cyfre, 1 duza litere, 1 mala litere, 1 znak specjalny z zakresu !@#$%&*(){}[]<>?, oraz składać sie conajmniej z 8 symboli') + return redirect('edit_user') + + if newpassword1 != newpassword2: + messages.error(request,'Podane nowe hasła są różne') + return redirect('edit_user') + + instant.set_password(newpassword1) + instant.save() + messages.success(request,'Hasło zmienione, nastąpiło wylogowanie!') + return redirect('my_offer') + + return render(request , 'homepage/edit_user.html') def login(request): if request.method == 'POST':