コード例 #1
0
    def get(self, request, *args, **kwargs):
        try:
            fund = Fund.objects.get(pk=self.kwargs['pk'])
        except Exception as error:
            return Response(ReturnResponse.Response(1, __name__,
                                                    "Invalid Fund",
                                                    error).return_json(),
                            status=status.HTTP_200_OK)
        try:
            fundCurrency = FundCurrency.objects.filter(
                fund=fund).order_by('-rebalance__pk')[0:1].get()
        except Exception as error:
            return Response(ReturnResponse.Response(2, __name__,
                                                    "Invalid FundCurrency",
                                                    error).return_json(),
                            status=status.HTTP_200_OK)

        news = []
        newsfeed = NewsFeed.NewsFeed(XCHANGE['CRYPTOPANIC'])
        for record in FundCurrency.objects.filter(fund=fund).order_by(
                '-rebalance__pk')[:fundCurrency.rebalance.num_of_coins]:
            try:
                currency = Currency.objects.using('coins').get(
                    pk=record.currency)
            except Exception as error:
                logger.error("{0}".format(error))
                return Response(ReturnResponse.Response(
                    3, __name__, "No currency", error).return_json(),
                                status=status.HTTP_200_OK)
            news.append(newsfeed.get_news_feed(currency.symbol))
        return Response(ReturnResponse.Response(0, __name__, json.dumps(news),
                                                0).return_json(),
                        status=status.HTTP_200_OK)
