Update main.py
Browse files
main.py
CHANGED
|
@@ -19,22 +19,22 @@ from langchain.schema.runnable import Runnable, RunnablePassthrough, RunnableLam
|
|
| 19 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 20 |
from langchain_core.prompts import PromptTemplate
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
|
| 39 |
@cl.author_rename
|
| 40 |
def rename(orig_author: str):
|
|
|
|
| 19 |
from langchain.prompts import ChatPromptTemplate, MessagesPlaceholder
|
| 20 |
from langchain_core.prompts import PromptTemplate
|
| 21 |
|
| 22 |
+
@cl.password_auth_callback
|
| 23 |
+
def auth_callback(username: str, password: str):
|
| 24 |
+
auth = json.loads(os.environ['CHAINLIT_AUTH_LOGIN'])
|
| 25 |
+
ident = next(d['ident'] for d in auth if d['ident'] == username)
|
| 26 |
+
pwd = next(d['pwd'] for d in auth if d['ident'] == username)
|
| 27 |
+
resultLogAdmin = bcrypt.checkpw(username.encode('utf-8'), bcrypt.hashpw(ident.encode('utf-8'), bcrypt.gensalt()))
|
| 28 |
+
resultPwdAdmin = bcrypt.checkpw(password.encode('utf-8'), bcrypt.hashpw(pwd.encode('utf-8'), bcrypt.gensalt()))
|
| 29 |
+
resultRole = next(d['role'] for d in auth if d['ident'] == username)
|
| 30 |
+
if resultLogAdmin and resultPwdAdmin and resultRole == "admindatapcc":
|
| 31 |
+
return cl.User(
|
| 32 |
+
identifier=ident + " : π§βπΌ Admin Datapcc", metadata={"role": "admin", "provider": "credentials"}
|
| 33 |
+
)
|
| 34 |
+
elif resultLogAdmin and resultPwdAdmin and resultRole == "userdatapcc":
|
| 35 |
+
return cl.User(
|
| 36 |
+
identifier=ident + " : π§βπ User Datapcc", metadata={"role": "user", "provider": "credentials"}
|
| 37 |
+
)
|
| 38 |
|
| 39 |
@cl.author_rename
|
| 40 |
def rename(orig_author: str):
|