예제 #1
0
    def save(self, validated_data):
        email = validated_data.get('email')
        new_user = User(
            username=email,
            email=email,
            is_active=False,
        )
        new_user.save()

        # Create new salary instance
        new_salary = Salary(user=new_user)
        new_salary.save()

        # Create new adminprofile instance
        new_adminprofile = AdminProfile(user=new_user)
        new_adminprofile.save()

        # Create new company instance and assign admin_profile to new admin_profile, other fields have placeholder values
        new_company = Company(adminprofile=new_adminprofile)
        new_company.save()

        registration = Registration(
            user=new_user,
            code_type='RV',
            profile_type='AP',
        )
        registration.save()

        email = Email(
            to=email,
            subject='Thank you for registering with RazzPay!',
            content=f'Here is your validation code: {registration.code}')
        email.save(request=self.context['request'])
        return new_user
예제 #2
0
    def save(self, validated_data):
        # Obtain user info
        email = validated_data.get('email')
        first_name = validated_data.get('first_name')
        last_name = validated_data.get('last_name')
        company = self.context['request'].user.company

        # Obtain salary info
        gross_month = validated_data.get('gross_month')
        position = validated_data.get('position')

        new_user = User(
            username=email,
            email=email,
            first_name=first_name,
            last_name=last_name,
            company_id=company.id,
            # Mark as true so that employee user instance can be used immediately without waiting for employee to register via email code
            is_active=True,
        )
        new_user.save()

        # Create new employeeprofile instance
        new_employeeprofile = EmployeeProfile(user=new_user)
        new_employeeprofile.save()

        # Create new salary instance
        new_salary = Salary(user=new_user,
                            position=position,
                            gross_month=round((gross_month), 2),
                            ahv_amount=round((gross_month * 0.05125), 2),
                            alv_amount=round((gross_month * 0.011), 2),
                            pension=round((gross_month * 0.01), 2),
                            net=round(
                                (gross_month - (gross_month * 0.05125) -
                                 (gross_month * 0.011) - (gross_month * 0.01)),
                                2))
        new_salary.save()

        registration = Registration(
            user=new_user,
            code_type='RV',
            profile_type='EP',
        )
        registration.save()

        email = Email(
            to=email,
            subject='Welcome to RazzPay!',
            content=f'Here is your validation code: {registration.code}')
        email.save(request=self.context['request'])
        return new_user
예제 #3
0
 def send_password_reset_email(self):
     email = self.validated_data.get('email')
     user = User.objects.get(email=email)
     user.registration.code = code_generator()
     user.registration.code_used = False
     user.registration.code_type = 'PR'
     user.registration.save()
     email = Email(
         to=email,
         subject='Reset your password for RazzPay',
         content=
         f'Here is your RazzPay password reset code: {user.registration.code}'
     )
     email.save(request=self.context['request'])
예제 #4
0
def send_message(message, to_user, email_type):
    # comment this out to test sending emails in other environments
    if settings.ENVIRONMENT != 'production':
        return
    email = Email(user=to_user,
                  subject=message.subject,
                  text_body=message.text,
                  html_body=message.html,
                  to_address=message.to[0],
                  from_address=message.from_address,
                  email_type=email_type)
    email.save()
    s = sendgrid.Sendgrid(settings.EMAIL_HOST_USER,
                          settings.EMAIL_HOST_PASSWORD,
                          secure=True)
    s.smtp.send(message)
예제 #5
0
파일: init.py 프로젝트: 326-queue/project
        company=random.choice(companies),
        position=fake.job(),
        email=fake.email(),
        phone_number=fake.phone_number(),
        is_warm_contact=fake.boolean(),
    )
    contact.save()
    contacts.append(contact)

print("Generating emails...")
emails = []
for i in range(100):
    status = random.choice(["sent", "scheduled", "draft"])
    email = Email(
        subject=fake.sentences(nb=1, ext_word_list=None)[0],
        body=fake.text(max_nb_chars=200, ext_word_list=None),
        status=status,
        created_by=random.choice(users),
    )
    if status == "scheduled":
        email.time_scheduled = fake.date_time_this_month(before_now=False,
                                                         after_now=True,
                                                         tzinfo=pytz.UTC)
    elif status == "sent":
        email.time_sent = fake.date_time_this_month(before_now=True,
                                                    after_now=False,
                                                    tzinfo=pytz.UTC)
    email.save()
    emails.append(email)

print("Generating hackathons...")
hackathons = []