1.7.0 password recovery
This commit is contained in:
@@ -23,6 +23,8 @@ urlpatterns = [
|
|||||||
|
|
||||||
path('support_tickets/', support_tickets_ajax, name='support_tickets_ajax'),
|
path('support_tickets/', support_tickets_ajax, name='support_tickets_ajax'),
|
||||||
|
|
||||||
|
path('password_recovery/', password_recovery_ajax, name='password_recovery_ajax'),
|
||||||
|
path('password_recovery_confirm/', password_recovery_confirm_ajax, name='password_recovery_confirm_ajax'),
|
||||||
|
|
||||||
path('change_profile/', change_profile_ajax, name='change_profile_ajax'),
|
path('change_profile/', change_profile_ajax, name='change_profile_ajax'),
|
||||||
path('change_profile_confirm/', change_profile_confirm_ajax, name='change_profile_confirm_ajax'),
|
path('change_profile_confirm/', change_profile_confirm_ajax, name='change_profile_confirm_ajax'),
|
||||||
|
|||||||
@@ -31,6 +31,120 @@ from GeneralApp.funcs import get_and_set_lang
|
|||||||
# html = render_to_string('blocks/profile/b_subscribe.html', Dict, request=request)
|
# html = render_to_string('blocks/profile/b_subscribe.html', Dict, request=request)
|
||||||
# return JsonResponse({'html': html}, status=200)
|
# return JsonResponse({'html': html}, status=200)
|
||||||
|
|
||||||
|
def password_recovery_confirm_ajax(request):
|
||||||
|
if request.method != 'POST':
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
if not request.POST['pass'] or not request.POST['pass_confirm'] or not request.POST['user_id']:
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
lang = get_and_set_lang(request)
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
if request.POST['pass'] != request.POST['pass_confirm']:
|
||||||
|
return JsonResponse({
|
||||||
|
'status': 'error',
|
||||||
|
'error': _('Пароли не совпадают')
|
||||||
|
}, status=400)
|
||||||
|
|
||||||
|
user = User.objects.get(id=request.POST['user_id'])
|
||||||
|
user.set_password(request.POST['pass'])
|
||||||
|
|
||||||
|
return JsonResponse({
|
||||||
|
'status': 'success',
|
||||||
|
'message': _('Пароль был успешно изменен')
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return JsonResponse({
|
||||||
|
'status': 'error',
|
||||||
|
'error': str(e)
|
||||||
|
}, status=400)
|
||||||
|
|
||||||
|
def password_recovery_ajax(request):
|
||||||
|
if request.method != 'POST':
|
||||||
|
raise Http404
|
||||||
|
|
||||||
|
lang = get_and_set_lang(request)
|
||||||
|
|
||||||
|
try:
|
||||||
|
email = request.POST['email']
|
||||||
|
|
||||||
|
try:
|
||||||
|
user = User.objects.get(email=email)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
return JsonResponse({
|
||||||
|
'status': 'error',
|
||||||
|
'error': _('Пользователь с указанным email не зарегистрирован на сайте')
|
||||||
|
}, status=400)
|
||||||
|
|
||||||
|
user.user_profile.authMailCode = uuid1().hex
|
||||||
|
user.user_profile.save(update_fields=['authMailCode'])
|
||||||
|
|
||||||
|
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 = _('Восстановление пароля учетной записи на сайте tripwb.com')
|
||||||
|
|
||||||
|
mail_txt = _('Вы получили это письмо потому что '
|
||||||
|
'был произведен запрос на восстановление пароля '
|
||||||
|
'для данного email на сайте tripwb.com.<br>'
|
||||||
|
'<br>'
|
||||||
|
'Если Вы не выполняли запрос - просто проигнорируйте это письмо.<br><br>'
|
||||||
|
'Если же это были Вы и Вам требуется восстановить пароль от учетной записи - '
|
||||||
|
'перейдите по ссылке, указанной ниже.<br><br>')
|
||||||
|
link = sets["domain"] + f'reset_password/{str(user.id)}/{user.user_profile.authMailCode}/<br><br>'
|
||||||
|
|
||||||
|
sign_txt = _('Спасибо за то, что вы с нами!<br>'
|
||||||
|
'С уважением,<br>'
|
||||||
|
'Команда Trip With Bonus.<br>')
|
||||||
|
|
||||||
|
Dict = {
|
||||||
|
'logo': f'{sets["domain"]}/static/img/svg/LogoMobile.svg',
|
||||||
|
'project_name': sets['project_name'],
|
||||||
|
'message_title': subject,
|
||||||
|
'message_text': f'<p><b>{_("ДАННЫЕ ЗАПРОСА")}</b></p>'
|
||||||
|
f'<p style="padding-left: 20px; line-height: 30px;">'
|
||||||
|
f'{mail_txt}'
|
||||||
|
f'{link}'
|
||||||
|
f'{sign_txt}'
|
||||||
|
f'</p>'
|
||||||
|
}
|
||||||
|
|
||||||
|
html = render_to_string('mail/m_request_offer.html', Dict, request)
|
||||||
|
from BaseModels.mailSender import admin_send_mail_by_SMTPlib
|
||||||
|
mail_sets = get_mail_send_options()
|
||||||
|
to = [email]
|
||||||
|
res = admin_send_mail_by_SMTPlib(
|
||||||
|
mail_sets,
|
||||||
|
subject=subject,
|
||||||
|
from_email=mail_sets['sender_email'], to=to,
|
||||||
|
html_content=html
|
||||||
|
)
|
||||||
|
to = ['web@syncsystems.net']
|
||||||
|
res = admin_send_mail_by_SMTPlib(
|
||||||
|
mail_sets,
|
||||||
|
subject=subject,
|
||||||
|
from_email=mail_sets['sender_email'], to=to,
|
||||||
|
html_content=html
|
||||||
|
)
|
||||||
|
|
||||||
|
return JsonResponse({
|
||||||
|
'status': 'sended',
|
||||||
|
'message': _('На email') + ' ' + email + ' '
|
||||||
|
+ _('отправлено письмо с инструкциями для восстановления пароля')
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
return JsonResponse({
|
||||||
|
'status': 'error',
|
||||||
|
'error': str(e)
|
||||||
|
}, status=400)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def mailing_subscribe_ajax(request):
|
def mailing_subscribe_ajax(request):
|
||||||
if request.method != 'POST':
|
if request.method != 'POST':
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ from django.contrib.auth import views
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
|
||||||
path('registration/', registration_View, name='registration_page'),
|
path('registration/', registration_View, name='registration_page'),
|
||||||
|
|
||||||
|
path('reset_password/<int:user_id>/<str:token>/',
|
||||||
|
recovery_password_page_View, name='recovery_password_page'),
|
||||||
# path('', user_profile_View, name='user_profile'),
|
# path('', user_profile_View, name='user_profile'),
|
||||||
# path('page/chat/<int:user_id>/', chat_w_user_View, name='chat_w_user'),
|
# path('page/chat/<int:user_id>/', chat_w_user_View, name='chat_w_user'),
|
||||||
# path('page/chat/', chat_w_user_View, name='chat_w_user_wo_user_id'),
|
# path('page/chat/', chat_w_user_View, name='chat_w_user_wo_user_id'),
|
||||||
|
|||||||
@@ -278,12 +278,19 @@ def decode_get_param(data):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def recovery_password_user(request, uidb64=None, token=None):
|
def recovery_password_page_View(request, user_id, token):
|
||||||
from django.contrib.auth.views import PasswordResetConfirmView
|
try:
|
||||||
|
user = User.objects.get(id=user_id, user_profile__authMailCode=token)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
raise Http404
|
||||||
|
|
||||||
return PasswordResetConfirmView(request=request, uidb64=uidb64, token=token
|
Dict = {
|
||||||
)
|
'user': user
|
||||||
|
}
|
||||||
|
|
||||||
|
t = loader.get_template('pages/profile/p_user_profile.html')
|
||||||
|
response = get_inter_http_response(t, Dict, request)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,25 @@ from django.contrib import admin
|
|||||||
class Admin_Route(Admin_Trans_BaseModel):
|
class Admin_Route(Admin_Trans_BaseModel):
|
||||||
readonly_fields = ['highlight_end_DT', 'rising_DT']
|
readonly_fields = ['highlight_end_DT', 'rising_DT']
|
||||||
list_display = [
|
list_display = [
|
||||||
'id', 'owner_type', 'receive_msg_by_email', 'type_transport', 'cargo_type',
|
'id', 'owner_type',
|
||||||
|
'rising_DT',
|
||||||
|
'receive_msg_by_email', 'type_transport', 'cargo_type',
|
||||||
'departure_DT', 'from_city', 'from_place',
|
'departure_DT', 'from_city', 'from_place',
|
||||||
'arrival_DT', 'to_city', 'to_place', 'owner',
|
'arrival_DT', 'to_city', 'to_place', 'owner',
|
||||||
'order', 'modifiedDT', 'createDT'
|
'order', 'modifiedDT', 'createDT'
|
||||||
]
|
]
|
||||||
|
list_editable = ['rising_DT']
|
||||||
|
|
||||||
list_display_links = ['id']
|
list_display_links = ['id']
|
||||||
|
|
||||||
list_filter = ['owner_type', 'type_transport', 'cargo_type', 'from_place', 'arrival_DT', 'modifiedDT', 'createDT']
|
list_filter = [
|
||||||
|
'owner_type', 'type_transport',
|
||||||
|
'rising_DT',
|
||||||
|
'cargo_type',
|
||||||
|
'from_place', 'arrival_DT',
|
||||||
|
'modifiedDT', 'createDT'
|
||||||
|
]
|
||||||
|
|
||||||
search_fields = [
|
search_fields = [
|
||||||
'owner__first_name', 'owner__last_name', 'from_city__name', 'to_city__name'
|
'owner__first_name', 'owner__last_name', 'from_city__name', 'to_city__name'
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ from .models import *
|
|||||||
from .forms import *
|
from .forms import *
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from django.db.models import F
|
from django.db.models import F, Q
|
||||||
|
|
||||||
elements_on_page = 25
|
elements_on_page = 25
|
||||||
|
|
||||||
@@ -258,6 +258,12 @@ def get_routes_Dict(user=None, data=None):
|
|||||||
# rising_DT=None
|
# rising_DT=None
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
routes_rising_off = Route.objects.exclude(rising_DT=None).filter(
|
||||||
|
Q(rising_DT__lt=datetime.now() - timedelta(days=1)) | Q(departure_DT__lt=datetime.now())
|
||||||
|
)
|
||||||
|
if routes_rising_off:
|
||||||
|
routes_rising_off.update(rising_DT=None)
|
||||||
|
|
||||||
routes = Route.objects.filter(
|
routes = Route.objects.filter(
|
||||||
**kwargs
|
**kwargs
|
||||||
).order_by(
|
).order_by(
|
||||||
|
|||||||
Reference in New Issue
Block a user