コード例 #2
0
    def create(self, request, *args, **kwargs):
        serializer = RegisterAffiliateSerializer(data=request.data)

        try:
            serializer.is_valid(raise_exception=True)
            register_affiliate = serializer.save()
        except serializers.ValidationError as error:
            result = '{0}:'.format(error)
            logger.error("Serializer Error: {0}: error:{1}".format(
                serializer.errors, result))
            return Response(ReturnResponse.Response(
                1, __name__, 'Email Address Already Exists',
                result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)
        except Exception as error:
            result = 'Failed parsing JSon:{0}'.format(request)
            logger.error("{0} error{1}: Serialize Error:{2}".format(
                result, error, register_affiliate.errors))
            return Response(ReturnResponse.Response(1, __name__,
                                                    'Failed parsing Json',
                                                    result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        my_email = MyEmail.MyEmail('Register Affiliate')

        result = my_email.send_register_affiliate_email(register_affiliate)
        logger.debug(result)
        return Response(ReturnResponse.Response(1, __name__, 'success',
                                                result).return_json(),
                        status=status.HTTP_201_CREATED)
コード例 #3
0
    def create(self, request, *args, **kwargs):
        serializer = RegisterSerializer(data=request.data)

        try:
            serializer.is_valid(raise_exception=True)
            register_user = serializer.save(ipAddress=get_client_ip(request))
        except serializers.ValidationError as error:
            logger.error("Failed Serializing User:{0}: error:{1}".format(
                request.data, serializer.errors))
            return Response(ReturnResponse.Response(
                1, __name__, 'Email Address Already Exists',
                error).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)
        except Exception as error:
            logger.error('Failed parsing JSon:{0} Error:{1}'.format(
                request, error))
            return Response(ReturnResponse.Response(1, __name__,
                                                    'Failed parsing Json',
                                                    error).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        my_email = MyEmail.MyEmail('Verify Email')

        result = my_email.send_verify_email(register_user)
        logger.debug(result)
        return Response(ReturnResponse.Response(1, __name__, 'success',
                                                result).return_json(),
                        status=status.HTTP_201_CREATED)
コード例 #4
0
    def post(self, request, *args, **kwargs):
        try:
            braintree_visamc_transaction = BraintreeVisaMCTransactionSerializer(
                data=request.data)
        except Exception as error:
            return Response(ReturnResponse.Response(1, __name__, 'failed',
                                                    error).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)
        try:
            braintree_visamc_transaction.is_valid(raise_exception=True)
            instance = braintree_visamc_transaction.save(
                user_profile=request.user.user_profile)
            braintree = BrainTreeProcessor.BraintreeGateway()
            result = braintree.depositVisaMC(instance)

            deposit_transaction = DepositTransaction(
                user_profile=request.user.user_profile,
                deposit_status=DepositTransactionStatus.objects.get(
                    pk=DEPOSIT_STATUS['SETTLED']),
                payment_gateway=PaymentGateway.objects.get(
                    pk=PAYMENT_GATEWAYS['BRAINTREE']),
                deposit_type=DepositTransactionType.objects.get(
                    pk=DEPOSIT_TYPE['VISA']),
                deposit_id=instance.id)
            deposit_transaction.save()
        except Exception as error:
            return Response(ReturnResponse.Response(1, __name__, 'failed',
                                                    error).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)
        return Response(ReturnResponse.Response(1, __name__, 'success',
                                                result).return_json(),
                        status=status.HTTP_200_OK)
コード例 #5
0
    def post(self, request):
        news_letter = ""

        if NewsLetter.objects.filter(email=request.data['email']).exists():
            result = "Email exists."
            logger.error(result)
            return Response(ReturnResponse.Response(1, __name__,
                                                    "Subscription Failed",
                                                    result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        try:
            news_letter = NewsLetterSerializer(data=request.data,
                                               many=False,
                                               partial=True)
            news_letter.is_valid(raise_exception=True)
        except Exception as error:
            result = 'Failed to parse JSON:{0}:{1}'.format(request, error)
            logger.error(result)
            return Response(ReturnResponse.Response(1, __name__,
                                                    "Subscription Failed",
                                                    result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        news_letter.save()
        result = "Joined Mailing List"
        logger.error(result + request.data['email'])
        return Response(ReturnResponse.Response(0, __name__,
                                                "Subscription Successful",
                                                result).return_json(),
                        status=status.HTTP_201_CREATED)
コード例 #6
0
ファイル: MyEmail.py プロジェクト: kevinstotz/DimeAPI
    def load_text_template(self, template_filename):

        filename = join(EMAIL_TEMPLATE_DIR, template_filename)

        with open(filename, "r", encoding="utf8") as template:
            self.bodyText = template.read()
        if len(self.bodyText) > 10:
            result = 'Read Email Template:{0}'.format(filename)
            logger.debug(result)
            return ReturnResponse.Response(0, __name__, 'success',
                                           result).return_json()
        else:
            result = 'Failed Reading Email Template:{0}'.format(filename)
            logger.critical(result)
            return ReturnResponse.Response(1, __name__, 'failed',
                                           result).return_json()
コード例 #7
0
ファイル: views.py プロジェクト: kevinstotz/DimeAPI
 def post(self, request, *args, **kwargs):
     result = '{"redirect_to":"' + DASHBOARD_HOSTNAME_URL + '"}'
     logger.error(result)
     return Response(ReturnResponse.Response(1, __name__,
                                             "Login Successful",
                                             result).return_json(),
                     status=status.HTTP_200_OK)
コード例 #8
0
ファイル: views.py プロジェクト: kevinstotz/DimeAPI
 def post(self, request, *args, **kwargs):
     pp = PayPalProcessor.PayPalProcessor()
     pp.createPayment()
     logger.info("Paypal payment created")
     return Response(ReturnResponse.Response(0, __name__, 'success',
                                             "0").return_json(),
                     status=status.HTTP_201_CREATED)
コード例 #9
0
ファイル: views.py プロジェクト: kevinstotz/DimeAPI
 def post(self, request):
     if not request.data['Username']:
         return Response(ReturnResponse.Response(1, __name__, 'error',
                                                 0).return_json(),
                         status=status.HTTP_400_BAD_REQUEST)
     if len(request.data['Username']) <= 5:
         return Response(ReturnResponse.Response(1, __name__, 'error',
                                                 0).return_json(),
                         status=status.HTTP_400_BAD_REQUEST)
     try:
         custom_user = CustomUser.objects.get(
             email=request.data['Username'])
     except ObjectDoesNotExist as error:
         logger.error(error)
         return Response(ReturnResponse.Response(1, __name__, "error",
                                                 0).return_json(),
                         status=status.HTTP_400_BAD_REQUEST)
     return Response(ReturnResponse.Response(0, __name__, "success",
                                             custom_user.pk).return_json(),
                     status=status.HTTP_200_OK)
コード例 #10
0
ファイル: views.py プロジェクト: kevinstotz/DimeAPI
    def post(self, request, *args, **kwargs):
        pp = PayPalProcessor.PayPalProcessor()
        try:
            serializer = PaypalTransactionSerializer(data=request.data)
        except Exception as error:
            logger.error("Paypal payment captured error: {0}".format(error))
            return
        try:
            serializer.is_valid(raise_exception=True)
            serializer.save()
        except Exception as error:
            logger.error("Paypal payment captured error: {0}".format(error))
            return Response(ReturnResponse.Response(1, __name__, 'failed',
                                                    error).return_json(),
                            status=status.HTTP_200_OK)
        pp.capture(serializer)

        return Response(ReturnResponse.Response(0, __name__, 'success',
                                                "0").return_json(),
                        status=status.HTTP_200_OK)
コード例 #11
0
ファイル: views.py プロジェクト: kevinstotz/DimeAPI
    def post(self, request):

        if not request.data['email']:
            return Response(ReturnResponse.Response(1, __name__, 'success',
                                                    "err").return_json(),
                            status=status.HTTP_400_BAD_REQUEST)
        if len(request.data['email']) <= 5:
            return Response(ReturnResponse.Response(1, __name__, 'success',
                                                    "err").return_json(),
                            status=status.HTTP_400_BAD_REQUEST)
        user = UserUtil.get_user_from_email(request.data['email'])
        if user is None:
            return Response(ReturnResponse.Response(1, __name__, 'success',
                                                    "err").return_json(),
                            status=status.HTTP_400_BAD_REQUEST)
        my_email = MyEmail.MyEmail('Send Forgot Password')
        result = my_email.send_forgot_password_email(user)
        logger.error(result)
        return Response(ReturnResponse.Response(
            1, __name__, 'success',
            "Message sent!".format(request.data['email'])).return_json(),
                        status=status.HTTP_200_OK)
コード例 #12
0
    def post(self, request, *args, **kwargs):
        contact_us = ''
        try:
            contact_us = ContactUsFormSerializer(data=request.data,
                                                 partial=True)
            contact_us.is_valid(raise_exception=True)
        except Exception as error:
            result = 'Failed to parse JSON:{0}'.format(
                request) + contact_us + str(error)
            logger.error(result)
            return Response(ReturnResponse.Response(1, __name__,
                                                    "Contact Us send Failed",
                                                    result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        contact_us.create(contact_us.validated_data)
        my_email = MyEmail.MyEmail(name=contact_us.validated_data['name'])
        result = my_email.send_contact_us(contact_us)
        result = "Email Sent!"
        logger.error(result)
        return Response(ReturnResponse.Response(0, __name__, result,
                                                0).return_json(),
                        status=status.HTTP_201_CREATED)
コード例 #13
0
ファイル: views.py プロジェクト: kevinstotz/DimeAPI
 def delete(self, request, pk, format=None):
     document = self.get_object()
     if document.user == self.request.user.user_profile:
         document.delete()
         logger.info("Document deleted: " + document.name +
                     ":by user_profile:" +
                     str(self.request.user.user_profile.pk))
     else:
         logger.info("Document tried to be deleted: " + document.name +
                     ":by user_profile:" +
                     str(self.request.user.user_profile.pk))
     return Response(ReturnResponse.Response(0, __name__, "deleted",
                                             0).return_json(),
                     status=status.HTTP_204_NO_CONTENT)
コード例 #14
0
ファイル: views.py プロジェクト: kevinstotz/DimeAPI
 def post(self, request):
     if not 'password' in request.data:
         return Response(ReturnResponse.Response(
             1, __name__, 'failed', "Password required").return_json(),
                         status=status.HTTP_400_BAD_REQUEST)
     if not 'passwordConfirm' in request.data:
         return Response(ReturnResponse.Response(
             1, __name__, 'failed',
             "Password Confirm required").return_json(),
                         status=status.HTTP_401_UNAUTHORIZED)
     if 'authorizationCode' not in request.data:
         return Response(ReturnResponse.Response(
             1, __name__, 'failed',
             "autherizationCode required").return_json(),
                         status=status.HTTP_403_FORBIDDEN)
     if request.data['password'] != request.data['passwordConfirm']:
         return Response(ReturnResponse.Response(
             1, __name__, 'failed', "passwords do not match").return_json(),
                         status=status.HTTP_405_METHOD_NOT_ALLOWED)
     my_email = MyEmail.MyEmail('Send Forgot Password')
     result = my_email.send_reset_password_email(request.data)
     return Response(ReturnResponse.Response(1, __name__, 'success',
                                             result).return_json(),
                     status=status.HTTP_200_OK)
コード例 #15
0
ファイル: views.py プロジェクト: kevinstotz/DimeAPI
 def post(self, request, filename, format=None):
     file_obj = request.data['file']
     document = Document()
     document.document = file_obj
     document.name = file_obj.name
     document.file_type = FileType.objects.get(pk=1)
     document.status = DocumentStatus.objects.get(
         pk=DOCUMENT_STATUS['READY_TO_VERIFY'])
     document.type = DocumentType.objects.get(
         pk=file_obj.name[:file_obj.name.index('_')])
     document.user = self.request.user.user_profile
     document.save()
     logger.info("document uploaded " + document.name)
     return Response(ReturnResponse.Response(1, __name__, 'success',
                                             "u").return_json(),
                     status=status.HTTP_201_CREATED)
コード例 #16
0
ファイル: views.py プロジェクト: kevinstotz/DimeAPI
 def post(self, request, *args, **kwargs):
     logger.info("Paypal payment returned")
     return Response(ReturnResponse.Response(0, __name__, 'success',
                                             0).return_json(),
                     status=status.HTTP_201_CREATED)
コード例 #17
0
    def get(self, request, *args, **kwargs):

        authorization_code = kwargs.get('Authorization_Code', 0)

        try:
            self.get_queryset().filter(
                authorizationCode=authorization_code).count()
            verify_register = Register.objects.get(
                authorizationCode=authorization_code)
        except ObjectDoesNotExist:
            register_status = RegisterStatus.objects.get(
                pk=REGISTER_STATUS['INVALID'])
            result = 'Invalid Register Code:{0} :{1}'.format(
                register_status.status, authorization_code)
            logger.error(result)
            return Response(ReturnResponse.Response(1, __name__,
                                                    'Invalid Register Code',
                                                    result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        if verify_register.status.pk == REGISTER_STATUS['EXPIRED']:
            result = 'Expired Register Code:{0} :{1}'.format(
                verify_register.status, authorization_code)
            logger.error(result)
            return Response(ReturnResponse.Response(1, __name__,
                                                    'Register Code Expired',
                                                    result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        if verify_register.status.pk == REGISTER_STATUS['VERIFIED']:
            result = 'Already Verified Register Code:{0} :{1}'.format(
                verify_register.status, authorization_code)
            logger.error(result)
            return Response(ReturnResponse.Response(
                1, __name__, 'Register Code already Verified',
                result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        if verify_register.status.pk == REGISTER_STATUS['NEW']:
            result = 'New Register Code:{0} :{1}'.format(
                verify_register.status, authorization_code)
            logger.error(result)
            return Response(ReturnResponse.Response(1, __name__,
                                                    'Register Code is New',
                                                    result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        if verify_register.status.pk != REGISTER_STATUS['SENT']:
            result = 'Register Code Already Sent:{0} :{1}'.format(
                verify_register.status, authorization_code)
            logger.error(result)
            return Response(ReturnResponse.Response(1, __name__,
                                                    'Register Code is Sent',
                                                    result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        if (UnixEpoch.datetime_to_epoch(datetime.now()) -
                UnixEpoch.datetime_to_epoch(verify_register.inserted)
            ) > AUTHORIZATION_CODE_VALID_TIME_IN_SECONDS:
            register_status = RegisterStatus.objects.get(
                pk=REGISTER_STATUS['EXPIRED'])
            verify_register.status = register_status
            verify_register.save()
            result = 'Register Code Expired:{0} :{1}'.format(
                verify_register.status, authorization_code)
            logger.error(result)
            return Response(ReturnResponse.Response(1, __name__,
                                                    'Register Code Expired',
                                                    result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        user_util = UserUtil.UserUtils()
        if user_util.find_username(verify_register.firstName +
                                   verify_register.lastName) != 0:
            result = 'Failed creating username: already exists'
            logger.error(result)
            return Response(ReturnResponse.Response(1, __name__,
                                                    'Username Exists',
                                                    result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        email_util = EmailUtil.EmailUtil()
        if email_util.find_email(verify_register.email) != 0:
            email_status = EmailAddressStatus.objects.get(
                pk=EMAIL_ADDRESS_STATUS['EXISTS'])
            result = 'Email Already exists:{0}: {1}:'.format(
                email_status.status, verify_register.email)
            logger.error(result)
            return Response(ReturnResponse.Response(1, __name__,
                                                    'Email Already Exists',
                                                    result).return_json(),
                            status=status.HTTP_400_BAD_REQUEST)

        user_profile = UserProfile()
        user_profile.save()
        new_user = CustomUser(
            email=verify_register.email,
            username=user_util.new_username,
            status=UserStatus.objects.get(pk=USER_STATUS['ACTIVE']),
            user_profile=user_profile)
        try:
            pw = UserUtil.generate_password()
            new_user.set_password(pw)
            new_user.save()
        except Exception as error:
            logger.error("{0}".format(error))

        email = EmailAddress(
            email=verify_register.email,
            user_profile=user_profile,
            type=EmailAddressType(pk=EMAIL_ADDRESS_TYPE['PRIMARY']),
            status=EmailAddressStatus(pk=EMAIL_ADDRESS_STATUS['ACTIVE']))

        first_name = Name(name=verify_register.firstName,
                          type=NameType.objects.get(pk=NAME_TYPE['FIRST']),
                          user_profile=user_profile)

        last_name = Name(name=verify_register.lastName,
                         type=NameType.objects.get(pk=NAME_TYPE['LAST']),
                         user_profile=user_profile)
        try:
            for zipcode in ZipCode.objects.filter(
                    zipcode=verify_register.zipCode):
                for state in State.objects.filter(zip_codes=zipcode):
                    s = State.objects.get(pk=state.pk)
                    c = Country.objects.get(pk=state.country.pk)
                    z = ZipCode.objects.get(pk=zipcode.pk)
                    address = Address(country=c,
                                      state=s,
                                      zipcode=z,
                                      user_profile=user_profile)
                    break
                break
        except Exception as error:
            logger.error(error)
            address = Address(user_profile=user_profile)

        address.save()
        email.save()
        first_name.save()
        last_name.save()

        my_mail = MyEmail.MyEmail("Welcome Email")
        my_mail.send_welcome_email(new_user, pw)

        verify_register.status = RegisterStatus.objects.get(
            pk=REGISTER_STATUS['VERIFIED'])
        verify_register.save()

        result = 'User Added:{0}:'.format(new_user.pk)
        logger.info(result)
        return Response(ReturnResponse.Response(
            1, __name__, 'Registration Succuess!  Welcome Email Sent.',
            result).return_json(),
                        status=status.HTTP_200_OK)
コード例 #18
0
ファイル: MyEmail.py プロジェクト: kevinstotz/DimeAPI
    def send_contact_us(self, contactus):

        try:
            email_template = EmailTemplate.objects.get(
                pk=EMAIL_TEMPLATE['CONTACTUS'])
            result = 'Getting  CONTACTUS :{0} from DB:'.format(
                email_template.htmlFilename)
            logger.debug(result)
        except ObjectDoesNotExist:
            result = 'Failed getting CONTACTUS record #:{0} from DB:'.format(
                EMAIL_TEMPLATE['CONTACTUS'])
            logger.critical(result)
            return ReturnResponse.Response(1, __name__, 'failed',
                                           result).return_json()

        notification = Notification()
        notification.toUser = 1
        notification.message = email_template.pk
        notification.type = NotificationType(pk=NOTIFICATION_TYPE['EMAIL'])

        try:
            self.load_html_template(email_template.htmlFilename.name)
            result = 'read email template file:{0}'.format(
                email_template.htmlFilename)
            logger.debug(result)
        except Exception as error:
            result = 'Failed reading Email template:{0}'.format(
                email_template.htmlFilename)
            logger.critical(result)
            logger.critical(error)
            return ReturnResponse.Response(1, __name__, 'failed',
                                           result).return_json()

        self.subject = email_template.subject
        self.fromEmail = email_template.fromAddress + '@' + EMAIL_FROM_DOMAIN
        self.toEmail = email_template.fromAddress + '@' + EMAIL_FROM_DOMAIN
        self.replace_string_in_html_template(
            'EMAIL_VERIFY_TRACK_URL', EMAIL_VERIFY_TRACK_URL + "contactus")
        self.replace_string_in_html_template(
            'NAME', contactus.validated_data['name'] + " ")
        self.replace_string_in_html_template('EMAIL',
                                             contactus.validated_data['email'])
        self.replace_string_in_html_template(
            'MESSAGE', contactus.validated_data['message'])

        try:
            self.load_text_template(email_template.textFilename.name)
            result = 'read email template file:{0}'.format(
                email_template.textFilename)
            logger.debug(result)
        except Exception as error:
            result = 'Failed reading Email template:{0}'.format(
                email_template.textFilename)
            logger.critical(result)
            logger.critical(error)
            return ReturnResponse.Response(1, __name__, 'failed',
                                           result).return_json()

        self.replace_string_in_text_template(
            'EMAIL_VERIFY_TRACK_URL', EMAIL_VERIFY_TRACK_URL + "contactus")
        self.replace_string_in_text_template(
            'NAME', contactus.validated_data['name'] + " ")
        self.replace_string_in_text_template('EMAIL',
                                             contactus.validated_data['email'])
        self.replace_string_in_text_template(
            'MESSAGE', contactus.validated_data['message'])

        self.mail_server = MailServer.objects.get(pk=3)
        self.emailPassword = self.mail_server.password
        self.emailUsername = self.mail_server.username
        self.emailHost = self.mail_server.server
        self.emailPort = self.mail_server.port

        if self.send() == 1:
            notification.status = NotificationStatus.objects.get(
                pk=NOTIFICATION_STATUS['SENT'])
            result = 'Contact us email sent to user ID:{0}'.format(
                contactus.validated_data['email'])
            logger.debug(result)
        else:
            notification.status = NotificationStatus.objects.get(
                pk=NOTIFICATION_STATUS['FAILED'])
            result = 'Failed sending email:{0} to user ID:{1}'.format(
                email_template.htmlFilename, contactus.validated_data['email'])
            logger.error(result)
            return ReturnResponse.Response(1, __name__, 'failed',
                                           result).return_json()
        notification.save()
        result = 'Email sent!'
        return ReturnResponse.Response(0, __name__, 'success',
                                       result).return_json()
コード例 #19
0
ファイル: MyEmail.py プロジェクト: kevinstotz/DimeAPI
    def send_verify_email(self, register_user):

        try:
            email_template = EmailTemplate.objects.get(
                pk=EMAIL_TEMPLATE['VERIFY'])
            result = 'Getting EMAIL_TEMPLATE VERIFY :{0} from DB:'.format(
                email_template.htmlFilename)
            logger.debug(result)
        except ObjectDoesNotExist:
            result = 'Failed getting EMAIL_TEMPLATE record #:{0} from DB:'.format(
                EMAIL_TEMPLATE['VERIFY'])
            logger.critical(result)
            return ReturnResponse.Response(1, __name__, 'failed',
                                           result).return_json()

        notification = Notification()
        notification.toUser = register_user.pk
        notification.message = email_template.pk
        notification.type = NotificationType(pk=NOTIFICATION_TYPE['EMAIL'])

        try:
            self.load_html_template(email_template.htmlFilename.name)
            result = 'read email template file:{0}'.format(
                email_template.htmlFilename)
            logger.debug(result)
        except Exception as error:
            result = 'Failed reading Email template:{0}'.format(
                email_template.htmlFilename)
            logger.critical(result)
            logger.critical(error)
            return ReturnResponse.Response(1, __name__, 'failed',
                                           result).return_json()

        self.subject = email_template.subject
        self.fromEmail = email_template.fromAddress + '@' + EMAIL_FROM_DOMAIN
        self.toEmail = register_user.email

        self.replace_string_in_html_template(
            'EMAIL_VERIFY_TRACK_URL',
            EMAIL_VERIFY_TRACK_URL + register_user.authorizationCode)
        self.replace_string_in_html_template(
            'EMAIL_VERIFY_ACCOUNT_URL',
            EMAIL_VERIFY_ACCOUNT_URL + register_user.authorizationCode)
        self.replace_string_in_html_template('FIRST_NAME',
                                             register_user.firstName + " ")
        self.replace_string_in_html_template('LAST_NAME',
                                             register_user.lastName)

        try:
            self.load_text_template(email_template.textFilename.name)
            result = 'read email template file:{0}'.format(
                email_template.textFilename)
            logger.debug(result)
        except Exception as error:
            result = 'Failed reading Email template:{0}'.format(
                email_template.textFilename)
            logger.critical(result)
            logger.critical(error)
            return ReturnResponse.Response(1, __name__, 'failed',
                                           result).return_json()

        self.replace_string_in_text_template(
            'EMAIL_VERIFY_TRACK_URL',
            EMAIL_VERIFY_TRACK_URL + register_user.authorizationCode)
        self.replace_string_in_text_template(
            'EMAIL_VERIFY_ACCOUNT_URL',
            EMAIL_VERIFY_ACCOUNT_URL + register_user.authorizationCode)
        self.replace_string_in_text_template('FIRST_NAME',
                                             register_user.firstName + " ")
        self.replace_string_in_text_template('LAST_NAME',
                                             register_user.lastName)

        if self.send() == 1:
            notification.status = NotificationStatus.objects.get(
                pk=NOTIFICATION_STATUS['SENT'])
            register_user.status = RegisterStatus.objects.get(
                pk=REGISTER_STATUS['SENT'])
            register_user.save()
            result = 'Registered User and sent email to user ID:{0}'.format(
                register_user)
            logger.debug(result)
        else:
            notification.status = NotificationStatus.objects.get(
                pk=NOTIFICATION_STATUS['FAILED'])
            result = 'Failed sending email:{0} to user ID:{1}'.format(
                email_template.htmlFilename, register_user)
            logger.error(result)
            return ReturnResponse.Response(1, __name__, 'failed',
                                           result).return_json()
        notification.save()
        result = 'Verification email sent to:{}'.format(self.toEmail)
        return ReturnResponse.Response(0, __name__, 'success',
                                       result).return_json()
コード例 #20
0
ファイル: MyEmail.py プロジェクト: kevinstotz/DimeAPI
    def send_welcome_email(self, new_user, new_password):

        try:
            new_user = CustomUser.objects.get(pk=new_user.pk)
            result = 'Loaded New User in Users: Id:{0}'.format(new_user.pk)
            logger.debug(result)
        except ObjectDoesNotExist as error:
            result = 'Could not find New User in Users: Id:{0}'.format(
                new_user.pk)
            logger.error(result)
            logger.error(error)
            return ReturnResponse.Response(1, __name__,
                                           'Could not find New User',
                                           result).return_json()

        try:
            email_template = EmailTemplate.objects.get(
                pk=EMAIL_TEMPLATE['WELCOME'])
            result = 'Loaded Email Template WELCOME:{0}'.format(
                email_template.htmlFilename)
            logger.debug(result)
        except ObjectDoesNotExist as error:
            result = 'Could not find Email Template:{0}'.format(error)
            logger.error(error)
            return ReturnResponse.Response(1, __name__,
                                           'Could not find Email Template',
                                           result).return_json()

        notification = Notification()
        notification.toUser = new_user.pk
        notification.message = email_template.pk

        try:
            notification.type = NotificationType.objects.get(
                pk=NOTIFICATION_TYPE['EMAIL'])
            result = 'Loaded email type notification: Id:{0}'.format(
                NOTIFICATION_TYPE['EMAIL'])
            logger.debug(result)
        except ObjectDoesNotExist as error:
            result = 'Failed loading email type notification Type: {0}{1}'.format(
                NOTIFICATION_TYPE['EMAIL'], error)
            logger.error(error)
            logger.error(result)
            return ReturnResponse.Response(
                1, __name__, 'Failed loading email type notification',
                result).return_json()

        try:
            self.load_html_template(email_template.htmlFilename.name)
            result = 'read email template file:{0}'.format(
                email_template.htmlFilename.name)
            logger.debug(result)
        except Exception as error:
            result = 'Failed reading email template:{0}'.format(
                email_template.htmlFilename.name)
            logger.error(error)
            logger.error(result)
            return ReturnResponse.Response(1, __name__,
                                           'Failed reading email template',
                                           result).return_json()

        try:
            self.load_text_template(email_template.textFilename.name)
            result = 'read email template file:{0}'.format(
                email_template.textFilename.name)
            logger.debug(result)
        except Exception as error:
            result = 'Failed reading email template:{0}'.format(
                email_template.textFilename.name)
            logger.error(error)
            logger.error(result)
            return ReturnResponse.Response(1, __name__,
                                           'Failed reading email template',
                                           result).return_json()

        self.subject = email_template.subject
        self.fromEmail = email_template.fromAddress + '@' + EMAIL_FROM_DOMAIN

        try:
            email_address_status = EmailAddressStatus.objects.get(
                pk=EMAIL_ADDRESS_STATUS['ACTIVE'])
            result = 'Loaded email address status Active: Id:{0}'.format(
                EMAIL_ADDRESS_STATUS['ACTIVE'])
            logger.debug(result)
        except ObjectDoesNotExist as error:
            result = 'Failed Loading email address status Active: Id:{0}'.format(
                EMAIL_ADDRESS_STATUS['ACTIVE'])
            logger.critical(error)
            logger.critical(result)
            return ReturnResponse.Response(
                1, __name__, 'Failed Loading email address status',
                result).return_json()

        try:
            email_address = EmailAddress.objects.get(
                user_profile=new_user.user_profile,
                status=email_address_status)
            result = 'Loaded email address :{0}'.format(email_address.email)
            logger.debug(result)
        except ObjectDoesNotExist as error:
            result = 'Failed Loading email address:'
            logger.critical(result)
            logger.critical(error)
            return ReturnResponse.Response(1, __name__,
                                           'Failed Loading email address',
                                           result).return_json()
        self.toEmail = email_address.email

        name_type = ""
        try:
            name_type = NameType.objects.get(pk=NAME_TYPE['FIRST'])
            result = 'Loaded name type:{0}'.format(name_type.type)
            logger.debug(result)
        except ObjectDoesNotExist:
            result = 'Failed Loading Name Type First:{0}'.format(
                name_type.type)
            logger.critical(result)
            return ReturnResponse.Response(1, __name__,
                                           'Failed Loading Name Type First',
                                           result).return_json()

        name = ""
        try:
            name = Name.objects.get(user_profile=new_user.user_profile,
                                    type=name_type)
            result = 'Loaded name:{0}'.format(name.name)
            logger.debug(result)
        except ObjectDoesNotExist as error:
            result = 'Loaded name type:{0}'.format(name.name)
            logger.critical(result)
            logger.critical(error)
            return ReturnResponse.Response(1, __name__, 'Failed Loading Name',
                                           result).return_json()

        self.subject = self.subject.replace('NAME', name.name)
        self.replace_string_in_html_template('PASSWORD', str(new_password))
        self.replace_string_in_html_template('USERNAME', email_address.email)
        self.replace_string_in_html_template('FIRST_NAME', name.name)
        self.replace_string_in_html_template('EMAIL_VERIFY_TRACK_URL',
                                             EMAIL_VERIFY_TRACK_URL)
        self.replace_string_in_html_template('WELCOME_EMAIL_LOGIN',
                                             WELCOME_EMAIL_LOGIN)

        self.replace_string_in_text_template('PASSWORD', str(new_password))
        self.replace_string_in_text_template('USERNAME', email_address.email)
        self.replace_string_in_text_template('FIRST_NAME', name.name)
        self.replace_string_in_text_template('EMAIL_VERIFY_TRACK_URL',
                                             EMAIL_VERIFY_TRACK_URL)
        self.replace_string_in_text_template('WELCOME_EMAIL_LOGIN',
                                             WELCOME_EMAIL_LOGIN)

        if self.send() == 1:
            notification.status = NotificationStatus.objects.get(
                pk=NOTIFICATION_STATUS['SENT'])
            result = 'Welcome Email Sent to:{0}'.format(email_address.email)
            logger.debug(result)
        else:
            notification.status = NotificationStatus.objects.get(
                pk=NOTIFICATION_STATUS['FAILED'])
            result = 'Failed Welcome Email Sent to:{0}'.format(
                email_address.email)
            logger.info(result)
        notification.save()
        return ReturnResponse.Response(0, __name__, 'success',
                                       result).return_json()
コード例 #21
0
ファイル: views.py プロジェクト: kevinstotz/DimeAPI
 def get(self, request, *args, **kwargs):
     result = '{"redirect_to": "' + DASHBOARD_HOSTNAME_URL + '"}'
     return Response(ReturnResponse.Response(1, __name__, "failed",
                                             result).return_json(),
                     status=status.HTTP_400_BAD_REQUEST)