Beispiel #1
0
        def signup(self):
            """
            For Email Signup
            :return:
            """
            self._login_enabled()
            self._signup_enabled()
            self.meta_(title="Signup")

            if request.method == "POST":
                # reCaptcha
                if not recaptcha.verify():
                    flash_error("Invalid Security code")
                    return redirect(url_for("UserAccount:signup", next=request.form.get("next")))
                try:
                    name = request.form.get("name")
                    email = request.form.get("email")
                    password = request.form.get("password")
                    password2 = request.form.get("password2")
                    profile_image_url = request.form.get("profile_image_url", None)

                    if not name:
                        raise ViewError("Name is required")
                    elif not utils.is_valid_email(email):
                        raise ViewError("Invalid email address '%s'" % email)
                    elif not password.strip() or password.strip() != password2.strip():
                        raise ViewError("Passwords don't match")
                    elif not utils.is_valid_password(password):
                        raise ViewError("Invalid password")
                    else:
                        new_account = User.new(
                            email=email,
                            password=password.strip(),
                            first_name=name,
                            profile_image_url=profile_image_url,
                            signup_method="email",
                        )

                        self.login_user(new_account)
                        return redirect(request.form.get("next") or url_for(on_signin_view))
                except Exception as ex:
                    flash_error(ex.message)
                return redirect(url_for("UserAccount:signup", next=request.form.get("next")))

            logout_user()
            return self.render_(login_url_next=request.args.get("next", ""), view_template_=template_page % "signup")
Beispiel #2
0
    def contact_page(self):

        if not self.config_("MAILER_URI") \
                or not self.config_("MODULE_CONTACT_PAGE_EMAIL"):
            abort(500, "Mailer Error. Invalid [ MAILER_URI ] "
                       "or [ MODULE_CONTACT_PAGE_EMAIL ] is missing or empty")

        contact_email = self.config_("MODULE_CONTACT_PAGE_EMAIL")

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

            if recaptcha.verify():
                if not email or not subject or not message:
                    error_message = "All fields are required"
                elif not utils.is_valid_email(email):
                    error_message = "Invalid email address"
                if error_message:
                    flash_error(error_message)
                else:
                    mailer.send_template("contact-us.txt",
                                         to=contact_email,
                                         reply_to=email,
                                         mail_from=email,
                                         mail_subject=subject,
                                         mail_message=message,
                                         mail_name=name)
                    flash_success("Message sent. Thank you!")
            else:
                flash_error("Security code is invalid")
            return redirect(url_for("ContactPage"))
        else:
            self.meta_(title="Contact Us")
            return dict(view_template_=template_page % "contact_page")