Beispiel #1
0
def register_profile(sender, **kwargs):
    if kwargs.get("created"):
        profile = kwargs.get("instance")
        if profile:
            user_new = model_to_dict(profile.user)
            try:
                # condition for not calling at the time of run test cases
                if "test" not in sys.argv:
                    BaseSendMail.delay(user_new, type="account_confirmation", key=profile.activation_key)
            except:
                pass
            return
Beispiel #2
0
    def test_send_emai_to_user(self):

        """ send mail to created user """
        send_mail = BaseSendMail.delay(
            self.user_data,
            type='test_email')
        self.assertEqual(send_mail.state, 'PENDING')
Beispiel #3
0
    def send_white_invitation(self, request):

        try:
            data = {}
            user_id = request.user
            data["message"] = request.data.get("message")
            email = data["message"]["email"]
            user_exist = User.objects.filter(email=data["message"]["email"])
        except:
            user_id = None
        if user_exist:
            logger.debug("email for grey contact already exists")
            return CustomeResponse(
                {"msg": "email already exists"}, status=status.HTTP_400_BAD_REQUEST, validate_errors=1
            )
        else:
            try:
                sender_folder_id = FolderContact.objects.filter(
                    user_id=request.user.id, contact_id=request.data.get("receiver_bcard_or_contact_id")
                ).values_list("folder_id", flat=True)[0]

                sender_business_card_id = Folder.objects.filter(id=sender_folder_id).values_list(
                    "businesscard_id", flat=True
                )[0]

                data["email"] = request.user.email
                data["sender_user_id"] = request.user.id
                data["receiver_user_id"] = ""
                data["sender_business_card_id"] = sender_business_card_id
                data["request_type"] = "b2g"
                data["receiver_bcard_or_contact_id"] = request.data.get("receiver_bcard_or_contact_id")

                email = data["message"]["email"].encode("base64", "strict")
                fname = data["message"]["fname"].encode("base64", "strict")
                lname = data["message"]["lname"].encode("base64", "strict")
                contactId = str(data["receiver_bcard_or_contact_id"]).encode("base64", "strict")
                sid = str(data["sender_user_id"]).encode("base64", "strict")

            except:
                return CustomeResponse(
                    {"msg": "Please provide receiver_bcard_or_contact_id"},
                    status=status.HTTP_400_BAD_REQUEST,
                    validate_errors=1,
                )

            salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
            activation_key = hashlib.sha1(salt + email).hexdigest()[:10]
            email_invit_url = (
                str(settings.DOMAIN_NAME)
                + "/api/greyrequest/invite_registration"
                + "/?email="
                + email
                + "&fname="
                + fname
                + "&lname="
                + lname
                + "&cid="
                + contactId
                + "&sid="
                + sid
            )

            serializer = SendRequestSerializer(data=data, context={"request": request, "msg": "not exist"})
            if serializer.is_valid():
                serializer.save()
                BaseSendMail.delay(
                    data, type="grey_invitation", key=activation_key, url=email_invit_url, first_name=fname, email=email
                )
                return CustomeResponse(serializer.data, status=status.HTTP_201_CREATED)
            else:
                return CustomeResponse({"msg": serializer.errors}, validate_errors=1)