New Version
This commit is contained in:
71
app/routes2.py
Normal file
71
app/routes2.py
Normal file
@@ -0,0 +1,71 @@
|
||||
from flask import flash, redirect, render_template, url_for
|
||||
from flask_login import current_user, login_required, login_user, logout_user
|
||||
|
||||
from app import app
|
||||
from app.forms import LoginForm, WPAForm
|
||||
from app.models import Passwords, User
|
||||
from app.network_utils import scan_networks, connect_network, disconnect_network
|
||||
|
||||
|
||||
@app.route("/")
|
||||
@app.route("/index")
|
||||
@login_required
|
||||
def index():
|
||||
return render_template("index.html", networks=scan_networks())
|
||||
|
||||
|
||||
@app.route("/login", methods=["GET", "POST"])
|
||||
def login():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for("index"))
|
||||
form = LoginForm()
|
||||
if form.validate_on_submit():
|
||||
user = User.query.filter_by(username=form.username.data).first()
|
||||
if user is None or not user.check_password(form.password.data):
|
||||
flash("Invalid username or password")
|
||||
return redirect(url_for("login"))
|
||||
login_user(user)
|
||||
return redirect(url_for("index"))
|
||||
return render_template("login.html", title="Sign In", form=form)
|
||||
|
||||
|
||||
@app.route("/logout")
|
||||
def logout():
|
||||
logout_user()
|
||||
return redirect(url_for("index"))
|
||||
|
||||
|
||||
@app.route("/connect/<string:ssid>&<string:security>", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def connect(ssid, security):
|
||||
if security == "WPA2":
|
||||
return redirect(url_for("connectwpa", ssid=ssid))
|
||||
|
||||
result = connect_network(ssid, security, "")
|
||||
if result:
|
||||
return render_template("message.html", message="Successfully connected to {}".format(ssid))
|
||||
|
||||
return render_template("message.html", message="Failt to connected to {}".format(ssid))
|
||||
|
||||
|
||||
@app.route("/wpa/<ssid>", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def connectwpa(ssid):
|
||||
form = WPAForm()
|
||||
if form.validate_on_submit():
|
||||
result = connect_network(ssid, "WPA2", form.password.data)
|
||||
if result:
|
||||
return render_template("message.html", message="Successfully connected to {}".format(ssid))
|
||||
|
||||
return render_template("message.html", message="Failt to connected to {}".format(ssid))
|
||||
|
||||
return render_template("wpa.html", title="WPA Password", form=form)
|
||||
|
||||
|
||||
@app.route("/disconnect/<string:ssid>", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def disconnect(ssid):
|
||||
if disconnect_network(ssid):
|
||||
return render_template("message.html", message="Sucessfully disconnected from {}".format(ssid))
|
||||
|
||||
return render_template("message.html", message="Failt to disconnect from {}".format(ssid))
|
||||
Reference in New Issue
Block a user