Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -30,12 +30,19 @@ import bcrypt
|
|
| 30 |
|
| 31 |
@cl.password_auth_callback
|
| 32 |
def auth_callback(username: str, password: str):
|
| 33 |
-
resultLogAdmin = bcrypt.checkpw(username.encode('utf-8'), bcrypt.hashpw(os.environ['CHAINLIT_AUTH_LOGIN'].encode('utf-8'), bcrypt.gensalt()))
|
| 34 |
-
resultPwdAdmin = bcrypt.checkpw(password.encode('utf-8'), bcrypt.hashpw(os.environ['CHAINLIT_AUTH_PASSWD'].encode('utf-8'), bcrypt.gensalt()))
|
| 35 |
-
if
|
|
|
|
|
|
|
|
|
|
| 36 |
return cl.User(
|
| 37 |
identifier="🧑💼 Admin Datapcc", metadata={"role": "admin", "provider": "credentials"}
|
| 38 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
def modele(document):
|
| 41 |
if document == "Note de composante sectorielle":
|
|
|
|
| 30 |
|
| 31 |
@cl.password_auth_callback
|
| 32 |
def auth_callback(username: str, password: str):
|
| 33 |
+
#resultLogAdmin = bcrypt.checkpw(username.encode('utf-8'), bcrypt.hashpw(os.environ['CHAINLIT_AUTH_LOGIN'].encode('utf-8'), bcrypt.gensalt()))
|
| 34 |
+
#resultPwdAdmin = bcrypt.checkpw(password.encode('utf-8'), bcrypt.hashpw(os.environ['CHAINLIT_AUTH_PASSWD'].encode('utf-8'), bcrypt.gensalt()))
|
| 35 |
+
resultLogAdmin = bcrypt.checkpw(username.encode('utf-8'), bcrypt.hashpw(next(d['ident'] for d in os.environ['CHAINLIT_AUTH_LOGIN'] if d['ident'] == username).encode('utf-8'), bcrypt.gensalt()))
|
| 36 |
+
resultPwdAdmin = bcrypt.checkpw(password.encode('utf-8'), bcrypt.hashpw(next(d['pwd'] for d in os.environ['CHAINLIT_AUTH_LOGIN'] if d['ident'] == username).encode('utf-8'), bcrypt.gensalt()))
|
| 37 |
+
resultRole = next(d['role'] for d in os.environ['CHAINLIT_AUTH_LOGIN'] if d['ident'] == username)
|
| 38 |
+
if resultLogAdmin and resultPwdAdmin and resultRole == "admindatapcc":
|
| 39 |
return cl.User(
|
| 40 |
identifier="🧑💼 Admin Datapcc", metadata={"role": "admin", "provider": "credentials"}
|
| 41 |
)
|
| 42 |
+
elif resultLogAdmin and resultPwdAdmin and resultRole == "userdatapcc":
|
| 43 |
+
return cl.User(
|
| 44 |
+
identifier="🧑🎓 User Datapcc", metadata={"role": "user", "provider": "credentials"}
|
| 45 |
+
)
|
| 46 |
|
| 47 |
def modele(document):
|
| 48 |
if document == "Note de composante sectorielle":
|