chandralegend commited on
Commit
3657410
1 Parent(s): eff79d4

addedauthentication

Browse files
.sessions/chandra_irugalbandara/level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ 0
requirements.txt CHANGED
@@ -0,0 +1 @@
 
 
1
+ firebase_admin
utils/__pycache__/login.cpython-310.pyc CHANGED
Binary files a/utils/__pycache__/login.cpython-310.pyc and b/utils/__pycache__/login.cpython-310.pyc differ
 
utils/login.py CHANGED
@@ -1,5 +1,10 @@
1
  import streamlit as st
2
  import os
 
 
 
 
 
3
 
4
 
5
  def initialize_login():
@@ -7,9 +12,9 @@ def initialize_login():
7
  st.columns(3)[1].image("assets/logo.png")
8
  username = st.text_input("Username")
9
  password = st.text_input("Password", type="password")
 
10
  if st.button("Login"):
11
- # TODO: replace with actual authorization check
12
- authorized = {"status": True, "Name": "John Doe", "username": "johndoe"}
13
  if authorized["status"]:
14
  st.session_state["login"] = authorized
15
  os.makedirs(
@@ -24,5 +29,31 @@ def initialize_login():
24
  st.sidebar.success(f'Hello, {st.session_state["login"]["Name"]}!')
25
 
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  def get_login():
28
  return st.session_state.get("login", {"status": False})
 
1
  import streamlit as st
2
  import os
3
+ import requests
4
+ import os
5
+ import json
6
+
7
+ # Fetch the service account key JSON file contents
8
 
9
 
10
  def initialize_login():
 
12
  st.columns(3)[1].image("assets/logo.png")
13
  username = st.text_input("Username")
14
  password = st.text_input("Password", type="password")
15
+
16
  if st.button("Login"):
17
+ authorized = authenticate(username, password)
 
18
  if authorized["status"]:
19
  st.session_state["login"] = authorized
20
  os.makedirs(
 
29
  st.sidebar.success(f'Hello, {st.session_state["login"]["Name"]}!')
30
 
31
 
32
+ def authenticate(username, password):
33
+ FIREBASE_WEB_API_KEY = os.environ.get("FIREBASE_WEB_API_KEY")
34
+ payload = json.dumps(
35
+ {
36
+ "email": f"{username}@aieye.com",
37
+ "password": password,
38
+ "returnSecureToken": False,
39
+ }
40
+ )
41
+
42
+ rest_api_url = (
43
+ f"https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword"
44
+ )
45
+ r = requests.post(rest_api_url, params={"key": FIREBASE_WEB_API_KEY}, data=payload)
46
+ print(r.json())
47
+
48
+ if r.status_code == 200:
49
+ return {
50
+ "status": True,
51
+ "Name": " ".join(username.split("_")),
52
+ "username": username,
53
+ }
54
+ else:
55
+ return {"status": False}
56
+
57
+
58
  def get_login():
59
  return st.session_state.get("login", {"status": False})