Phase 1
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from flask import Blueprint, render_template, redirect, url_for, flash, request
|
||||
from flask_login import login_user, logout_user, login_required
|
||||
from app import db
|
||||
from app.models.user import User
|
||||
|
||||
bp = Blueprint('auth', __name__, url_prefix='/auth')
|
||||
|
||||
@bp.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
if request.method == 'POST':
|
||||
username = request.form.get('username')
|
||||
password = request.form.get('password')
|
||||
|
||||
user = User.query.filter_by(username=username).first()
|
||||
|
||||
if user and user.check_password(password):
|
||||
login_user(user)
|
||||
next_page = request.args.get('next')
|
||||
return redirect(next_page or url_for('dashboard.index'))
|
||||
else:
|
||||
flash('Invalid username or password', 'danger')
|
||||
|
||||
return render_template('login.html')
|
||||
|
||||
@bp.route('/logout')
|
||||
@login_required
|
||||
def logout():
|
||||
logout_user()
|
||||
flash('You have been logged out successfully', 'success')
|
||||
return redirect(url_for('auth.login'))
|
||||
@@ -0,0 +1,10 @@
|
||||
from flask import Blueprint, render_template
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
bp = Blueprint('dashboard', __name__)
|
||||
|
||||
@bp.route('/')
|
||||
@bp.route('/dashboard')
|
||||
@login_required
|
||||
def index():
|
||||
return render_template('dashboard.html', user=current_user)
|
||||
@@ -0,0 +1,7 @@
|
||||
from flask import Blueprint
|
||||
|
||||
bp = Blueprint('inspections', __name__, url_prefix='/inspections')
|
||||
|
||||
@bp.route('/')
|
||||
def index():
|
||||
return "Inspections module - Coming in Phase 2"
|
||||
@@ -0,0 +1,7 @@
|
||||
from flask import Blueprint
|
||||
|
||||
bp = Blueprint('reports', __name__, url_prefix='/reports')
|
||||
|
||||
@bp.route('/')
|
||||
def index():
|
||||
return "Reports module - Coming in Phase 2"
|
||||
@@ -0,0 +1,7 @@
|
||||
from flask import Blueprint
|
||||
|
||||
bp = Blueprint('templates', __name__, url_prefix='/templates')
|
||||
|
||||
@bp.route('/')
|
||||
def index():
|
||||
return "Templates module - Coming in Phase 2"
|
||||
Reference in New Issue
Block a user