From 74e76fe6e778a322b1b66cdb4d7f347aaa1f92ee Mon Sep 17 00:00:00 2001 From: SDE Date: Sun, 9 Jun 2024 16:37:08 +0300 Subject: [PATCH] 1.2.0 confirm email after registration --- AuthApp/js_views.py | 24 +++++--- AuthApp/urls.py | 6 +- AuthApp/views.py | 55 +++++++++++++++++- templates/mail/m_confirm_email.html | 87 +++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+), 13 deletions(-) create mode 100644 templates/mail/m_confirm_email.html diff --git a/AuthApp/js_views.py b/AuthApp/js_views.py index dab5410..2b40fe8 100644 --- a/AuthApp/js_views.py +++ b/AuthApp/js_views.py @@ -466,24 +466,24 @@ def login_ajax(request): - -def send_registration_mail(data_Dict, user): +def send_check_email_after_registration(data_Dict, user): try: from GeneralApp.funcs_options import get_options_by_opt_types, get_mail_send_options sets = get_options_by_opt_types(['domain', 'project_name'], only_vals=True) - subject = _('Добро пожаловать в Trip With Bonus!') + subject = _('Trip With Bonus - Подтверждение регистрации ') Dict = { 'logo': f'{sets["domain"]}/static/img/svg/LogoMobile.svg', 'project_name': sets['project_name'], + 'domain': sets['domain'], 'message_title': subject, } Dict.update(data_Dict) - html = render_to_string('mail/m_registration.html', Dict) + html = render_to_string('mail/m_confirm_email.html', Dict) from BaseModels.mailSender import admin_send_mail_by_SMTPlib mail_sets = get_mail_send_options() to = [user.email, 'web@syncsystems.net', 'sa@a3-global.com', 'sysadmin.hax@gmail.com'] @@ -501,6 +501,9 @@ def send_registration_mail(data_Dict, user): + + + def registration_ajax(request): if request.method != 'POST': raise Http404 @@ -528,26 +531,29 @@ def registration_ajax(request): 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, backend='django.contrib.auth.backends.ModelBackend') + # if user: + # auth.login(request, user, backend='django.contrib.auth.backends.ModelBackend') if 'mailingSubscribeRequired' in data and data['mailingSubscribeRequired'] == 'true': user.user_profile.mailing_on = True user.last_name = form.data['lastname'] user.first_name = form.data['firstname'] + user.is_active = False user.save() user.user_profile.phone = form.data['tel'] + user.user_profile.authMailCode = uuid1().hex user.user_profile.save() mail_Dict = { 'user': user, - 'pass': form.data['password'] } - res = send_registration_mail(mail_Dict, user) + + res = send_check_email_after_registration(mail_Dict, user) + # res = send_registration_mail(mail_Dict, user) res_Dict = { - 'redirect_url': reverse('profile_page', args=['dashboard']) + # 'redirect_url': reverse('profile_page', args=['dashboard']) } return JsonResponse(res_Dict) diff --git a/AuthApp/urls.py b/AuthApp/urls.py index 6bb962e..5135d0c 100644 --- a/AuthApp/urls.py +++ b/AuthApp/urls.py @@ -46,9 +46,9 @@ urlpatterns = [ # # # ----------------------- # - # url(r'^check_user_registration_and_activate/(?P[\d+]*)/(?P[0-9a-z\+\-\_]+)$', - # check_user_registration_and_activate, - # name='check_user_registration_and_activate'), + path('check_user_registration_and_activate///', + check_user_registration_and_activate, + name='check_user_registration_and_activate'), # # # url(r'^user/password/reset/$', # # 'django.contrib.auth.views.password_reset', diff --git a/AuthApp/views.py b/AuthApp/views.py index f3a4ccc..695251e 100644 --- a/AuthApp/views.py +++ b/AuthApp/views.py @@ -5,7 +5,8 @@ from django.shortcuts import render from uuid import uuid1 from AuthApp.models import * from django.contrib import auth -from django.http import HttpResponse, Http404 +from django.urls import reverse +from django.http import HttpResponse, Http404, HttpResponseRedirect from django.template import loader, RequestContext from django.contrib.auth.decorators import login_required from BaseModels.mailSender import techSendMail @@ -16,6 +17,58 @@ from .funcs import * from GeneralApp.funcs import get_inter_http_respose from GeneralApp.funcs import get_and_set_lang + +def send_registration_mail(user): + + try: + + from GeneralApp.funcs_options import get_options_by_opt_types, get_mail_send_options + sets = get_options_by_opt_types(['domain', 'project_name'], only_vals=True) + + subject = _('Добро пожаловать в Trip With Bonus!') + + Dict = { + 'logo': f'{sets["domain"]}/static/img/svg/LogoMobile.svg', + 'project_name': sets['project_name'], + 'message_title': subject, + 'user': user + } + + html = render_to_string('mail/m_registration.html', Dict) + from BaseModels.mailSender import admin_send_mail_by_SMTPlib + mail_sets = get_mail_send_options() + to = [user.email, 'web@syncsystems.net', 'sa@a3-global.com', 'sysadmin.hax@gmail.com'] + res = admin_send_mail_by_SMTPlib( + mail_sets, + subject=subject, + from_email=mail_sets['sender_email'], to=to, + html_content=html + ) + + return res + except Exception as e: + print(f'send_registration_mail Error = {str(e)}') + return None + +def check_user_registration_and_activate(request, user_id, authMailCode): + try: + user = User.objects.get( + id=user_id, + is_active=False, + user_profile__authMailCode=authMailCode + ) + user.is_active = True + user.save(update_fields=['is_active']) + + res = send_registration_mail(user) + + return HttpResponseRedirect(reverse('login_profile')) + except User.DoesNotExist: + user = None + + raise Http404 + + def registration_View(request): Dict = {} diff --git a/templates/mail/m_confirm_email.html b/templates/mail/m_confirm_email.html new file mode 100644 index 0000000..49912f4 --- /dev/null +++ b/templates/mail/m_confirm_email.html @@ -0,0 +1,87 @@ +{% load i18n %} + + +
+
+
+ {{ project_name }} +
+

+ {{ message_title|safe }} +

+
+

{% translate "Здравствуйте" %}{% if user.first_name %}, {{ user.first_name }}{% endif %}!

+ +

{% translate "На сайте" %} tripwb.com {% translate "произведена регистрация с использованием Вашего адреса электронной почты." %}.

+ +

{% translate "Если это сделали Вы, нажмите на ссылку ниже и пройдите процедуру верификации." %} ссылка на верификацию

+ +

{% translate "Если это письмо ошибочно попало к Вам, просто проигнорируйте его." %}

+ +

+ {% blocktrans %} + С уважением,
+ Команда Trip With Bonus.
+ {% endblocktrans %} +

+ + +
+ {% for button in message_buttons %} + + {% endfor %} + + +
+
+
+{# Адрес кафе: Минск, ул. Будславская, 2#} +{#
#} +{# График работы: пн-вс 12:00 - 24:00#} +{#
#} +{# Телефоны кафе: +375 44 77 321 77#} +
+
+ + + +
+
\ No newline at end of file