mgbam commited on
Commit
48c65d9
·
verified ·
1 Parent(s): 02847d6

Create services/auth.py

Browse files
Files changed (1) hide show
  1. services/auth.py +24 -0
services/auth.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_authenticator import Authenticate
3
+ from config.settings import settings
4
+ from repositories.user_repo import UserRepo
5
+
6
+ user_repo = UserRepo(settings.database_url)
7
+
8
+ def init_auth():
9
+ users = user_repo.get_all_users()
10
+ creds = {u.username: {"name": u.full_name, "password": u.hashed_password} for u in users}
11
+ return Authenticate(
12
+ credentials=creds,
13
+ cookie_name="quantum_healthcare_auth",
14
+ key=settings.secret_key,
15
+ cookie_expiry_days=1,
16
+ )
17
+
18
+ authenticator = init_auth()
19
+
20
+ def require_login():
21
+ name, authentication_status, username = authenticator.login("Login", "sidebar")
22
+ if not authentication_status:
23
+ st.stop()
24
+ return username