Example #1
0
def settings():
    infos = get_infos()

    user = get_current_user()
    name = user.name
    email = user.email
    website = user.website
    affiliation = user.affiliation
    country = user.country

    tokens = UserTokens.query.filter_by(user_id=user.id).all()

    prevent_name_change = get_config("prevent_name_change")

    if get_config("verify_emails") and not user.verified:
        confirm_url = markup(url_for("auth.confirm"))
        infos.append(
            markup(
                "Your email address isn't confirmed!<br>"
                "Please check your email to confirm your email address.<br><br>"
                f'To have the confirmation email resent please <a href="{confirm_url}">click here</a>.'
            ))

    return render_template(
        "settings.html",
        name=name,
        email=email,
        website=website,
        affiliation=affiliation,
        country=country,
        tokens=tokens,
        prevent_name_change=prevent_name_change,
        infos=infos,
    )
Example #2
0
 def js(self, asset_key):
     asset = self.manifest()[asset_key]
     entry = asset["file"]
     imports = asset.get("imports", [])
     html = ""
     for i in imports:
         # TODO: Needs a better recursive solution
         i = self.manifest()[i]["file"]
         url = url_for("views.themes_beta", path=i)
         html += f'<script defer type="module" src="{url}"></script>'
     url = url_for("views.themes_beta", path=entry)
     html += f'<script defer type="module" src="{url}"></script>'
     return markup(html)
Example #3
0
 def scripts(self):
     application_root = current_app.config.get("APPLICATION_ROOT")
     subdir = application_root != "/"
     scripts = []
     for script in get_registered_scripts():
         if script.startswith("http"):
             scripts.append(f'<script defer src="{script}"></script>')
         elif subdir:
             scripts.append(
                 f'<script defer src="{application_root}/{script}"></script>'
             )
         else:
             scripts.append(f'<script defer src="{script}"></script>')
     return markup("\n".join(scripts))
Example #4
0
 def styles(self):
     application_root = current_app.config.get("APPLICATION_ROOT")
     subdir = application_root != "/"
     _styles = []
     for stylesheet in get_registered_stylesheets():
         if stylesheet.startswith("http"):
             _styles.append(
                 f'<link rel="stylesheet" type="text/css" href="{stylesheet}">'
             )
         elif subdir:
             _styles.append(
                 f'<link rel="stylesheet" type="text/css" href="{application_root}/{stylesheet}">'
             )
         else:
             _styles.append(
                 f'<link rel="stylesheet" type="text/css" href="{stylesheet}">'
             )
     return markup("\n".join(_styles))
Example #5
0
File: auth.py Project: HackRU/CTFd
def reset_password(data=None):
    if config.can_send_mail() is False:
        return render_template(
            "reset_password.html",
            errors=[
                markup(
                    "This CTF is not configured to send email.<br> Please contact an organizer to have your password reset."
                )
            ],
        )

    if data is not None:
        try:
            email_address = unserialize(data, max_age=1800)
        except (BadTimeSignature, SignatureExpired):
            return render_template(
                "reset_password.html", errors=["Your link has expired"]
            )
        except (BadSignature, TypeError, base64.binascii.Error):
            return render_template(
                "reset_password.html", errors=["Your reset token is invalid"]
            )

        if request.method == "GET":
            return render_template("reset_password.html", mode="set")
        if request.method == "POST":
            password = request.form.get("password", "").strip()
            user = Users.query.filter_by(email=email_address).first_or_404()
            if user.oauth_id:
                return render_template(
                    "reset_password.html",
                    infos=[
                        "Your account was registered via an authentication provider and does not have an associated password. Please login via your authentication provider."
                    ],
                )

            pass_short = len(password) == 0
            if pass_short:
                return render_template(
                    "reset_password.html", errors=["Please pick a longer password"]
                )

            user.password = password
            db.session.commit()
            clear_user_session(user_id=user.id)
            log(
                "logins",
                format="[{date}] {ip} -  successful password reset for {name}",
                name=user.name,
            )
            db.session.close()
            email.password_change_alert(user.email)
            return redirect(url_for("auth.login"))

    if request.method == "POST":
        email_address = request.form["email"].strip()
        user = Users.query.filter_by(email=email_address).first()

        get_errors()

        if not user:
            return render_template(
                "reset_password.html",
                infos=[
                    "If that account exists you will receive an email, please check your inbox"
                ],
            )

        if user.oauth_id:
            return render_template(
                "reset_password.html",
                infos=[
                    "The email address associated with this account was registered via an authentication provider and does not have an associated password. Please login via your authentication provider."
                ],
            )

        email.forgot_password(email_address)

        return render_template(
            "reset_password.html",
            infos=[
                "If that account exists you will receive an email, please check your inbox"
            ],
        )
    return render_template("reset_password.html")
Example #6
0
    def theme_footer(self):
        from CTFd.utils.helpers import markup

        return markup(get_config("theme_footer", default=""))
Example #7
0
    def html(self):
        from CTFd.utils.config.pages import build_html
        from CTFd.utils.helpers import markup

        return markup(build_html(self.content))
Example #8
0
 def css(self, asset_key):
     asset = self.manifest_css()[asset_key]
     entry = asset["file"]
     url = url_for("views.themes_beta", path=entry)
     return markup(f'<link rel="stylesheet" href="{url}">')
Example #9
0
    def html(self):
        from CTFd.utils.config.pages import build_markdown
        from CTFd.utils.helpers import markup

        return markup(build_markdown(self.content, sanitize=True))
Example #10
0
    def html(self):
        from CTFd.utils.config.pages import build_markdown
        from CTFd.utils.helpers import markup

        return markup(build_markdown(self.description))