From fddea097d3f530c5c3d54b767679ae5950f34660 Mon Sep 17 00:00:00 2001 From: ArtemB Date: Fri, 20 Sep 2024 18:16:00 +0300 Subject: [PATCH] 1.2.6 password recovery TRI-108 --- AuthApp/views.py | 2 +- static/css/styles.css | 13 ++- static/js/authorization.js | 10 +- static/js/registration.js | 17 ++- static/js/user_profile.js | 7 ++ templates/forms/f_login.html | 23 ++++ templates/forms/f_password_recovery.html | 107 ++++++++++++++++++ .../pages/profile/p_password_recovery.html | 10 ++ 8 files changed, 180 insertions(+), 9 deletions(-) create mode 100644 templates/forms/f_password_recovery.html create mode 100644 templates/pages/profile/p_password_recovery.html diff --git a/AuthApp/views.py b/AuthApp/views.py index a9bb308..4d5980a 100644 --- a/AuthApp/views.py +++ b/AuthApp/views.py @@ -288,7 +288,7 @@ def recovery_password_page_View(request, user_id, token): 'user': user } - t = loader.get_template('pages/profile/p_user_profile.html') + t = loader.get_template('pages/profile/p_password_recovery.html') response = get_inter_http_response(t, Dict, request) return response diff --git a/static/css/styles.css b/static/css/styles.css index 74408ca..f1a5a3b 100644 --- a/static/css/styles.css +++ b/static/css/styles.css @@ -1303,7 +1303,8 @@ section.login>form { color: rgba(39, 36, 36, 0.60); } .call_to_reg { - + cursor: pointer; + text-align: center; color: rgba(39, 36, 36, 0.60); font-style: normal; font-weight: 500; @@ -3365,6 +3366,16 @@ details[open] summary ~ *{ /*END news articles all*/ +.login_form.hide{ + display: none; +} +.password_recovery{ + display: none; +} +.password_recovery.show{ + display: block; +} + diff --git a/static/js/authorization.js b/static/js/authorization.js index e6cca7a..da0a6c3 100644 --- a/static/js/authorization.js +++ b/static/js/authorization.js @@ -3,14 +3,18 @@ function SendLoginForm(el){ event.preventDefault() let form = el.form; let formData = new FormData(form); - let msr = sessionStorage.getItem('mailingSubscribeRequired') - formData.set('mailingSubscribeRequired',msr) + let url = '/user_account/password_recovery/' + if(!el.classList.contains('recovery')){ + url = '/user_account/login/' + let msr = sessionStorage.getItem('mailingSubscribeRequired') + formData.set('mailingSubscribeRequired',msr) + } $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, - url: '/user_account/login/', + url: url, type: "POST", // async: true, cache: false, diff --git a/static/js/registration.js b/static/js/registration.js index a747787..817fd19 100644 --- a/static/js/registration.js +++ b/static/js/registration.js @@ -1,13 +1,19 @@ -function SendRegistrationForm(el){ +function SendRegistrationForm(el, user_id){ event.preventDefault() let form = el.form; let formData = new FormData(form); - let msr = sessionStorage.getItem('mailingSubscribeRequired') - formData.set('mailingSubscribeRequired',msr) + let url = '/user_account/password_recovery_confirm/' + formData.set('user_id', user_id) + if(!el.classList.contains('recovery')){ + url = '/user_account/registration/'; + let msr = sessionStorage.getItem('mailingSubscribeRequired') + formData.set('mailingSubscribeRequired',msr) + } + $.ajax({ headers: { "X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val() }, - url: '/user_account/registration/', + url: url, type: "POST", // async: true, cache: false, @@ -16,6 +22,9 @@ function SendRegistrationForm(el){ // enctype: 'json', data: formData, success: function(data){ + + document.getElementById('confirm_password').innerHTML = data.message + document.querySelector('.info_text').classList.add('show') // location.href = `/profile/page/dashboard/` window.sessionStorage.removeItem('mailingSubscribeRequired') diff --git a/static/js/user_profile.js b/static/js/user_profile.js index 55e7154..02fcba0 100644 --- a/static/js/user_profile.js +++ b/static/js/user_profile.js @@ -1395,6 +1395,13 @@ function showTabBtn(el) { } +function showForm(){ + let hide_form = document.getElementsByClassName('login_form') + let show_form = document.getElementsByClassName('password_recovery') + hide_form[0].classList.add('hide') + show_form[0].classList.add('show') +} + diff --git a/templates/forms/f_login.html b/templates/forms/f_login.html index 8a861d6..f035b5f 100644 --- a/templates/forms/f_login.html +++ b/templates/forms/f_login.html @@ -49,6 +49,29 @@ {% endif %}
{% translate "Нет аккаунта?" %} {% translate "Зарегистрируйтесь" %}
+
{% translate "Восстановить пароль" %}
+ + + +
+ {% csrf_token %} + +
+ + {% if form.username and form.errors.username %} + {{ form.errors.username }} + {% endif %} +
+
+ + +
\ No newline at end of file diff --git a/templates/forms/f_password_recovery.html b/templates/forms/f_password_recovery.html new file mode 100644 index 0000000..6e19556 --- /dev/null +++ b/templates/forms/f_password_recovery.html @@ -0,0 +1,107 @@ +{% load i18n %} + +{% trans "Пароль *" as p_password %} +{% trans "Подтвердить пароль *" as p_con_password %} + +
+

{% translate "Восстановление пароля" %}

+ + +
+ {% csrf_token %} + +
+
+ + + {% if form.errors and form.errors.password %} + {{ form.errors.password }} + {% endif %} +
+ +
+ + {% if form.errors and form.errors.confirm_password %} + {{ form.errors.confirm_password }} + {% endif %} +
+ +
+ +
+ +
+ +
+
+ + + +{##} +{##} +{#
#} +{#

Регистрация

#} +{##} +{#
#} +{##} +{# #} +{# #} +{##} +{#
#} +{#
#} +{# #} +{# #} +{#
#} +{##} +{#
#} +{# {% csrf_token %}#} +{#
#} +{# #} +{# {% if form.errors and form.errors.firstname %}#} +{# {{ form.errors.firstname }}#} +{# {% endif %}#} +{# #} +{# {% if form.errors and form.errors.email %}#} +{# {{ form.errors.email }}#} +{# {% endif %}#} +{# #} +{# {% if form.errors and form.errors.password %}#} +{# {{ form.errors.password }}#} +{# {% endif %}#} +{# #} +{# {% if form.errors and form.errors.lastname %}#} +{# {{ form.errors.lastname }}#} +{# {% endif %}#} +{# #} +{# {% if form.errors and form.errors.tel %}#} +{# {{ form.errors.tel }}#} +{# {% endif %}#} +{# #} +{# {% if form.errors and form.errors.confirm_password %}#} +{# {{ form.errors.confirm_password }}#} +{# {% endif %}#} +{#
#} +{##} +{#

Регистрируясь, я соглашаюсь с Лицензионным соглашениеми и Политикой конфиденциальности

#} +{##} +{#
#} +{# #} +{#
#} +{#
#} +{##} +{##} +{##} +{#
#} \ No newline at end of file diff --git a/templates/pages/profile/p_password_recovery.html b/templates/pages/profile/p_password_recovery.html new file mode 100644 index 0000000..df11e9f --- /dev/null +++ b/templates/pages/profile/p_password_recovery.html @@ -0,0 +1,10 @@ +{% extends 'tb_base.html' %} +{% load static %} + +{% block meta %} + +{% endblock %} + +{% block content %} + {% include 'forms/f_password_recovery.html' %} +{% endblock %} \ No newline at end of file