-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
84 lines (74 loc) · 2.1 KB
/
config.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pyrebase
from flask import session,flash
from datetime import datetime
config = {
"apiKey": "#########################################",
"authDomain": "#########################",
"databaseURL": "#################################",
"projectId": "############",
"storageBucket": "######################",
"messagingSenderId": "############"
}
firebase = pyrebase.initialize_app(config)
auth=firebase.auth()
db = firebase.database()
def register_with_email_and_password(name,phone,email,password):
try:
user=auth.create_user_with_email_and_password(email,password)
auth.send_email_verification(user['idToken'])
Register(name,email,phone)
return True
except:
return False
def signin_with_email_and_password(email,password):
try:
user=auth.sign_in_with_email_and_password(email,password)
session['username'] = user['email']
session['id'] = user['localId']
jsonv = profiledata().val()
for key in jsonv:
session['name']=jsonv[key]['name']
session['phone']=jsonv[key]['phone']
return True
except:
return False
def reset_password_with_email(email):
try:
auth.send_password_reset_email(email)
return True
except:
return False
def sendMessage(name,phoneNum,email,message):
data = {
"name": name ,
"email": email ,
"phone": phoneNum ,
"message": message
}
db.child("messages").push(data)
def Register(name,email,phoneNum):
data = {
"name": name ,
"email": email ,
"phone": phoneNum ,
}
db.child("users").child(session['id']).push(data)
def historify(id,query,ip):
data = {
"query": query ,
"time": str(datetime.now()) ,
"ip": str(ip) ,
}
db.child("history").child(id).push(data)
def isLoggedIn():
if 'username' in session:
return True
else:
return False
def profiledata():
return db.child("users").child(session['id']).get()
def history():
try:
return db.child("history").child(session['id']).get()
except:
return False