Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

[NeuralChat] Support user management in backend server #952

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
029ab8f
Support user management backend part
lvliang-intel Dec 17, 2023
c12f7ec
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 24, 2024
912d190
fix ut issues
lvliang-intel Jan 24, 2024
b19e91e
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 24, 2024
68998d6
fix copyright
lvliang-intel Jan 24, 2024
d17e1ff
fix pylint issues
lvliang-intel Jan 25, 2024
dbdd3b4
support IntelLDAP
lvliang-intel Jan 26, 2024
b9b0a95
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 26, 2024
97972c9
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 30, 2024
36a54b5
update code
lvliang-intel Jan 30, 2024
6f3ece9
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 30, 2024
4cff30d
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 31, 2024
cbdbb38
fix pylint issue
lvliang-intel Jan 31, 2024
ded96da
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 31, 2024
072a19c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2024
abc55bf
fix email issue
lvliang-intel Jan 31, 2024
5707d8a
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Jan 31, 2024
8bd4ad3
Merge branch 'lvl/user_management' of https://github.com/intel/intel-…
lvliang-intel Jan 31, 2024
80c2915
only verify account and password
lvliang-intel Feb 2, 2024
180a970
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Feb 2, 2024
59cc602
fix pylint
lvliang-intel Feb 2, 2024
b0768ee
Merge branch 'main' of https://github.com/intel/intel-extension-for-t…
lvliang-intel Feb 2, 2024
63798e7
Merge branch 'main' into lvl/user_management
lvliang-intel Feb 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
support IntelLDAP
Signed-off-by: lvliang-intel <[email protected]>
lvliang-intel committed Jan 26, 2024
commit dbdd3b454705697076a372b49cc007eae48d5852
Original file line number Diff line number Diff line change
@@ -41,6 +41,20 @@ class OAuthAccount(SQLAlchemyBaseOAuthAccountTableUUID, Base):
class User(SQLAlchemyBaseUserTableUUID, Base):
role = Column(String(length=50), default='user', nullable=False)
is_vipuser = Column(Boolean, default=False, nullable=False)
wwid = Column(String(length=50), nullable=True)
email_address = Column(String(length=255), nullable=True)
account = Column(String(length=50), nullable=True)
name = Column(String(length=255), nullable=True)
given_name = Column(String(length=255), nullable=True)
distinguished_name = Column(String(length=255), nullable=True)
idsid = Column(String(length=50), nullable=True)
generic = Column(Boolean, default=False, nullable=False)
SuperGroup = Column(String(length=50), nullable=True)
Group = Column(String(length=50), nullable=True)
Division = Column(String(length=50), nullable=True)
DivisionLong = Column(String(length=255), nullable=True)
CostCenterLong = Column(String(length=255), nullable=True)
mgrWWID = Column(String(length=50), nullable=True)

oauth_accounts: Mapped[List[OAuthAccount]] = relationship(
"OAuthAccount", lazy="joined"
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
import yaml
import logging
from yacs.config import CfgNode
from fastapi import FastAPI, Depends
from fastapi import FastAPI, Depends, HTTPException
from fastapi import APIRouter
from starlette.middleware.cors import CORSMiddleware
from .base_executor import BaseCommandExecutor
@@ -39,12 +39,11 @@
from ..chatbot import build_chatbot
from ..plugins import plugins
from transformers import BitsAndBytesConfig
from .user.users import auth_backend, current_active_user, fastapi_users
from .user.users import auth_backend, current_active_user, fastapi_users, UserManager, get_user_manager
from .schemas.user import UserCreate, UserRead, UserUpdate
from .database.user_db import User, create_db_and_tables
from .user.users import SECRET, google_oauth_client, github_oauth_client, facebook_oauth_client, microsoft_oauth_client


__all__ = ['NeuralChatServerExecutor']

app = FastAPI(
@@ -398,3 +397,26 @@ def __call__(self,
@app.get("/authenticated-route")
async def authenticated_route(user: User = Depends(current_active_user)):
return {"message": f"Hello {user.email}!"}

@app.post("/intel/login")
async def login(
credentials: dict,
user_manager: UserManager = Depends(get_user_manager)
):
try:
username = credentials.get("account")
password = credentials.get("password")

from LDAPclient import IntelLDAP
user_manager.ldap_client = IntelLDAP(user=username, password=password)
user = await user_manager.fastapi_users.authenticate(
{"email": username, "password": password},
user_manager.db
)

if user is None:
raise HTTPException(status_code=401, detail="LDAP authentication failed")

return {"msg": "Login successful", "user_id": user.id}
except HTTPException as e:
return {"msg": "Login failed", "error_detail": e.detail}
Original file line number Diff line number Diff line change
@@ -24,14 +24,53 @@
class UserRead(schemas.BaseUser[uuid.UUID]):
role: str
is_vipuser: bool = False

wwid: Optional[str] = None
email_address: Optional[str] = None
account: Optional[str] = None
name: Optional[str] = None
given_name: Optional[str] = None
distinguished_name: Optional[str] = None
idsid: Optional[str] = None
generic: bool = False
SuperGroup: Optional[str] = None
Group: Optional[str] = None
Division: Optional[str] = None
DivisionLong: Optional[str] = None
CostCenterLong: Optional[str] = None
mgrWWID: Optional[str] = None

class UserCreate(schemas.BaseUserCreate):
role: Optional[str] = 'user'
is_vipuser: bool = False

wwid: Optional[str] = None
email_address: Optional[str] = None
account: Optional[str] = None
name: Optional[str] = None
given_name: Optional[str] = None
distinguished_name: Optional[str] = None
idsid: Optional[str] = None
generic: bool = False
SuperGroup: Optional[str] = None
Group: Optional[str] = None
Division: Optional[str] = None
DivisionLong: Optional[str] = None
CostCenterLong: Optional[str] = None
mgrWWID: Optional[str] = None

class UserUpdate(schemas.BaseUserUpdate):
role: Optional[str]
is_vipuser: Optional[bool]

wwid: Optional[str] = None
email_address: Optional[str] = None
account: Optional[str] = None
name: Optional[str] = None
given_name: Optional[str] = None
distinguished_name: Optional[str] = None
idsid: Optional[str] = None
generic: bool = False
SuperGroup: Optional[str] = None
Group: Optional[str] = None
Division: Optional[str] = None
DivisionLong: Optional[str] = None
CostCenterLong: Optional[str] = None
mgrWWID: Optional[str] = None