From 957065a09113e69fb9d06c07ada7929536078c03 Mon Sep 17 00:00:00 2001 From: SDE Date: Thu, 22 Jun 2023 22:17:01 +0300 Subject: [PATCH] 0.0.11 profile page --- AuthApp/js_views.py | 21 ++++++++++++++------- AuthApp/urls.py | 1 + AuthApp/views.py | 13 +++++++++++++ templates/forms/f_registration.html | 12 ++++++------ templates/pages/p_user_profile.html | 10 ++++++++++ 5 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 templates/pages/p_user_profile.html diff --git a/AuthApp/js_views.py b/AuthApp/js_views.py index 19a9cca..63041b2 100644 --- a/AuthApp/js_views.py +++ b/AuthApp/js_views.py @@ -26,16 +26,23 @@ def registration_ajax(request): html = render_to_string('forms/f_registration.html', Dict) return JsonResponse({'html': html}, status=400) + user = User.objects.create_user(username=form.data['email'], email=form.data['email'], password=form.data['password']) + # user = auth.authenticate(username=new_user_Dict['name'], password=new_user_Dict['pass']) + if user: + auth.login(request, user) - res_data = { - 'errors': 'тестовый верный ответ' - } + res_Dict = {} + + JsonResponse(res_Dict) except Exception as e: - res_data = { - 'errors': f'ошибка в запросе = {str(e)}' + errors_Dict = { + 'errors': { + '__all__': f'ошибка в запросе = {str(e)}' + } } + Dict = {'form': errors_Dict} + html = render_to_string('forms/f_registration.html', Dict) + return JsonResponse({'html': html}, status=400) - - return JsonResponse(res_data) \ No newline at end of file diff --git a/AuthApp/urls.py b/AuthApp/urls.py index a6f259f..fd11a63 100644 --- a/AuthApp/urls.py +++ b/AuthApp/urls.py @@ -8,6 +8,7 @@ from django.contrib.auth import views urlpatterns = [ path('registration/', registration_View, name='registration_page'), + path('profile/', user_profile_View, name='user_profile'), # ajax ---------------- # url(r'^login$', user_login_View_ajax, name='user_login_View_ajax'), diff --git a/AuthApp/views.py b/AuthApp/views.py index 9ae9fa2..597095f 100644 --- a/AuthApp/views.py +++ b/AuthApp/views.py @@ -21,6 +21,19 @@ def registration_View(request): return HttpResponse(t.render(Dict, request)) +def user_profile_View(request): + + Dict = {} + + t = loader.get_template('pages/p_user_profile.html') + return HttpResponse(t.render(Dict, request)) + + + + + + + def create_personal_user(data, creator): try: diff --git a/templates/forms/f_registration.html b/templates/forms/f_registration.html index 7cb895a..652f8a1 100644 --- a/templates/forms/f_registration.html +++ b/templates/forms/f_registration.html @@ -9,27 +9,27 @@
{% 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 %} diff --git a/templates/pages/p_user_profile.html b/templates/pages/p_user_profile.html new file mode 100644 index 0000000..566549b --- /dev/null +++ b/templates/pages/p_user_profile.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file