2020-10-05 20:53:40 +00:00
|
|
|
import pyrebase
|
|
|
|
|
|
|
|
firebaseConfig = {
|
|
|
|
'apiKey': "AIzaSyAdL0W5HscjEDFPK4BDi6Cnc7FLa30GPYY",
|
|
|
|
'authDomain': "vehicleantitheftrecognition.firebaseapp.com",
|
|
|
|
'databaseURL': "https://vehicleantitheftrecognition.firebaseio.com",
|
|
|
|
'projectId': "vehicleantitheftrecognition",
|
|
|
|
'storageBucket': "vehicleantitheftrecognition.appspot.com",
|
|
|
|
'messagingSenderId': "163692530359",
|
|
|
|
'appId': "1:163692530359:web:b6dc7ccfc56a79afb11b32",
|
2020-10-12 16:10:01 +00:00
|
|
|
'measurementId': "G-EPWP2LK89Q",
|
|
|
|
'serviceAccount': 'vehicleantitheftrecognition-firebase-adminsdk-krrgw-05da515de5.json'
|
2020-10-14 14:10:37 +00:00
|
|
|
}
|
2020-10-05 20:53:40 +00:00
|
|
|
|
|
|
|
firebase = pyrebase.initialize_app(firebaseConfig)
|
|
|
|
db = firebase.database()
|
|
|
|
auth = firebase.auth()
|
|
|
|
storage = firebase.storage()
|
|
|
|
|
2020-10-12 16:10:01 +00:00
|
|
|
|
2020-10-14 14:10:37 +00:00
|
|
|
# Create account function which creates a new authentication info.
|
2020-10-14 14:17:42 +00:00
|
|
|
def create_account(username, password, confirm_password):
|
2020-10-14 14:10:37 +00:00
|
|
|
email = username + "@hotmail.com"
|
2020-10-14 14:17:42 +00:00
|
|
|
if password == confirm_password:
|
2020-10-14 14:10:37 +00:00
|
|
|
auth.create_user_with_email_and_password(email, password)
|
2020-10-14 14:17:42 +00:00
|
|
|
print("Account successfully created.")
|
2020-10-14 14:10:37 +00:00
|
|
|
else:
|
|
|
|
print("Confirmed password doesn't match to other password.")
|
|
|
|
|
|
|
|
|
|
|
|
# Login function which verifies the given authentication info.
|
|
|
|
def login(username, password):
|
|
|
|
email = username + "@hotmail.com"
|
|
|
|
try:
|
|
|
|
auth.sign_in_with_email_and_password(email, password)
|
|
|
|
print("Successfully Logged in.")
|
|
|
|
except:
|
|
|
|
print("Invalid username or password.")
|
|
|
|
|
|
|
|
|
|
|
|
# Uploads the data of specified user uploaded into firebase.
|
2020-10-14 14:17:42 +00:00
|
|
|
def upload_data(user_id, firstname, lastname, email, phone, address):
|
2020-10-14 14:10:37 +00:00
|
|
|
data = {"First Name": firstname, "Last Name": lastname, "E-Mail": email, "Phone": phone, "Address": address}
|
2020-10-14 14:17:42 +00:00
|
|
|
db.child("Users").child(user_id).set(data)
|
2020-10-14 14:10:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Removes the data of specified user uploaded into firebase.
|
2020-10-14 14:17:42 +00:00
|
|
|
def remove_data(user_id):
|
|
|
|
db.child("Users").child(user_id).remove()
|
2020-10-14 14:10:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Returns the first name or else an empty string.
|
2020-10-14 14:17:42 +00:00
|
|
|
def get_firstname(user_id):
|
2020-11-18 02:56:47 +00:00
|
|
|
firstname = db.child("Users").child(str(user_id)).child("First Name").get().val()
|
2020-10-14 14:10:37 +00:00
|
|
|
return firstname
|
|
|
|
|
|
|
|
|
|
|
|
# Returns the last name or else an empty string.
|
2020-10-14 14:17:42 +00:00
|
|
|
def get_lastname(user_id):
|
2020-11-18 02:56:47 +00:00
|
|
|
lastname = db.child("Users").child(str(user_id)).child("Last Name").get().val()
|
2020-10-14 14:10:37 +00:00
|
|
|
return lastname
|
|
|
|
|
|
|
|
|
|
|
|
# Returns the e-mail or else an empty string.
|
2020-10-14 14:17:42 +00:00
|
|
|
def get_email(user_id):
|
2020-11-18 02:56:47 +00:00
|
|
|
email = db.child("Users").child(str(user_id)).child("E-Mail").get().val()
|
2020-10-14 14:10:37 +00:00
|
|
|
return email
|
|
|
|
|
|
|
|
|
|
|
|
# Returns the phone or else an empty string.
|
2020-10-14 14:17:42 +00:00
|
|
|
def get_phone(user_id):
|
2020-11-18 02:56:47 +00:00
|
|
|
phone = db.child("Users").child(str(user_id)).child("Phone").get().val()
|
2020-10-14 14:10:37 +00:00
|
|
|
return phone
|
|
|
|
|
|
|
|
|
|
|
|
# Returns the address or else an empty string.
|
2020-10-14 14:17:42 +00:00
|
|
|
def get_address(user_id):
|
2020-11-18 02:56:47 +00:00
|
|
|
address = db.child("Users").child(str(user_id)).child("Address").get().val()
|
2020-10-14 14:10:37 +00:00
|
|
|
return address
|
|
|
|
|
|
|
|
|
2020-11-14 20:25:24 +00:00
|
|
|
# Uploads the photos of user, input should be something like "example.jpg"
|
2020-11-14 17:28:50 +00:00
|
|
|
def upload_user_photo(user_id):
|
|
|
|
storage.child("Photos_of_Users/" + user_id).put("Facial_images/face_rec/train/" + user_id)
|
2020-10-14 14:10:37 +00:00
|
|
|
|
|
|
|
|
2020-11-14 20:25:24 +00:00
|
|
|
# Uploads the photos of thief, input should be something like "example.jpg"
|
2020-11-14 17:28:50 +00:00
|
|
|
def upload_thief_photo(thief_id):
|
|
|
|
storage.child("Photos_of_Thieves/" + thief_id).put("Facial_images/face_rec/train/" + thief_id)
|
2020-10-14 14:10:37 +00:00
|
|
|
|
|
|
|
|
2020-11-14 20:25:24 +00:00
|
|
|
# Downloads the specified user's photos, input should be something like "example.jpg"
|
|
|
|
def download_user_photo(user_id):
|
|
|
|
storage.child("Photos_of_Users/" + user_id).download("Facial_images/face_rec/train/" + user_id)
|
2020-10-14 14:10:37 +00:00
|
|
|
|
|
|
|
|
2020-11-14 20:25:24 +00:00
|
|
|
# Downloads the specified thief's photos, input should be something like "example.jpg"
|
|
|
|
def download_thief_photo(thief_id):
|
|
|
|
storage.child("Photos_of_Thieves/" + thief_id).download("Photos_of_Thieves/" + thief_id)
|
2020-10-14 14:10:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Deletes photo of the specified user.
|
2020-10-14 14:17:42 +00:00
|
|
|
def delete_user_photo(user_photo):
|
|
|
|
storage.delete('Photos_of_Users/' + user_photo)
|
2020-11-05 17:09:20 +00:00
|
|
|
|
2020-11-05 17:14:27 +00:00
|
|
|
|
2020-11-05 17:09:20 +00:00
|
|
|
# Deletes photo of the specified thief.
|
|
|
|
def delete_thief_photo(user_photo):
|
2020-11-14 17:28:50 +00:00
|
|
|
storage.delete('Photos_of_Thieves/' + user_photo)
|
2020-11-18 02:56:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Motor signal getter
|
|
|
|
def get_motor():
|
|
|
|
motor = db.child("signal").child("1").child("motor").get().val()
|
|
|
|
return motor
|
|
|
|
|
|
|
|
|
|
|
|
# Motor signal setter
|
|
|
|
def set_motor(motor):
|
|
|
|
data = {"motor": motor}
|
|
|
|
db.child("signal").child("1").set(data)
|
|
|
|
|
|
|
|
|
|
|
|
# Alarm signal getter
|
|
|
|
def get_alarm():
|
|
|
|
alarm = db.child("signal").child("1").child("alarm").get().val()
|
|
|
|
return alarm
|
|
|
|
|
|
|
|
|
|
|
|
# Alarm signal setter
|
|
|
|
def set_alarm(alarm):
|
|
|
|
data = {"alarm": alarm}
|
|
|
|
db.child("signal").child("1").set(data)
|
|
|
|
|
|
|
|
|
|
|
|
# Power signal getter
|
|
|
|
def get_power():
|
|
|
|
alarm = db.child("signal").child("1").child("power").get().val()
|
|
|
|
return alarm
|
|
|
|
|
|
|
|
|
|
|
|
# Power signal setter
|
|
|
|
def set_power(power):
|
|
|
|
data = {"power": power}
|
|
|
|
db.child("signal").child("1").set(data)
|