Exemple #1
0
    def dispatch_request(self) -> str:
        email = flask.request.form.get("email", "")
        subject = flask.request.form.get("subject", "")
        message = flask.request.form.get("message", "")
        # Ensure all fields are populated
        if not all([email, subject, message]):
            self.logger.info("not all fields specified")
            return self.render(help_error="Please specify all fields",
                               help_active=True)

        sent_email, sent_discord = True, True

        # Send the email
        try:
            email_resp = help_post.send_help_email(flask.session["username"],
                                                   email, subject, message)
            if not str(email_resp.status_code).startswith("20"):
                self.logger.error(
                    f"non 20x status code for help email: {email_resp.status_code} - {email_resp.body}"
                )
            sent_email = str(email_resp.status_code).startswith("20")
        except Exception as e:
            self.logger.error(f"failed to send help email: {str(e.body)}")

        # Try and send to Discord
        try:
            sent_discord = help_post.send_help_webhook(
                flask.session["username"], email, subject, message)
        except Exception as e:
            self.logger.error(f"failed to send help discord webhook: {str(e)}")

        # Check that at least one form of communication was sent
        if not sent_email and not sent_discord:
            # If not, report an error to the user
            return self.render(
                help_error=
                "There was a problem :( Please email [email protected] instead",
                help_active=True,
            )
        # Otherwise when things are okay, report back stating so
        message = ''
        if sent_email:
            message += "sent help email"
        if sent_discord and sent_email:
            message += " and "
        if sent_discord:
            message += "fired discord webhook"
        self.logger.info(message)
        return self.render(help_success=True, help_active=True)
Exemple #2
0
    def dispatch_request(self) -> str:
        # Get the details from the form data
        email = flask.request.form["email"]
        reason = flask.request.form["reason"]
        username = flask.session["username"]
        email_failed = False
        discord_failed = False

        # Try to send the email
        try:
            email_resp = help_post.send_sudo_request_email(username, email)
            if not str(email_resp.status_code).startswith("20"):
                self.logger.error(
                    f"non 20x status code for help email: {email_resp.status_code} - {email_resp.body}"
                )
            email_failed = not str(email_resp.status_code).startswith("20")
        except Exception as e:
            email_failed = True
            self.logger.error(f"failed to send email: {e}")

        # Try to send a message to the Discord
        try:
            subject = "Feynman Account Request"
            msg = f"This user wants an account on Feynman pls.\nReason: {reason}"
            discord_failed = help_post.send_help_webhook(
                username, email, subject, msg)
        except Exception as e:
            discord_failed = True
            self.logger.error(f"failed to fire discord webhook: {e}")

        if discord_failed and email_failed:
            caption = "There was a problem :("
            message = "Please email [email protected] instead!"
        else:
            caption = "Success!"
            message = "A confirmation email has been sent to you. We will be in touch shortly." + \
                "<br/>Return to <a href='/tools'>tools page</a>."
        # Return an appropriate response depending on whether or not the message sent
        return self.render(
            caption=caption,
            message=message,
        )