From fdeed92ab66c91b7f3d616ec03e73bd0269cf64b Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 15 Feb 2018 18:32:21 +0300 Subject: [PATCH] =?UTF-8?q?update=20api=20=D0=BF=D1=80=D0=BE=D1=85=D0=BE?= =?UTF-8?q?=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- access/models/user.py | 3 +- access/views.py | 23 +++++- finance/signals.py | 160 +++++++++++++++++++++--------------------- lms/settings.py | 12 +--- storage/views.py | 22 ++---- 5 files changed, 112 insertions(+), 108 deletions(-) diff --git a/access/models/user.py b/access/models/user.py index af2cf77..ef82924 100644 --- a/access/models/user.py +++ b/access/models/user.py @@ -2,6 +2,7 @@ import random import string import uuid +from django.conf import settings from django.contrib.auth.base_user import BaseUserManager, AbstractBaseUser from django.contrib.auth.models import Group, PermissionsMixin from django.core.mail import send_mail @@ -73,7 +74,7 @@ class CustomUserManager(BaseUserManager): Вы были успешны зарегистрированны на портале go.skillbox.ru ваш пароль %s для подтверждения регистрации перейдите по ссылке - https://go.skillbox.ru/api/v1/users/registration/?hash=%s''' %(password, invite.hash), + %s/api/v1/users/registration/?hash=%s''' % (password, settings.DOMAIN, invite.hash), "from_email": 'robo@skillbox.ru', "recipient_list": [user.email], } diff --git a/access/views.py b/access/views.py index 171c260..40543e5 100644 --- a/access/views.py +++ b/access/views.py @@ -3,6 +3,7 @@ import random import string from django.contrib import auth +from django.conf import settings from django.contrib.auth import get_user_model from django.core.mail import send_mail from django.db.models import Q @@ -74,8 +75,8 @@ class ResetPasswordView(APIView): message=''' Ваш новый пароль %s, (в последствии вы сможите сменить его в личном кабинете), если вы не отправляли заявку на сброс пароля просто проигнорируйте это сообщение, - для подтверждения смены пароля перейдите по https://go.skillbox.ru/api/v1/users/reset/?hash=%s - (ссылке ссылка действительна в течении 5 минут)''' % (invite.password, invite.hash), + для подтверждения смены пароля перейдите по %s/api/v1/users/reset/?hash=%s + (ссылке ссылка действительна в течении 5 минут)''' % (invite.password, settings.DOMAIN, invite.hash), from_email='robo@skillbox.ru', recipient_list=[user.email], ) @@ -118,6 +119,24 @@ class FindUserView(APIView): class DetailUserView(APIView): renderer_classes = (JSONRenderer,) + @staticmethod + def post(request, pk=None): + if pk is None: + return Response("out_key mast be set", status=400) + + if not request.user.out_key == pk: + return Response("You can't change this profile", status=403) + + f_n = request.JSON.get('first_name', None) + l_n = request.JSON.get('last_name', None) + + acc = request.JSON.get('account', None) + + serialized_user = UserSelfSerializer(request.user).data + serialized_user['is_i'] = True + + return Response(serialized_user, status=200) + @staticmethod def get(request, pk=None): if pk is None: diff --git a/finance/signals.py b/finance/signals.py index 5082a19..6b88d88 100644 --- a/finance/signals.py +++ b/finance/signals.py @@ -1,79 +1,81 @@ -# from django.core.mail import EmailMessage -# from django.db.models.signals import pre_save, post_save -# from django.dispatch import receiver -# from yandex_money.models import Payment -# -# from finance.models import Invoice -# from access.models.other import Progress -# from course_service.maps.api import OutApiRoute -# -# api = OutApiRoute -# -# -# @receiver(pre_save, sender=Invoice) -# def invoice_signal(instance, **kwargs): -# """Отправка сообщения после сохранения платежа""" -# if instance.yandex_pay and instance.method == 'Y' and instance.status == 'P': -# msg = EmailMessage( -# 'Вам выставлен новый счёт', -# '''Вам выставлен счёт, для оплаты перейдите по ссылке -# https://go.skillbox.ru/api/v1/finance/payment/%s/''' % instance.yandex_pay.id, -# 'robo@skillbox.ru', -# [instance.yandex_pay.cps_email], -# [instance.bill.opener.email], -# reply_to=[instance.bill.opener.email], -# ) -# msg.send() -# -# if instance.status == 'F': -# if instance.is_open: -# Progress.objects.get_or_create( -# route=instance.bill.route, -# user=instance.bill.user, -# ) -# msg = EmailMessage( -# 'Ваш платёж прошёл успешно', -# '''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и -# ознакомиться с материалами https://go.skillbox.ru/course/%s''' -# % (api.get_route(instance.bill.route).name, api.get_route(instance.bill.route).course.slug), -# 'robo@skillbox.ru', -# [instance.bill.user.email], -# cc=[instance.bill.opener.email], -# reply_to=[instance.bill.opener.email], -# ) -# else: -# msg = EmailMessage( -# 'Ваш платёж прошёл успешно', -# '''Курс "%s" был забронирован''' % instance.bill.course.title, -# 'robo@skillbox.ru', -# [instance.yandex_pay.cps_email], -# cc=[instance.bill.opener.email], -# reply_to=[instance.bill.opener.email], -# ) -# msg.send() -# -# if instance.status == 'C': -# msg = EmailMessage( -# 'Ошибка платежа!' -# """Внимание не прошёл платёж пользавателю %s, -# по курсу "%s" ID платежа: %s. Если не получается -# решить проблему самостоятельно, ответьте на это письмо, -# постарайтесь подробно описать последовательность действий, -# которая привела к ошибке""" -# % (instance.bill.user.get_full_name(), api.get_route(instance.bill.route).course.title, instance.id), -# instance.bill.opener.email, -# reply_to=["it@skillbox.ru"] -# ) -# msg.send() -# -# -# @receiver(post_save, sender=Payment) -# def access_pay(instance, **kwargs): -# if instance.status == 'success': -# instance.invoice.status = "F" -# instance.invoice.real_price = instance.shop_amount -# instance.invoice.save() -# -# if instance.status == 'fail': -# instance.invoice.status = "C" -# instance.invoice.save() +from django.core.mail import EmailMessage +from django.db.models.signals import pre_save, post_save +from django.dispatch import receiver +from yandex_money.models import Payment +from django.conf import settings + +from finance.models import Invoice +from courses.models import Course +from progress.models import Progress + + +@receiver(pre_save, sender=Invoice) +def invoice_signal(instance, **kwargs): + """Отправка сообщения после сохранения платежа""" + + course = Course.objects.get(token=instance.bill.course_token) + + if instance.yandex_pay and instance.method == 'Y' and instance.status == 'P': + msg = EmailMessage( + 'Вам выставлен новый счёт', + '''Вам выставлен счёт, для оплаты перейдите по ссылке + %s/api/v1/finance/payment/%s/''' % (settings.DOMAIN, instance.yandex_pay.id,), + 'robo@skillbox.ru', + [instance.yandex_pay.cps_email], + [instance.bill.opener.email], + reply_to=[instance.bill.opener.email], + ) + msg.send() + + if instance.status == 'F': + if instance.is_open: + Progress.objects.get_or_create( + course_token=instance.bill.course_token, + user=instance.bill.user, + ) + msg = EmailMessage( + 'Ваш платёж прошёл успешно', + '''Вам открыт доступ к курсу "%s", вы можете перейти по ссылке и + ознакомиться с материалами %s/course/%s''' + % (course.title, settings.DOMAIN, course.slug), + 'robo@skillbox.ru', + [instance.bill.user.email], + cc=[instance.bill.opener.email], + reply_to=[instance.bill.opener.email], + ) + else: + msg = EmailMessage( + 'Ваш платёж прошёл успешно', + '''Курс "%s" был забронирован''' % instance.bill.course.title, + 'robo@skillbox.ru', + [instance.yandex_pay.cps_email], + cc=[instance.bill.opener.email], + reply_to=[instance.bill.opener.email], + ) + msg.send() + + if instance.status == 'C': + msg = EmailMessage( + 'Ошибка платежа!' + """Внимание не прошёл платёж пользавателю %s, + по курсу "%s" ID платежа: %s. Если не получается + решить проблему самостоятельно, ответьте на это письмо, + постарайтесь подробно описать последовательность действий, + которая привела к ошибке""" + % (instance.bill.user.get_full_name(), course.title, instance.id), + instance.bill.opener.email, + reply_to=["it@skillbox.ru"] + ) + msg.send() + + +@receiver(post_save, sender=Payment) +def access_pay(instance, **kwargs): + if instance.status == 'success': + instance.invoice.status = "F" + instance.invoice.real_price = instance.shop_amount + instance.invoice.save() + + if instance.status == 'fail': + instance.invoice.status = "C" + instance.invoice.save() diff --git a/lms/settings.py b/lms/settings.py index e588ab5..00314ef 100644 --- a/lms/settings.py +++ b/lms/settings.py @@ -50,17 +50,7 @@ AUTH_USER_MODEL = 'access.User' VZAAR = 'f1e965defc6fbaa92c544cf84267e830' SMS = '5ED9C6BB-41E8-C760-10FA-F8A310D88952' ALLOWED_HOSTS = ['*'] -DOMAIN = 'https://go.skillbox.ru' - -BILL_LOGIN = '1501' -BILL_URL = 'https://api.simplepay.pro/sp/payment' -BILL_KEY = u'848360a6b0b8cdfaca3603ede75e4d8b' -BILL_RESULT_KEY = u'82a513fc6a0bd9cb087e0df4be5520f6' -BILL_TOKEN = u'c63fc7fdc74de318e1f9b078b6d4406a3e62f522b00fb305afe61c0ead238eb9c88dcab6b324727537fe5c1631cba3a9bcb76955364aa269334b42fb4099d236' -AMO_USER_LOGIN = 'baryshnikov@mokselle.com' -AMO_USER_HASH = 'd639c26c1c1900e5a8cee66cd3395bdc' -AMO_SUBDOMAIN = 'mokselle' -DEFAULT_FROM_EMAIL = 'robo@skillbox.ru' +DOMAIN = "http://31.186.103.4" #'https://go.skillbox.ru' YANDEX_MONEY_DEBUG = False YANDEX_MONEY_SCID = '149639' diff --git a/storage/views.py b/storage/views.py index 347dd7c..55770d6 100644 --- a/storage/views.py +++ b/storage/views.py @@ -44,20 +44,12 @@ class CommentView(APIView): @staticmethod def get(request): - tokens = request.GET.getlist('tokens', None) - - if not tokens: - return Response("Attribute tokens not set", status=400) + token = request.GET.get('token', None) - if tokens == ["null"]: - return Response([], status=200) - - comment_list = [] - - for token in tokens: - try: - comment_list.append(CommentSerializer(Comment.objects.get(token=token)).data) - except Comment.DoesNotExist: - comment_list.append({'upload': 'error'}) + if not token: + return Response("Attribute token not set", status=400) - return Response(comment_list, status=200) \ No newline at end of file + try: + return Response(CommentSerializer(Comment.objects.get(token=token)).data, status=200) + except Comment.DoesNotExist: + return Response("Comment not found", status=404)