log file added

This commit is contained in:
Swapnil9693
2026-02-17 15:25:57 +05:30
parent b8c289294d
commit 684e41e5c3
7 changed files with 228 additions and 32 deletions

View File

@@ -1,4 +1,5 @@
from flask import Blueprint, render_template, request, redirect, url_for, flash, session
import os
from functools import wraps
from ldap3 import Server, Connection, ALL
from ldap3.core.exceptions import LDAPException
@@ -12,7 +13,10 @@ class LoginAuth:
# -------------------------------
# LDAP CONFIGURATION
# -------------------------------
self.LDAP_SERVER = "ldap://localhost:389"
self.LDAP_SERVER = os.getenv(
"LDAP_SERVER",
"ldap://host.docker.internal:389"
)
self.BASE_DN = "ou=users,dc=lcepl,dc=org" # LDAP Users DN
@@ -24,18 +28,16 @@ class LoginAuth:
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'))
@@ -46,10 +48,26 @@ class LoginAuth:
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")
# # 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
# -------------------------------