Example #1
0
def post_register(sender, instance, created, **kwargs):
    from drf_user import user_settings

    from drfaddons.add_ons 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])
Example #2
0
    def validated(self, serialized_data, *args, **kwargs):
        from drfaddons.add_ons import send_message

        if user_settings['EMAIL_VALIDATION']:
            email_validated = check_validation(
                serialized_data.initial_data['email'])
        else:
            email_validated = True

        if user_settings['MOBILE_VALIDATION']:
            mobile_validated = check_validation(
                serialized_data.initial_data['email'])
        else:
            mobile_validated = True

        data = dict()

        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'])

            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
            if user_settings['REGISTRATION']['SEND_MAIL']:
                send_message('EMAIL',
                             user_settings['REGISTRATION']['TEXT_MAIL_BODY'],
                             user_settings['REGISTRATION']['MAIL_SUBJECT'],
                             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
Example #3
0
def placed_order(bh, **kwargs):
    from drfaddons.add_ons import send_message

    if bh.total < 9:
        message = """You just placed an order at %s, Office Cafe.
Order Number: %s
Total: %s :PENDING
Pay at Store only.
Greetings for eatings ^.^""" % (bh.store.name, bh.id, round(bh.total, 2))
    else:
        message = """You just placed an order at %s, Office Cafe.
Order Number: %s
Total Amount %s :PAID
Greetings for eatings ^.^""" % (bh.store.name, bh.id, round(bh.total, 2))

    items = ''
    for itm in bh.billitem_set.all():
        items += '%s - %s' % (itm.item.name, itm.quantity)

    if bh.paid:
        paid = 'Yes'
    else:
        paid = 'No'

    store_message = """%s just placed an order
Paid: %s
Amount: %s
Mobile: %s
Item: %s""" % (bh.name, paid, round(bh.total, 2), bh.mobile, items)

    send_message(message, 'Order placed | Office Cafe', [bh.email], [bh.email])
    send_message(message, 'Order placed | Office Cafe', [bh.mobile],
                 [bh.email])

    send_message(store_message, 'Order placed | Office Cafe',
                 ['*****@*****.**'], ['*****@*****.**'])
    send_message(store_message, 'Order placed | Office Cafe',
                 [bh.store.mobile], ['*****@*****.**'])
Example #4
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.add_ons import send_message

    import datetime

    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!"

    rdata = send_message(prop, message, otp_settings['SUBJECT'], recip)

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

    return rdata
Example #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
    -------

    """
    from drfaddons.add_ons import send_message

    from rest_framework.exceptions import PermissionDenied

    import datetime

    otp = otpobj.otp

    if otpobj.reactive_at > datetime.datetime.now():
        raise PermissionDenied(detail=_('OTP sending not allowed until: '
                                        + otpobj.reactive_at.strftime('%d-%h-%Y %H:%M:%S')))

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

    rdata = send_message(message, otp_settings['SUBJECT'], [value], [recip])

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

    return rdata