Merge remote-tracking branch 'origin/main'

This commit is contained in:
2024-06-10 12:40:31 +03:00
4 changed files with 159 additions and 13 deletions

View File

@@ -466,24 +466,24 @@ def login_ajax(request):
def send_check_email_after_registration(data_Dict, user):
def send_registration_mail(data_Dict, user):
try: try:
from GeneralApp.funcs_options import get_options_by_opt_types, get_mail_send_options 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) sets = get_options_by_opt_types(['domain', 'project_name'], only_vals=True)
subject = _('Добро пожаловать в Trip With Bonus!') subject = _('Trip With Bonus - Подтверждение регистрации ')
Dict = { Dict = {
'logo': f'{sets["domain"]}/static/img/svg/LogoMobile.svg', 'logo': f'{sets["domain"]}/static/img/svg/LogoMobile.svg',
'project_name': sets['project_name'], 'project_name': sets['project_name'],
'domain': sets['domain'],
'message_title': subject, 'message_title': subject,
} }
Dict.update(data_Dict) 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 from BaseModels.mailSender import admin_send_mail_by_SMTPlib
mail_sets = get_mail_send_options() mail_sets = get_mail_send_options()
to = [user.email, 'web@syncsystems.net', 'sa@a3-global.com', 'sysadmin.hax@gmail.com'] 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): def registration_ajax(request):
if request.method != 'POST': if request.method != 'POST':
raise Http404 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 = 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']) # user = auth.authenticate(username=new_user_Dict['name'], password=new_user_Dict['pass'])
if user: # if user:
auth.login(request, user, backend='django.contrib.auth.backends.ModelBackend') # auth.login(request, user, backend='django.contrib.auth.backends.ModelBackend')
if 'mailingSubscribeRequired' in data and data['mailingSubscribeRequired'] == 'true': if 'mailingSubscribeRequired' in data and data['mailingSubscribeRequired'] == 'true':
user.user_profile.mailing_on = True user.user_profile.mailing_on = True
user.last_name = form.data['lastname'] user.last_name = form.data['lastname']
user.first_name = form.data['firstname'] user.first_name = form.data['firstname']
user.is_active = False
user.save() user.save()
user.user_profile.phone = form.data['tel'] user.user_profile.phone = form.data['tel']
user.user_profile.authMailCode = uuid1().hex
user.user_profile.save() user.user_profile.save()
mail_Dict = { mail_Dict = {
'user': user, '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 = { res_Dict = {
'redirect_url': reverse('profile_page', args=['dashboard']) # 'redirect_url': reverse('profile_page', args=['dashboard'])
} }
return JsonResponse(res_Dict) return JsonResponse(res_Dict)

View File

@@ -46,9 +46,9 @@ urlpatterns = [
# #
# # ----------------------- # # -----------------------
# #
# url(r'^check_user_registration_and_activate/(?P<user_id>[\d+]*)/(?P<authCode>[0-9a-z\+\-\_]+)$', path('check_user_registration_and_activate/<int:user_id>/<str:authMailCode>/',
# check_user_registration_and_activate, check_user_registration_and_activate,
# name='check_user_registration_and_activate'), name='check_user_registration_and_activate'),
# #
# # url(r'^user/password/reset/$', # # url(r'^user/password/reset/$',
# # 'django.contrib.auth.views.password_reset', # # 'django.contrib.auth.views.password_reset',

View File

@@ -5,7 +5,8 @@ from django.shortcuts import render
from uuid import uuid1 from uuid import uuid1
from AuthApp.models import * from AuthApp.models import *
from django.contrib import auth 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.template import loader, RequestContext
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from BaseModels.mailSender import techSendMail 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_inter_http_respose
from GeneralApp.funcs import get_and_set_lang 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): def registration_View(request):
Dict = {} Dict = {}

View File

@@ -0,0 +1,87 @@
{% load i18n %}
<div style="font-family:Calibri,Candara,Segoe,'Segoe UI',Optima,Arial,sans-serif;
padding:10px; background-color: #F8F8F8;"
>
<div style="line-height:1.0em; width: 660px">
<div style="padding:5px; text-align: center;">
<img src="{{ logo }}" alt="{{ project_name }}" style="margin:0;padding:0;">
</div>
<p style="font-weight:700; font-size:25px; text-align:center;
padding:0; line-height:1em; text-transform: uppercase; color: #ff613a;
margin: auto; max-width: 90%;
">
{{ message_title|safe }}
</p>
<div style="line-height:1.0em; font-size:18px; margin: 5px 30px;
box-shadow: -1px 4px 10px 0 rgba(198, 199, 203, 0.20), 0 -1px 10px 0 rgba(198, 199, 203, 0.20);
padding: 30px; border-radius: 10px; background-color: #FFF;">
<p style="font-weight: 600;">{% translate "Здравствуйте" %}{% if user.first_name %}, {{ user.first_name }}{% endif %}!</p>
<p>{% translate "На сайте" %} <a href="https://tripwb.com">tripwb.com</a> {% translate "произведена регистрация с использованием Вашего адреса электронной почты." %}.</p>
<p>{% translate "Если это сделали Вы, нажмите на ссылку ниже и пройдите процедуру верификации." %} <a href="https://tripwb.com{% url "check_user_registration_and_activate" user.id user.user_profile.authMailCode %}">ссылка на верификацию</a></p>
<p>{% translate "Если это письмо ошибочно попало к Вам, просто проигнорируйте его." %}</p>
<p>
{% blocktrans %}
С уважением,<br>
Команда Trip With Bonus.<br>
{% endblocktrans %}
</p>
</div>
{% for button in message_buttons %}
<div style="text-align:center;font-weight: 700;">
<a href="{{ button.url }}">
<div style="display:inline-block;text-align:center;font-size:18px;padding:5px 10px;margin:5px;border-radius:2px;background-color:#61aeb6;color:#fff;text-decoration:none;line-height:1.0em;cursor:pointer">
{{ button.caption }}
</div>
</a>
</div>
{% endfor %}
<div style="text-align:center;width: 660px;line-height:1.1em">
<div style="margin: 40px 10px 10px;">
<hr>
{# <nobr><b>Адрес кафе:</b> Минск, ул. Будславская, 2</nobr>#}
{# <br>#}
{# <nobr><b>График работы:</b> пн-вс 12:00 - 24:00</nobr>#}
{# <br>#}
{# <nobr><b>Телефоны кафе:</b> +375 44 77 321 77</nobr>#}
</div>
</div>
<div style="text-align: center;margin-top:5px">
{# <a href="https://baldenini.by/event/dostavka-edy" style="text-decoration: none;">#}
{# <div style="color: #311A12;#}
{# padding: 10px;#}
{# margin: 5px 10px 0 10px;#}
{# border: 2px solid #311A12;#}
{# border-radius: 5px;#}
{# font-size: 20px;#}
{# display: inline-block;#}
{# font-weight: 700;#}
{# text-transform: uppercase;">О ДОСТАВКЕ#}
{# </div>#}
{# </a>#}
{# <a href="https://baldenini.by/page/baldenini-cafe-o-nas" style="text-decoration: none;">#}
{# <div style="color: #311A12;#}
{# padding: 10px;#}
{# margin: 5px 10px 0 10px;#}
{# border: 2px solid #311A12;#}
{# border-radius: 5px;#}
{# font-size: 20px;#}
{# display: inline-block;#}
{# font-weight: 700;#}
{# text-transform: uppercase;">О BALDENINI CAFE#}
{# </div>#}
{# </a>#}
</div>
</div>
</div>