swapnil-dev #6
@@ -1,5 +1,8 @@
|
|||||||
from flask import Blueprint, render_template, request, redirect, url_for, flash, session
|
from flask import Blueprint, render_template, request, redirect, url_for, flash, session
|
||||||
|
<<<<<<< HEAD
|
||||||
import os
|
import os
|
||||||
|
=======
|
||||||
|
>>>>>>> b9a8b9c0a9c322c129ac50b3dec0ffb3c6d82a83
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from ldap3 import Server, Connection, ALL
|
from ldap3 import Server, Connection, ALL
|
||||||
from ldap3.core.exceptions import LDAPException
|
from ldap3.core.exceptions import LDAPException
|
||||||
@@ -13,10 +16,14 @@ class LoginAuth:
|
|||||||
# -------------------------------
|
# -------------------------------
|
||||||
# LDAP CONFIGURATION
|
# LDAP CONFIGURATION
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
<<<<<<< HEAD
|
||||||
self.LDAP_SERVER = os.getenv(
|
self.LDAP_SERVER = os.getenv(
|
||||||
"LDAP_SERVER",
|
"LDAP_SERVER",
|
||||||
"ldap://host.docker.internal:389"
|
"ldap://host.docker.internal:389"
|
||||||
)
|
)
|
||||||
|
=======
|
||||||
|
self.LDAP_SERVER = "ldap://localhost:389"
|
||||||
|
>>>>>>> b9a8b9c0a9c322c129ac50b3dec0ffb3c6d82a83
|
||||||
|
|
||||||
self.BASE_DN = "ou=users,dc=lcepl,dc=org" # LDAP Users DN
|
self.BASE_DN = "ou=users,dc=lcepl,dc=org" # LDAP Users DN
|
||||||
|
|
||||||
@@ -28,16 +35,30 @@ class LoginAuth:
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
username = request.form.get("username")
|
username = request.form.get("username")
|
||||||
password = request.form.get("password")
|
password = request.form.get("password")
|
||||||
|
<<<<<<< HEAD
|
||||||
if not username or not password:
|
if not username or not password:
|
||||||
flash("Username and password are required!", "danger")
|
flash("Username and password are required!", "danger")
|
||||||
return render_template("login.html")
|
return render_template("login.html")
|
||||||
user_dn = f"uid={username},{self.BASE_DN}"
|
user_dn = f"uid={username},{self.BASE_DN}"
|
||||||
server = Server(self.LDAP_SERVER, get_info=ALL)
|
server = Server(self.LDAP_SERVER, get_info=ALL)
|
||||||
|
=======
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
>>>>>>> b9a8b9c0a9c322c129ac50b3dec0ffb3c6d82a83
|
||||||
try:
|
try:
|
||||||
# Attempt LDAP bind
|
# Attempt LDAP bind
|
||||||
conn = Connection(server, user=user_dn, password=password, auto_bind=True)
|
conn = Connection(server, user=user_dn, password=password, auto_bind=True)
|
||||||
if conn.bound:
|
if conn.bound:
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
|
=======
|
||||||
|
>>>>>>> b9a8b9c0a9c322c129ac50b3dec0ffb3c6d82a83
|
||||||
session['user'] = username
|
session['user'] = username
|
||||||
flash(f"Login successful! Welcome {username}", "success")
|
flash(f"Login successful! Welcome {username}", "success")
|
||||||
return redirect(url_for('welcome'))
|
return redirect(url_for('welcome'))
|
||||||
@@ -48,6 +69,7 @@ class LoginAuth:
|
|||||||
finally:
|
finally:
|
||||||
if 'conn' in locals():
|
if 'conn' in locals():
|
||||||
conn.unbind()
|
conn.unbind()
|
||||||
|
<<<<<<< HEAD
|
||||||
# GET request: show login form
|
# GET request: show login form
|
||||||
return render_template("login.html")
|
return render_template("login.html")
|
||||||
|
|
||||||
@@ -68,6 +90,12 @@ class LoginAuth:
|
|||||||
# return render_template("login.html")
|
# return render_template("login.html")
|
||||||
|
|
||||||
|
|
||||||
|
=======
|
||||||
|
|
||||||
|
# GET request: show login form
|
||||||
|
return render_template("login.html")
|
||||||
|
|
||||||
|
>>>>>>> b9a8b9c0a9c322c129ac50b3dec0ffb3c6d82a83
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
# LOGOUT ROUTE
|
# LOGOUT ROUTE
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user