Пример #1
0
def reset_request():
    form = RequestResetForm()
    if form.validate_on_submit():
        logout_user()
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            confirm_url = generate_password_reset_url(user.email)
            html = render_template(
                "auth/email_password_reset_confirmation.html",
                confirm_url=confirm_url,
                first_name=user.first_name,
                last_name=user.last_name,
            )
            subject = "Reset password request"
            send_email(user.email, subject, html)
            flash(
                "An email has been sent with instructions to reset your password.",
                "info",
            )
            log(
                log.DEBUG,
                "An email has been sent with instructions to reset your password.",
            )
    return render_template(
        "auth/reset_password_request.html",
        title="Reset Password",
        form=form,
        dashboards=accessed_links(),
    )
Пример #2
0
def the_third_dash_app():
    return render_template(
        "dashapps/dash_app.html",
        dash_url=the_third_dash_app_obj.URL_BASE,
        min_height=the_third_dash_app_obj.MIN_HEIGHT,
        dashboards=accessed_links(),
    )
Пример #3
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
        user = User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data,
            country=form.country.data,
            organization=form.organization.data,
        )
        user.set_password(form.password.data)
        user.save()
        # login_user(user)
        flash("Registration successful.", "success")
        log(log.DEBUG, "Registration successful.")

        # SEND CONFIRMATION EMAIL
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            confirm_url = generate_password_reset_url(user.email)
            html = render_template(
                "auth/email_signup_confirmation.html",
                confirm_url=confirm_url,
                first_name=user.first_name,
                last_name=user.last_name,
                email=user.email,
            )
            subject = "Greetings from Visual Approach Analytics!"
            send_email(user.email, subject, html)
            log(
                log.DEBUG,
                "A confirmation email has been sent.",
            )

        return redirect(url_for("auth.signin"))
    elif form.is_submitted():
        for error in form.errors:
            for msg in form.errors[error]:
                log(log.ERROR, "signup(): %s", msg)
                flash(msg, "danger")
    return render_template("auth/register.html",
                           form=form,
                           dashboards=accessed_links())
Пример #4
0
def signin():
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is None or not user.check_password(form.password.data):
            flash("Wrong email or password.", "danger")
            log(log.ERROR, "Wrong email or password.")
            return redirect(url_for("auth.signin"))
        user.authenticated = True
        user.save()
        login_user(user)
        # flash("Login successful.", "success")
        log(log.DEBUG, "Login successful.")
        return redirect(url_for("main.index"))
    return render_template("auth/login.html",
                           form=form,
                           dashboards=accessed_links())
Пример #5
0
def reset_password(token):
    email = "unknown"
    try:
        email = confirm_token(token)
    except Exception:
        flash("The confirmation link is invalid or has expired.", "danger")
        log(log.ERROR, "The confirmation link is invalid or has expired.")
    user = User.query.filter_by(email=email).first_or_404()
    if not user:
        flash("That is an invalid or expired token.", "warning")
        log(log.ERROR, "That is an invalid or expired token.")
        return redirect(url_for("auth.signin"))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        user.save()
        flash("Your password has been changed!", "info")
        log(log.DEBUG, "Your password has been changed!")
        return redirect(url_for("auth.signin"))
    return render_template("auth/reset_token.html",
                           form=form,
                           dashboards=accessed_links())
Пример #6
0
def index():
    return render_template("index.html", dashboards=accessed_links())