modification of report, froms, models

This commit is contained in:
2026-02-17 16:54:43 +05:30
parent b8c289294d
commit 0ba78a0bd1
25 changed files with 92 additions and 404 deletions

View File

@@ -19,37 +19,50 @@ class LoginAuth:
# -------------------------------
# LOGIN ROUTE
# -------------------------------
# @self.bp.route('/login', methods=['GET', 'POST'])
# def login():
# if request.method == 'POST':
# username = request.form.get("username")
# password = request.form.get("password")
# if not username or not password:
# flash("Username and password are required!", "danger")
# return render_template("login.html")
# user_dn = f"uid={username},{self.BASE_DN}"
# server = Server(self.LDAP_SERVER, get_info=ALL)
# try:
# # Attempt LDAP bind
# conn = Connection(server, user=user_dn, password=password, auto_bind=True)
# if conn.bound:
# session['user'] = username
# flash(f"Login successful! Welcome {username}", "success")
# return redirect(url_for('welcome'))
# else:
# flash("Invalid username or password!", "danger")
# except LDAPException as e:
# flash(f"LDAP login failed: {str(e)}", "danger")
# finally:
# if 'conn' in locals():
# conn.unbind()
# # GET request: show login form
# return render_template("login.html")
# LOGIN ROUTE
@self.bp.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form.get("username")
password = request.form.get("password")
if not username or not password:
flash("Username and password are required!", "danger")
return render_template("login.html")
user_dn = f"uid={username},{self.BASE_DN}"
server = Server(self.LDAP_SERVER, get_info=ALL)
try:
# Attempt LDAP bind
conn = Connection(server, user=user_dn, password=password, auto_bind=True)
if conn.bound:
session['user'] = username
flash(f"Login successful! Welcome {username}", "success")
return redirect(url_for('welcome'))
else:
flash("Invalid username or password!", "danger")
except LDAPException as e:
flash(f"LDAP login failed: {str(e)}", "danger")
finally:
if 'conn' in locals():
conn.unbind()
# GET request: show login form
# Dummy validation — REPLACE with DB check later
if username == "admin" and password == "admin123":
session['user'] = username
flash("Login successful!", "success")
return redirect(url_for('welcome'))
else:
flash("Invalid username or password!", "danger")
return render_template("login.html")
# -------------------------------
# LOGOUT ROUTE
# -------------------------------