Exemplo n.º 1
0
def login():
    form = loginForm()

    if (request.method == "GET"):
        return render_template("login.html", form=form)

    elif (request.method == "POST"):
        if (form.validate()):
            username = form.username.data
            password = form.password.data
            if (user_validate_credentials(username, password)):
                user = User()
                user.id = username
                flask_login.login_user(user)

                #check to see if default credentials are being used. If so, redirect to change password page.
                if (user_validate_credentials("admin", "gosecure")):
                    flash("Please change the default password.", "notice")
                    return redirect(url_for("user"))
                else:
                    internet_status_bool = internet_status()
                    vpn_status_bool = vpn_status()
                    vpn_configuration_status_bool = vpn_configuration_status()

                    #check to see if network is up. If not, redirect to network page
                    if (internet_status_bool == False
                            and vpn_configuration_status_bool == True):
                        flash("Internet is not reachable.", "notice")
                        return redirect(url_for("wifi"))
                    #check to see if network and vpn are up. If not, redirect to initial setup page
                    elif (internet_status_bool == False
                          and vpn_status_bool == False):
                        return redirect(url_for("initial_setup"))
                    #check to see if vpn is up. If not, redirect to vpn page
                    elif (vpn_status_bool == False):
                        flash("VPN is not established.", "notice")
                        return redirect(url_for("vpn_psk"))
                    else:
                        return redirect(
                            request.args.get("next") or url_for("status"))
            else:
                flash("Invalid username or password. Please try again.",
                      "error")
                return render_template("login.html", form=form)
        else:
            flash_form_errors(form)
            return render_template("login.html", form=form)
Exemplo n.º 2
0
def login():
    form = loginForm()

    if request.method == "GET":
        return render_template("login.html", form=form) 

    elif request.method == "POST":
        if form.validate():
            username = form.username.data
            password = form.password.data
            if user_validate_credentials(username, password):
                user = User()
                user.id = username
                flask_login.login_user(user)
                
                # check to see if default credentials are being used. If so, redirect to change password page.
                if user_validate_credentials("admin", "gosecure"):
                    flash("Please change the default password.", "notice")
                    return redirect(url_for("user"))
                else:
                    internet_status_bool = internet_status()
                    vpn_status_bool = vpn_status()
                    vpn_configuration_status_bool = vpn_configuration_status()

                    # check to see if network is up. If not, redirect to network page
                    if internet_status_bool is False and vpn_configuration_status_bool is True:
                        flash("Internet is not reachable.", "notice")
                        return redirect(url_for("wifi"))
                    # check to see if network and vpn are up. If not, redirect to initial setup page
                    elif internet_status_bool is False and vpn_status_bool is False:
                        return redirect(url_for("initial_setup"))
                    # check to see if vpn is up. If not, redirect to vpn page
                    elif vpn_status_bool is False:
                        flash("VPN is not established.", "notice")
                        return redirect(url_for("vpn_psk"))
                    else:
                        return redirect(request.args.get("next") or url_for("status"))
            else:
                flash("Invalid username or password. Please try again.", "error")
                return render_template("login.html", form=form)
        else:
            flash_form_errors(form)
            return render_template("login.html", form=form)