Beispiel #1
0
def sendPasswordResetEmail(user_email):

    user = UserExistsByEmail(user_email)
    if not user:
        return False

    context = {
        'user': user,
        'domain': getOption('site_url'),
        'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
        'token': PasswordResetTokenGenerator().make_token(user),
        'protocol': 'http'
    }

    subject = "Reset your Password"

    html = render_to_string("accounts/email/forgot-password/template.html",
                            context=context)
    text = render_to_string("accounts/email/forgot-password/template.txt",
                            context=context)

    ScheduleEmail(to_email=user.email,
                  subject=subject,
                  html_text=html,
                  plain_text=text)

    return True
Beispiel #2
0
    def handle(self, *args, **kwargs):

        for option in options:
            if getOption(option[0]) == None:
                print(" -- Added Option %s - %s - %s" % (option[0], option[1], option[2]))
                addOption(option[0], option[1], option[2])
            else:
                print(" -- Existing Option %s - %s - %s" % (option[0], option[1], option[2]))

        print("Added Initial Entries!")
Beispiel #3
0
def SendAccountActivationEmail(user_email):

    user = UserExistsByEmail(user_email)
    if not user:
        return False

    context = {
        'user': user,
        'domain': getOption('site_url'),
        'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
        'token': AccountActivationTokenGenerator().make_token(user)
    }

    subject = "Activate your account"

    html = render_to_string("accounts/email/signup/template.html",
                            context=context)
    text = render_to_string("accounts/email/signup/template.txt",
                            context=context)

    ScheduleEmail(to_email=user.email,
                  subject=subject,
                  html_text=html,
                  plain_text=text)

    context = {'user': user}
    html = render_to_string("accounts/email/signup-admin/template.html",
                            context=context)
    text = render_to_string("accounts/email/signup-admin/template.txt",
                            context=context)

    ScheduleEmail(to_email=getOption('new_account_email_to_address'),
                  subject="New User Signup at GSTHEALTH",
                  html_text=html,
                  plain_text=text)

    return True
Beispiel #4
0
def send_mail(email):

    try:
        # plaintext = get_template("%s/template.txt" % template).render(context)
        # html = get_template("%s/template.html" % template).render(context)

        con = mail.get_connection(host=getOption("smtp_server"),
                                  port=getOption("smtp_port"),
                                  username=getOption("smtp_user"),
                                  password=getOption("smtp_pass"),
                                  use_tls=True)

        msg = mail.EmailMultiAlternatives(subject=email.subject,
                                          body=email.plain_text,
                                          from_email=email.from_email,
                                          to=[email.to_email],
                                          connection=con)

        msg.attach_alternative(email.html_text, "text/html")
        msg.send()

        return True
    except Exception as e:
        raise
Beispiel #5
0
def SendAccountActivationEmail(user_email):

    if not UserExistsByEmail(user_email):
        return False
    user = User.objects.get(email=user_email)
    context = {
        'user': user,
        'domain': getOption('site_url'),
        'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
        'token': AccountActivationTokenGenerator().make_token(user)
    }

    subject = "Activate your account"

    if send_mail(subject, user.email, 'accounts/email/signup', context):
        return True
    else:
        return False
Beispiel #6
0
def ScheduleEmail(to_email, subject, html_text, plain_text, from_email=None):
    try:
        email = Email.objects.create(
            from_email=from_email
            if from_email != None else getOption('send_mails_as'),
            to_email=to_email,
            subject=subject,
            html_text=html_text,
            plain_text=plain_text)

        task = EmailQueue.objects.create(email=email)
        if not settings.USE_CELERY:
            execute_email_task(task.id)
        else:
            email_task.delay(task.id)

        return True
    except Exception as e:
        raise
Beispiel #7
0
def sendPasswordResetEmail(user_email):

    if not UserExistsByEmail(user_email):
        return False
    user = User.objects.get(email=user_email)
    context = {
        'user': user,
        'domain': getOption('site_url'),
        'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
        'token': PasswordResetTokenGenerator().make_token(user),
        'protocol': 'http'
    }

    subject = "Reset your Password"

    if send_mail(subject, user.email, 'accounts/email/forgot-password',
                 context):
        return True
    else:
        return False
Beispiel #8
0
    def handle(self, *args, **kwargs):

        options = (
            ("site_title", "Letstream", "Site Title"),
            ("support_email", "*****@*****.**", "Support Email"),
            ("site_description", "Site Developed by Letstream.",
             "Site Description"),
            ("smtp_server", "mail.example.com", "SMTP Server"),
            ("smtp_user", "admin", "SMTP User"),
            ("smtp_pass", "pass", "SMTP Pass"),
            ("smtp_port", "000", "SMTP Port"),
            ("send_mails_as", "admin@localhost", "Send Mails As"),
            ("site_url", "http://localhost:8000", "Site Url"),
        )

        for option in options:
            if getOption(option[0]) == None:
                addOption(option[0], option[1], option[2])

        print("Added Initial Entries!")
Beispiel #9
0
    def handle(self, *args, **kwargs):
        
        options = (
            ("site_title", "Letstream", "Site Title"),
            ("support_email", "*****@*****.**", "Support Email"),
            ("site_description", "Site Developed by Letstream.", "Site Description"),
            ("smtp_server", "mail.example.com", "SMTP Server"),
            ("smtp_user", "admin", "SMTP User"),
            ("smtp_pass", "pass", "SMTP Pass"),
            ("smtp_port", "000", "SMTP Port"),
            ("send_mails_as", "admin@localhost", "Send Mails As"),
            ("site_url", "http://localhost:8000", "Site Url"),
        )

        for option in options:
            if getOption(option[0]) == None:
                addOption(option[0], option[1], option[2])

        departments = [
            {
                "name": "Amity School of Engineering and Technology",
                "short_name": "ASET",
                "branches": [
                    {
                        "name": "ASET - CSE",
                        "short_name": "CSE"
                    },
                    {
                        "name": "ASET - IT",
                        "short_name": "IT"
                    },
                    {
                        "name": "ASET - Mechanical",
                        "short_name": "MECH"
                    },
                    {
                        "name": "ASET - Civil",
                        "short_name": "Civil"
                    }
                ]
            },
            {
                "name": "Amity Institute of Information Technology",
                "short_name": "AIT",
                "branches": [
                    {
                        "name": "AIT - BCA",
                        "short_name": "BCA"
                    },
                    {
                        "name": "AIT - B.Sc.(IT)",
                        "short_name": "BSC"
                    }
                ]
            }
        ]

        for dept in departments:
            d = getDepartment(dept['name'])
            if not d:
                d = addDepartment(dept['name'], dept['short_name'])
            else:
                print("%s Department Exists" % d.name)
            if not d:
                print("Unable to add department %s" % dept['name'])
            else:
                for branch in dept['branches']:
                    if not getBranch(branch['name']):
                        b = addBranch(branch['name'], branch['short_name'], d)
                        if not b:
                            print("Unable to add Branch %s" % branch['name'])
                    else:
                        print("Branch %s exists" % branch['name'])

        print("Added Initial Entries!")