Exemple #1
0
        def contact_page(self):

            # Email to
            email_to = kwargs.pop(
                "email_to", self.get_config("APPLICATION_CONTACT_EMAIL", None))

            if not mail.validated:

                abort("MailmanConfigurationError")
            elif not email_to:
                abort("ContactPageMissingEmailToError")

            if request.method == "POST":
                email = request.form.get("email")
                subject = request.form.get("subject")
                message = request.form.get("message")
                name = request.form.get("name")

                flash_message = "Message sent. Thank you!"
                flash_type = "success"

                if recaptcha.verify():

                    if not email or not subject or not message:
                        flash_message = "All fields are required"
                        flash_type = "error"
                    elif not utils.is_valid_email(email):
                        flash_message = "Invalid email address"
                        flash_type = "error"
                    else:
                        try:
                            mail.send(to=email_to,
                                      reply_to=email,
                                      mail_from=email,
                                      mail_subject=subject,
                                      mail_message=message,
                                      mail_name=name,
                                      template="contact-us.txt")
                        except Exception as ex:
                            logging.exception(ex)
                            abort("MailmanConfigurationError")
                else:
                    flash_message = "Security code is invalid"
                    flash_type = "error"

                flash(flash_message, flash_type)

                return redirect(url_for(return_to))

            self.meta_tags(title="Contact Us")

            return None
Exemple #2
0
        def contact_page(self):

            # Email to
            email_to = kwargs.pop("email_to", self.get_config("APPLICATION_CONTACT_EMAIL", None))

            if not mail.validated:

                abort("MailmanConfigurationError")
            elif not email_to:
                abort("ContactPageMissingEmailToError")

            if request.method == "POST":
                email = request.form.get("email")
                subject = request.form.get("subject")
                message = request.form.get("message")
                name = request.form.get("name")

                flash_message = "Message sent. Thank you!"
                flash_type = "success"

                if recaptcha.verify():

                    if not email or not subject or not message:
                        flash_message = "All fields are required"
                        flash_type = "error"
                    elif not utils.is_valid_email(email):
                        flash_message = "Invalid email address"
                        flash_type = "error"
                    else:
                        try:
                            mail.send(to=email_to,
                                         reply_to=email,
                                         mail_from=email,
                                         mail_subject=subject,
                                         mail_message=message,
                                         mail_name=name,
                                         template="contact-us.txt")
                        except Exception as ex:
                            logging.exception(ex)
                            abort("MailmanConfigurationError")
                else:
                    flash_message = "Security code is invalid"
                    flash_type = "error"

                flash(flash_message, flash_type)

                return redirect(url_for(return_to))

            self.meta_tags(title="Contact Us")

            return None
Exemple #3
0
def setup_admin_user_publisher():
    """
    Setup Juice User and Publisher Admin
    :return:
    """

    # ==== Setup User Admin === #

    admin_email = conf.APPLICATION_ADMIN_EMAIL
    if not admin_email:
        print("ERROR: APPLICATION_ADMIN_EMAIL is empty")
        exit()

    password = utils.generate_random_string()
    if user.setup(model.User,
                  admin_email=admin_email,
                  password=password):

        if mail.validated:
            body = "Admin Password: %s" % password
            mail.send(to=admin_email, subject="Admin Password", body=body)

        print("---- Setup SUPER ADMIN User ----")
        print(("- Admin Email: %s" % admin_email))
        print(("- Admin Password: %s" % password))
        print(("-" * 40))
        print("")

    # ==== Setup Publisher === #

    # admin user
    admin_user = model.User.User.get_by_email(admin_email)

    # Set default categories and post types
    post_categories = ["Uncategorized"]
    post_types = ["Page", "Blog", "Document", "Other"]

    if admin_user and admin_user.role.name.lower() == "superadmin":
        print("---- Setup PUBLISHER ----")
        if publisher.setup(model.Publisher,
                           admin_user_id=admin_user.id,
                           post_types=post_types,
                           post_categories=post_categories):
            print("Completed")
        print(("-" * 40))
        print("")
Exemple #4
0
        def _send_reset_password(self, user):
            delivery = self.get_config("USER_AUTH_PASSWORD_RESET_METHOD")
            token_reset_ttl = self.get_config("USER_AUTH_TOKEN_RESET_TTL", 60)
            new_password = None
            if delivery.upper() == "TOKEN":
                token = user.set_temp_login(token_reset_ttl)
                url = url_for(endpoint_namespace % "reset_password",
                              token=token,
                              _external=True)
            else:
                new_password = user.set_password(password=None, random=True)
                url = url_for(endpoint_namespace % "login", _external=True)

            mail.send(template="reset-password.txt",
                         method_=delivery,
                         to=user.email,
                         name=user.email,
                         url=url,
                         new_password=new_password)
Exemple #5
0
        def _send_reset_password(self, user):
            delivery = self.get_config("USER_AUTH_PASSWORD_RESET_METHOD")
            token_reset_ttl = self.get_config("USER_AUTH_TOKEN_RESET_TTL", 60)
            new_password = None
            if delivery.upper() == "TOKEN":
                token = user.set_temp_login(token_reset_ttl)
                url = url_for(endpoint_namespace % "reset_password",
                              token=token,
                              _external=True)
            else:
                new_password = user.set_password(password=None, random=True)
                url = url_for(endpoint_namespace % "login", _external=True)

            mail.send(template="reset-password.txt",
                      method_=delivery,
                      to=user.email,
                      name=user.email,
                      url=url,
                      new_password=new_password)
Exemple #6
0
def setup_admin_user_publisher():
    """
    Setup Juice User and Publisher Admin
    :return:
    """

    # ==== Setup User Admin === #

    admin_email = conf.APPLICATION_ADMIN_EMAIL
    if not admin_email:
        print("ERROR: APPLICATION_ADMIN_EMAIL is empty")
        exit()

    password = utils.generate_random_string()
    if user.setup(model.User, admin_email=admin_email, password=password):

        if mail.validated:
            body = "Admin Password: %s" % password
            mail.send(to=admin_email, subject="Admin Password", body=body)

        print("---- Setup SUPER ADMIN User ----")
        print("- Admin Email: %s" % admin_email)
        print("- Admin Password: %s" % password)
        print("-" * 40)
        print("")

    # ==== Setup Publisher === #

    # admin user
    admin_user = model.User.User.get_by_email(admin_email)

    # Set default categories and post types
    post_categories = ["Uncategorized"]
    post_types = ["Page", "Blog", "Document", "Other"]

    if admin_user and admin_user.role.name.lower() == "superadmin":
        print("---- Setup PUBLISHER ----")
        if publisher.setup(
            model.Publisher, admin_user_id=admin_user.id, post_types=post_types, post_categories=post_categories
        ):
            print("Completed")
        print("-" * 40)
        print("")