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

added route for sending patient login link via email #4

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/venv
/venv
*.env
*.pyc
54 changes: 46 additions & 8 deletions backend/server/src/app.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,55 @@
from flask import Flask, render_template, make_response
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

load_dotenv()
app = Flask(__name__)

# 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()
uid = data.get("uid")
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, uid=uid),
)
mail.send(message)

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

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


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

@app.route('/')

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


if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=int(os.environ.get('PORT', 8080)))
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))
17 changes: 17 additions & 0 deletions backend/server/src/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Patient login email content
EMAIL_SUBJECT = "MobilityMate Account Access"
EMAIL_BODY_TEMPLATE = """Dear {name},

Welcome to MobilityMate - your dedicated partner in staying active and healthy! 🌟

To access your personalized exercise account and stay up to date with exercises recommended by your practitioner, simply click on the link below:

🔗 www.example.com/patient/{uid}

Your well-being is our priority! If you have any questions or need support, our team is here to assist you every step of the way.

Stay active, stay healthy!

Best regards,
The MobilityMate Team 🏋️‍♂️
"""