datacipen commited on
Commit
b986d7f
β€’
1 Parent(s): 9d20278

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +16 -16
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
- #@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):
 
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):