mirror of
https://github.com/imartinez/privateGPT.git
synced 2025-06-28 16:26:56 +00:00
updated with bug fixes for ad login
This commit is contained in:
parent
a87531c141
commit
b050052840
10
.env
10
.env
@ -15,11 +15,11 @@ SECRET_KEY=ba9dc3f976cf8fb40519dcd152a8d7d21c0b7861d841711cdb2602be8e85fd7c
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES=60
|
||||
REFRESH_TOKEN_EXPIRE_MINUTES = 120 # 7 days
|
||||
|
||||
SMTP_SERVER=smtp.gmail.com
|
||||
SMTP_PORT=587
|
||||
SMTP_SENDER_EMAIL=shresthasaurab030@outlook.com
|
||||
SMTP_USERNAME=shresthasaurab030
|
||||
SMTP_PASSWORD=huurxwxeorxjorzw
|
||||
SMTP_SERVER=mail.gibl.com.np
|
||||
SMTP_PORT=25
|
||||
SMTP_SENDER_EMAIL=noreply@gibl.com.np
|
||||
SMTP_USERNAME=noreply@gibl.com.np
|
||||
SMTP_PASSWORD=*G15y^N0reP!y
|
||||
|
||||
LDAP_SERVER=ldap://192.168.101.111
|
||||
LDAP_ENABLE=True
|
@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
LDAP_SERVER = settings.LDAP_SERVER
|
||||
# LDAP_ENABLE = settings.LDAP_ENABLE
|
||||
LDAP_ENABLE = False
|
||||
LDAP_ENABLE = True
|
||||
|
||||
router = APIRouter(prefix="/auth", tags=["auth"])
|
||||
|
||||
@ -118,16 +118,16 @@ def login_access_token(
|
||||
"""
|
||||
OAuth2 compatible token login, get an access token for future requests
|
||||
"""
|
||||
def ad_auth():
|
||||
def ad_auth(LDAP_ENABLE):
|
||||
if LDAP_ENABLE:
|
||||
existing_user = crud.user.get_by_email(db, email=form_data.username)
|
||||
|
||||
if existing_user:
|
||||
if existing_user.user_role.role.name == "SUPER_ADMIN":
|
||||
return True
|
||||
return existing_user
|
||||
else:
|
||||
username, department = ldap_login(db=db, username=form_data.username, password=form_data.password)
|
||||
return True
|
||||
return crud.user.get_by_name(db, name=username)
|
||||
else:
|
||||
username, department = ldap_login(db=db, username=form_data.username, password=form_data.password)
|
||||
depart = crud.department.get_by_department_name(db, name=department)
|
||||
@ -142,7 +142,7 @@ def login_access_token(
|
||||
return None
|
||||
|
||||
if LDAP_ENABLE:
|
||||
user = ad_auth()
|
||||
user = ad_auth(LDAP_ENABLE)
|
||||
if not user:
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
|
@ -7,7 +7,7 @@ from typing import Dict, Any, Optional, Union
|
||||
from jose import JWTError, jwt
|
||||
from passlib.context import CryptContext
|
||||
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES = 60 * 12 # 12 hrs
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES = 60 * 24 * 1 # 12 hrs
|
||||
REFRESH_TOKEN_EXPIRE_MINUTES = 60 * 24 * 7 # 7 days
|
||||
ALGORITHM = "HS256"
|
||||
# JWT_SECRET_KEY = os.environ['JWT_SECRET_KEY'] # should be kept secret
|
||||
|
@ -39,7 +39,7 @@ def send_registration_email(fullname: str, email: str, random_password: str) ->
|
||||
|
||||
try:
|
||||
with smtplib.SMTP(settings.SMTP_SERVER, settings.SMTP_PORT) as server:
|
||||
server.starttls()
|
||||
# server.starttls()
|
||||
server.login(settings.SMTP_USERNAME, settings.SMTP_PASSWORD)
|
||||
server.sendmail(settings.SMTP_SENDER_EMAIL, email, msg.as_string())
|
||||
except Exception as e:
|
||||
|
Loading…
Reference in New Issue
Block a user