mirror of
https://github.com/TakeusV1/flask_ipam.git
synced 2026-10-14 01:15:33 +02:00
V1.0
This commit is contained in:
1 parent
0980efcd24
commit
f11aa2d6c6
22 files changed
+491
No files matched your search
@@ -0,0 +1,26 @@
|
||||
from datetime import datetime
|
||||
from flask import Blueprint, request, render_template, flash, url_for, redirect, abort
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
from app._config import app_version
|
||||
|
||||
from app.extensions import *
|
||||
from app.models import *
|
||||
|
||||
admin = Blueprint('admin', __name__)
|
||||
|
||||
@admin.route('/')
|
||||
@login_required
|
||||
def home():
|
||||
if current_user.is_admin:
|
||||
return redirect(url_for('admin.dash'))
|
||||
else:
|
||||
return abort(403)
|
||||
|
||||
@admin.route('/dashboard')
|
||||
@login_required
|
||||
def dash():
|
||||
if current_user.is_admin == False:
|
||||
return abort(403)
|
||||
|
||||
return f"Welcome {current_user.username} to the admin dashboard"
|
||||
@@ -0,0 +1,45 @@
|
||||
from datetime import datetime
|
||||
from flask import Blueprint, request, render_template, flash, abort, redirect, url_for, jsonify
|
||||
from flask_login import login_required, current_user, login_user, logout_user
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
from app._config import *
|
||||
|
||||
from app.extensions import *
|
||||
from app.models import *
|
||||
from app.forms import LoginForm
|
||||
|
||||
auth = Blueprint('auth', __name__)
|
||||
|
||||
@auth.route("/login",methods=['GET','POST'])
|
||||
def login():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for('base.dashboard'))
|
||||
|
||||
form = LoginForm()
|
||||
if form.validate_on_submit():
|
||||
user = User.query.filter_by(username=form.username.data).first()
|
||||
if user != None:
|
||||
if user.password != None:
|
||||
if check_password_hash(user.password,form.password.data):
|
||||
login_user(user)
|
||||
|
||||
user.dat_last = datetime.now()
|
||||
db.session.commit()
|
||||
|
||||
return redirect(url_for("base.dashboard"))
|
||||
|
||||
flash("Bad username or password !", 'danger')
|
||||
return render_template("auth/login.html", title="Login", form=form, bad_password=True)
|
||||
return render_template('auth/login.html', title="Login", form=form)
|
||||
|
||||
@auth.route("/change",methods=['GET','POST'])
|
||||
@login_required
|
||||
def change():
|
||||
pass
|
||||
|
||||
@auth.route("/logout")
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
return redirect(url_for('auth.login'))
|
||||
@@ -0,0 +1,23 @@
|
||||
from datetime import datetime
|
||||
from flask import Blueprint, request, render_template, flash, redirect, url_for
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
from app._config import app_version
|
||||
|
||||
from app.extensions import *
|
||||
from app.models import *
|
||||
|
||||
base = Blueprint('base', __name__)
|
||||
|
||||
@base.route('/',methods=['GET','POST'])
|
||||
def home():
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for('base.dashboard'))
|
||||
else:
|
||||
return redirect(url_for('auth.login'))
|
||||
|
||||
@base.route('/dashboard',methods=['GET','POST'])
|
||||
@login_required
|
||||
def dashboard():
|
||||
|
||||
return render_template('panel/dashboard.html', title="Dashboard", is_dash=True, app_version=app_version)
|
||||
Reference in new issue
Block a user