Esempio n. 1
0
def post_register(sender, instance: get_user_model(), created, **kwargs):
    """Sends mail/message to users after registeration

    Parameters
    ----------
    sender: get_user_model()

    instance: get_user_model()

    created: bool
    """

    from drf_user import user_settings

    from drfaddons.utils import send_message

    if created:
        if user_settings["REGISTRATION"]["SEND_MAIL"]:
            send_message(
                message=user_settings["REGISTRATION"]["TEXT_MAIL_BODY"],
                subject=user_settings["REGISTRATION"]["MAIL_SUBJECT"],
                recip=[instance.email],
                recip_email=[instance.email],
                html_message=user_settings["REGISTRATION"]["HTML_MAIL_BODY"],
            )
        if user_settings["REGISTRATION"]["SEND_MESSAGE"]:
            send_message(
                message=user_settings["REGISTRATION"]["SMS_BODY"],
                subject=user_settings["REGISTRATION"]["MAIL_SUBJECT"],
                recip=[instance.mobile],
                recip_email=[instance.mobile],
            )
Esempio n. 2
0
def post_order(sender, instance: Order, created, **kwargs):
    INVOICE_URL = "https://tapatapi.civilmachines.com/api/order/invoice/"
    # INVOICE_URL = "http://192.168.1.247:8000/api/order/invoice/"
    invoice_url = INVOICE_URL + "{}/".format(instance.id)
    message = (
        "Thank You for ordering from us. Your invoice can be downloaded from "
        + invoice_url)
    subject = "Invoice"
    data = {
        "message": message,
        "subject": subject,
        "recip": [instance.mobile],
        "recip_email": [instance.email],
    }

    if created:
        send_message(**data)
Esempio n. 3
0
    def validated(self, serialized_data, *args, **kwargs):
        from drfaddons.utils import send_message

        # email_validated = check_validation(serialized_data.initial_data['email'])
        # mobile_validated = check_validation(serialized_data.initial_data['mobile'])
        email_validated = True
        mobile_validated = True
        data = {}

        if email_validated and mobile_validated:
            user = User.objects.create_user(
                username=serialized_data.initial_data["username"],
                email=serialized_data.initial_data["email"],
                name=serialized_data.initial_data["name"],
                password=serialized_data.initial_data["password"],
                mobile=serialized_data.initial_data["mobile"],
                is_active=True,
            )
            data = {
                "name": user.get_full_name(),
                "username": user.get_username(),
                "id": user.id,
                "email": user.email,
                "mobile": user.mobile,
            }
            status_code = status.HTTP_201_CREATED
            subject = "New account created | Hisab Kitab (v 0.1 b1)"
            message = """You've created an account with Hisab Kitab.
            Your account activation is subject to Administrator approval.
            Our Administrator may call you for verification.

            This app is a product of Vitartha, a StartUp focusing on Financially aware India.
            Vitartha will also like to thank M/s Civil Machines Technologies Private Limited for the technical
            production & development of this app.
            Thank You!
            """
            send_message(message, subject, [user.email], [user.email])
        else:
            status_code = status.HTTP_422_UNPROCESSABLE_ENTITY
        if not email_validated:
            data["email"] = ["Provided EMail is not validated!"]
        if not mobile_validated:
            data["mobile"] = ["Provided Mobile is not validated!"]

        return data, status_code
Esempio n. 4
0
def post_register(sender, instance: get_user_model(), created, **kwargs):
    from drf_user import user_settings

    from drfaddons.utils import send_message

    if created:
        if user_settings['REGISTRATION']['SEND_MAIL']:
            send_message(
                message=user_settings['REGISTRATION']['TEXT_MAIL_BODY'],
                subject=user_settings['REGISTRATION']['MAIL_SUBJECT'],
                recip=[instance.email],
                recip_email=[instance.email],
                html_message=user_settings['REGISTRATION']['HTML_MAIL_BODY'])
        if user_settings['REGISTRATION']['SEND_MESSAGE']:
            send_message(message=user_settings['REGISTRATION']['SMS_BODY'],
                         subject=user_settings['REGISTRATION']['MAIL_SUBJECT'],
                         recip=[instance.mobile],
                         recip_email=[instance.mobile])
Esempio n. 5
0
def send_otp(value, otpobj, recip):
    """
    This function sends OTP to specified value.
    Parameters
    ----------
    value: str
        This is the value at which and for which OTP is to be sent.
    otpobj: OTPValidation
        This is the OTP or One Time Passcode that is to be sent to user.
    recip: str
        This is the recipient to whom EMail is being sent. This will be
        deprecated once SMS feature is brought in.

    Returns
    -------

    """

    import datetime

    from django.utils import timezone

    from drfaddons.utils import send_message

    from rest_framework.exceptions import PermissionDenied, APIException

    otp = otpobj.otp

    if not datetime_passed_now(otpobj.reactive_at):
        raise PermissionDenied(detail=_("OTP sending not allowed until: " +
                                        str(otpobj.reactive_at)))

    message = ("OTP for verifying " + otpobj.get_prop_display() + ": " +
               value + " is " + otp + ". Don't share this with anyone!")

    try:
        rdata = send_message(message, otp_settings["SUBJECT"], [value],
                             [recip])
    except ValueError as err:
        raise APIException(
            _("Server configuration error occured: %s") % str(err))

    otpobj.reactive_at = timezone.now() + datetime.timedelta(
        minutes=otp_settings["COOLING_PERIOD"])
    otpobj.save()

    return rdata
Esempio n. 6
0
def send_otp(prop, value, otpobj, recip):
    """
    This function sends OTP to specified value.
    Parameters
    ----------
    prop: str
        This is the type of value. It can be "email" or "mobile"
    value: str
        This is the value at which and for which OTP is to be sent.
    otpobj: OTPValidation
        This is the OTP or One Time Passcode that is to be sent to user.
    recip: str
        This is the recipient to whom EMail is being sent. This will be deprecated once SMS feature is brought in.

    Returns
    -------

    """
    from drfaddons.utils import send_message

    otp = otpobj.otp

    rdata = {"success": False, "message": None}

    if otpobj.reactive_at > datetime.datetime.now():
        rdata[
            "message"] = "OTP sending not allowed until: " + otpobj.reactive_at.strftime(
                "%d-%h-%Y %H:%M:%S")
        return rdata

    message = ("OTP for verifying " + prop + ": " + value + " is " + otp +
               ". Don't share this with anyone!")
    subject = "OTP for Verification"

    rdata = send_message(message=message,
                         subject=subject,
                         recip_email=[recip],
                         recip=[recip])

    if rdata["success"]:
        otpobj.reactive_at = datetime.datetime.now() + datetime.timedelta(
            minutes=3)
        otpobj.save()

    return rdata