From 88f6e8259d1eb9d67b07ad28aa603c3ff73023d0 Mon Sep 17 00:00:00 2001 From: ameye Date: Sun, 26 Apr 2026 20:45:48 -0400 Subject: [PATCH] Added AWS SES email --- SQL/site_data.sql | 2 + app/api/routes/routes.py | 9 ++++- app/api/services/office_dashboard.py | 58 ++++++++++++++++++++++++++-- app/notifications/mail_factory.py | 48 +++++++++++++++++++++++ 4 files changed, 112 insertions(+), 5 deletions(-) diff --git a/SQL/site_data.sql b/SQL/site_data.sql index a5e79f6..e8d06fb 100644 --- a/SQL/site_data.sql +++ b/SQL/site_data.sql @@ -859,7 +859,9 @@ ALTER TABLE office_users ALTER COLUMN password TYPE VARCHAR(250); ALTER TABLE office_users OWNER TO merms_panel; INSERT INTO office_users (username, password, firstname, lastname, acc_level) VALUES ('mermsadmin','password','Merms','Admin',1000); +INSERT INTO office_users (username, password, firstname, lastname, acc_level) VALUES ('adminsanya','password','Sanya','Ameye',1000); +-- Dr.Sanya.Alan1! CREATE TABLE products_contacts( diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index d00a2be..6ec80af 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -741,7 +741,7 @@ def get_subscription_transaction_office(): def get_recent_signup_office(): # Call the dashboard service filters = {} - result = OfficeDashboardService.get_payments_data(filters) + result = OfficeDashboardService.get_recent_signup_data(filters) return jsonify(result) @@ -930,3 +930,10 @@ def refresh(): # logger.info(f"Authorize refresh request received: {data}") response = AuthorizationService.process_refresh_request() return response + + +@api.route("/cron/report-subscription", methods=["GET"]) +def report_subs(): + data = {} + AccountService.process_test_email(data) + return {"status": "ok"}, 200 \ No newline at end of file diff --git a/app/api/services/office_dashboard.py b/app/api/services/office_dashboard.py index 5f7399b..31fbf75 100644 --- a/app/api/services/office_dashboard.py +++ b/app/api/services/office_dashboard.py @@ -6,8 +6,6 @@ from app.config import settings from app.utils.logger import logger from app.api.services.base_service import BaseService from sqlalchemy import func, desc -from datetime import datetime, timedelta, timezone -from app.extensions import db from app.models import MembersProducts, Products, Payments, Members, CustomTemplates, ProductsTemplates, MembersProfile, \ ProductsDetails, MembersWebfiles @@ -226,7 +224,6 @@ class OfficeDashboardService(BaseService): return products_result - @staticmethod def get_office_product_templates(filters): @@ -594,4 +591,57 @@ class OfficeDashboardService(BaseService): except Exception as e: logger.error(f"An error occurred while getting dashboard data: {str(e)}", exc_info=True) - return jsonify({"message": "Internal Server Error"}), 500 \ No newline at end of file + return jsonify({"message": "Internal Server Error"}), 500 + + @staticmethod + def get_recent_signup_data(filters): + try: + if filters is None: + filters = {} + + # Extract pagination parameters + page = int(filters.get('page', 1)) + limit = int(filters.get('limit', 20)) + + # Ensure page and limit are valid + if page < 1: + page = 1 + if limit < 1 or limit > 100: + limit = 20 + + membersList, total_count = Members.get_all_member(None,None,1,30) + # Convert loans to dictionary format + member_data = [] + for member in membersList: + member_data.append({ + 'id': member.id, + 'username': member.username, + 'email': member.email, + 'firstname': member.firstname, + 'lastname': member.lastname, + 'country': member.country, + 'member_uid': member.uid, + 'profile_completed': member.profile_completed, + "added": member.added, + }) + + + + response_data = { + 'members': member_data, + 'count': 30, + 'pagination': { + 'total_count': total_count, + 'total_pages': 1, + 'current_page': page, + 'limit': limit, + 'has_next': page < 1, + 'has_prev': page > 1 + } + } + + return response_data + + except Exception as e: + logger.error(f"An error occurred while getting dashboard data: {str(e)}", exc_info=True) + return jsonify({"message": "Internal Server Error"}), 500 diff --git a/app/notifications/mail_factory.py b/app/notifications/mail_factory.py index 655f216..b93cb13 100644 --- a/app/notifications/mail_factory.py +++ b/app/notifications/mail_factory.py @@ -15,6 +15,19 @@ def send_email_factory(to_email, subject, html_content, text_content=None): raise +def alert_email_factory(to_email, subject, html_content, text_content=None): + try: + send_email_ses( + to_email=to_email, + subject=subject, + html_content=alert_template(html_content) + ) + + except Exception as e: + logger.error(f"Alert_Email_Factory failed: {e}") + raise + + def body_template(html_content): html_body = f"""\ @@ -45,3 +58,38 @@ def body_template(html_content): """ return html_body + + +def alert_template(html_content): + html_body = f"""\ + + + + + + + + + + + + + + +
+ +
+ {html_content} +
+
+ LINKS --- ---- ---- ----- +
+ For any support
+ Reach Out
+ support@mermsemr.com
+ https://www.mermsemr.com/ +
+ + + """ + return html_body