-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfb.py
More file actions
40 lines (36 loc) · 1.63 KB
/
fb.py
File metadata and controls
40 lines (36 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import firebase_admin
from firebase_admin import credentials, db, storage
if not firebase_admin._apps:
cred = credentials.Certificate("credentials.json")
firebase_admin.initialize_app(cred, {"databaseURL": "https://limble-30e8a-default-rtdb.asia-southeast1.firebasedatabase.app/"})
def add_user(user_data,user_type):
ref = db.reference('/')
user_ref = ref.child(user_type) #or mentee
user_ref.push().set(user_data)
print(f"New {user_type} added successfully.")
def check_user(user_type,email,pwd):
if not firebase_admin._apps:
cred = credentials.Certificate("credentials.json")
firebase_admin.initialize_app(cred, {"databaseURL": "https://limble-30e8a-default-rtdb.asia-southeast1.firebasedatabase.app/",'storageBucket': 'limble-30e8a.appspot.com'})
ref = db.reference('/')
user_ref = ref.child(user_type) #or mentee
details=user_ref.get()
flag=0
for i in details:
if email==details[i]["email"] and pwd==details[i]["password"]:
flag=1
name=details[i]["name"]
mentee_details=details[i]
if flag==1:
return [True,name,mentee_details]
else:
return [False]
def link(file):
if not firebase_admin._apps:
cred = credentials.Certificate("credentials.json")
firebase_admin.initialize_app(cred, {'storageBucket': 'your-storage-bucket-name.appspot.com'}) # Replace with your bucket name
bucket = storage.bucket(name='limble-30e8a.appspot.com')
blob = bucket.blob(file.filename)
blob.upload_from_string(file.read(), content_type=file.content_type)
blob.make_public()
return blob.public_url