Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #28 from mfdavies/signout
Browse files Browse the repository at this point in the history
Signout
  • Loading branch information
jdrco authored Jan 7, 2024
2 parents 6fb01be + c9dc71e commit e460be2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 90 deletions.
1 change: 1 addition & 0 deletions backend/conversation/READTHIS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I *Think* this is unused. Is it?
39 changes: 39 additions & 0 deletions backend/server/src/exercise/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from flask import request, jsonify, Blueprint
from firebase_admin import firestore

from firebase_admin import firestore
import tempfile
import os

exercise_blueprint = Blueprint("exercise", __name__)
db = firestore.client()
users_ref = db.collection("practitioners")

session = {}


@exercise_blueprint.route('/get_all', methods=['GET'])
def get_all():
try:
practitioner = request.args.get("practitioner")
exercises = users_ref.document(practitioner).collection("exercises").get()

exercise_list = []
for exercise in exercises:
exercise_data = exercise.to_dict()
exercise_data["id"] = exercise.id # Add the ID to the exercise data
exercise_list.append(exercise_data)

return jsonify({"exercises": exercise_list}), 200
except Exception as e:
return jsonify({"error": str(e)}), 400

@exercise_blueprint.route('/get', methods=['GET'])
def get():
try:
practitioner = request.args.get("practitioner")
exercise_id = request.args.get("exercise")
exercise_data = users_ref.document(practitioner).collection("exercises").document(exercise_id).get().to_dict()
return jsonify({"exercise": exercise_data}), 200
except Exception as e:
return jsonify({"error": str(e)}), 400
90 changes: 1 addition & 89 deletions backend/server/src/main.py
Original file line number Diff line number Diff line change
@@ -1,89 +1 @@
from flask import Flask, request, jsonify, render_template
from flask_mail import Mail, Message
from dotenv import load_dotenv
import os
from constants import *
import time
import firebase_admin
from firebase_admin import credentials
from flask_cors import CORS

load_dotenv()
app = Flask(__name__)
app.secret_key = os.getenv("SECRET_KEY")


def create_service_dict():
variables_keys = {
"type": os.getenv("TYPE"),
"project_id": os.getenv("PROJECT_ID"),
"private_key_id": os.getenv("PRIVATE_KEY_ID"),
"private_key": os.getenv("PRIVATE_KEY"),
"client_email": os.getenv("CLIENT_EMAIL"),
"client_id": os.getenv("CLIENT_ID"),
"auth_uri": os.getenv("AUTH_URI"),
"token_uri": os.getenv("TOKEN_URI"),
"auth_provider_x509_cert_url": os.getenv("AUTH_PROVIDER_X509_CERT_URL"),
"client_x509_cert_url": os.getenv("CLIENT_X509_CERT_URL"),
"universe_domain": os.getenv("UNIVERSE_DOMAIN"),
}
return variables_keys


cred = credentials.Certificate(create_service_dict())
firebase_admin.initialize_app(cred)

from conversation.views import conversation_blueprint

# Register the conversation Blueprint
app.register_blueprint(conversation_blueprint, url_prefix="/conversation")
CORS(app)

# Load Flask-Mail config from .env
app.config["MAIL_SERVER"] = os.getenv("MAIL_SERVER")
app.config["MAIL_PORT"] = int(os.getenv("MAIL_PORT"))
app.config["MAIL_USE_TLS"] = os.getenv("MAIL_USE_TLS").lower() == "true"
app.config["MAIL_USERNAME"] = os.getenv("MAIL_USERNAME")
app.config["MAIL_PASSWORD"] = os.getenv("MAIL_PASSWORD")
app.config["MAIL_DEFAULT_SENDER"] = os.getenv("MAIL_DEFAULT_SENDER")
mail = Mail(app)


@app.route("/patient/send-link", methods=["POST"])
def send_link():
try:
data = request.get_json()
practitionId = data.get("practitionId")
patientId = data.get("patientId")
name = data.get("name")
email = data.get("email")

# Send patient email with login link
message = Message(
subject=EMAIL_SUBJECT,
recipients=[email],
body=EMAIL_BODY_TEMPLATE.format(
name=name, practitionId=practitionId, patientId=patientId
),
)
mail.send(message)

return jsonify({"success": True, "message": "Email sent successfully"})

except Exception as e:
return jsonify({"success": False, "error": str(e)}), 500


def format_server_time():
server_time = time.localtime()
return time.strftime("%I:%M:%S %p", server_time)


@app.route("/")
def index():
context = {"server_time": format_server_time()}
return render_template("index.html", context=context)


if __name__ == "__main__":
app.run(debug=True, port=os.getenv("PORT", default=5000))

22 changes: 21 additions & 1 deletion frontend/src/views/practitioner/components/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
import { auth } from "../../../../firebaseConfig";
import { useNavigate } from "react-router-dom";



const Navbar = () => {
const navigate = useNavigate();

const handleLogout = async () => {
const confirmLogout = window.confirm("Are you sure you want to sign out?");
if (confirmLogout) {
auth.signOut().then(function() {
navigate('/');
console.log('Worked');
}).catch(function(error) {
console.error('Error signing out:', error);
});

}
};

return (
<div className="navbar bg-base-100">
<div className="flex-1">
Expand Down Expand Up @@ -46,7 +66,7 @@ const Navbar = () => {
<a>Settings</a>
</li>
<li>
<a>Logout</a>
<a onClick={handleLogout}>Logout</a>
</li>
</ul>
</div>
Expand Down

0 comments on commit e460be2

Please sign in to comment.