diff --git a/Application/backend/backend/.env b/Application/backend/backend/.env new file mode 100644 index 0000000000000000000000000000000000000000..e3d79b39d6f1f7b617270b4429dcadea414ce159 --- /dev/null +++ b/Application/backend/backend/.env @@ -0,0 +1,4 @@ +SWTICH_ACCESS_KEY_ID=4406dbe746a24614a9bc8f7ec864e59f +SWITCH_SECRET_ACCESS_KEY=cec6e60954b24a51923fe5aaea9fbb3b +SWTICH_ENDPOINT_URL=https://os.zhdk.cloud.switch.ch +S3_BUCKET_NAME=cloud-bach-proj \ No newline at end of file diff --git a/Application/backend/backend/app.log b/Application/backend/backend/app.log new file mode 100644 index 0000000000000000000000000000000000000000..9cee2c841a0fc8ba39b7c0cb3cba513b8df98ec7 --- /dev/null +++ b/Application/backend/backend/app.log @@ -0,0 +1,164 @@ +2024-12-02 12:10:55,122 - __main__ - INFO - Starting Flask application... +2024-12-02 12:11:05,697 - __main__ - INFO - Starting Flask application... +2024-12-02 12:11:05,701 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m + * Running on all addresses (0.0.0.0) + * Running on http://127.0.0.1:8000 + * Running on http://192.168.1.93:8000 +2024-12-02 12:11:05,701 - werkzeug - INFO - [33mPress CTRL+C to quit[0m +2024-12-02 12:11:50,693 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:11:50] "OPTIONS /enroll HTTP/1.1" 200 - +2024-12-02 12:11:50,703 - __main__ - INFO - Enrollment attempt for email: test@gmail.com +2024-12-02 12:11:51,392 - __main__ - ERROR - Unexpected error: An error occurred (InvalidAccessKeyId) when calling the PutObject operation: Unknown +2024-12-02 12:11:51,396 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:11:51] "[35m[1mPOST /enroll HTTP/1.1[0m" 500 - +2024-12-02 12:19:27,242 - __main__ - INFO - Starting Flask application... +2024-12-02 12:19:27,246 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m + * Running on all addresses (0.0.0.0) + * Running on http://127.0.0.1:8000 + * Running on http://192.168.1.93:8000 +2024-12-02 12:19:27,246 - werkzeug - INFO - [33mPress CTRL+C to quit[0m +2024-12-02 12:19:42,112 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:19:42] "OPTIONS /enroll HTTP/1.1" 200 - +2024-12-02 12:19:42,115 - __main__ - INFO - Enrollment attempt for email: test@gmail.com +2024-12-02 12:19:42,700 - __main__ - ERROR - Unexpected error: An error occurred (InvalidAccessKeyId) when calling the PutObject operation: Unknown +2024-12-02 12:19:42,702 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:19:42] "[35m[1mPOST /enroll HTTP/1.1[0m" 500 - +2024-12-02 12:20:19,205 - __main__ - INFO - AWS_ACCESS_KEY_ID: AKIAVEKYIBTQEJB2XSNM +2024-12-02 12:20:19,205 - __main__ - INFO - AWS_SECRET_ACCESS_KEY: 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 +2024-12-02 12:20:19,205 - __main__ - INFO - AWS_ENDPOINT_URL: https://os.zhdk.cloud.switch.ch +2024-12-02 12:20:19,205 - __main__ - INFO - S3_BUCKET_NAME: cloud-bach-proj +2024-12-02 12:20:19,272 - __main__ - INFO - Starting Flask application... +2024-12-02 12:20:19,274 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m + * Running on all addresses (0.0.0.0) + * Running on http://127.0.0.1:8000 + * Running on http://192.168.1.93:8000 +2024-12-02 12:20:19,274 - werkzeug - INFO - [33mPress CTRL+C to quit[0m +2024-12-02 12:21:40,705 - __main__ - INFO - SWTICH_ACCESS_KEY_ID: None +2024-12-02 12:21:40,705 - __main__ - INFO - SWITCH_SECRET_ACCESS_KEY: None +2024-12-02 12:21:40,705 - __main__ - INFO - SWTICH_ENDPOINT_URL: None +2024-12-02 12:21:40,705 - __main__ - INFO - S3_BUCKET_NAME: cloud-bach-proj +2024-12-02 12:21:40,713 - botocore.credentials - INFO - Found credentials in environment variables. +2024-12-02 12:21:40,766 - botocore.configprovider - INFO - Found endpoint for s3 via: environment_global. +2024-12-02 12:21:40,770 - __main__ - INFO - Starting Flask application... +2024-12-02 12:21:40,773 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m + * Running on all addresses (0.0.0.0) + * Running on http://127.0.0.1:8000 + * Running on http://192.168.1.93:8000 +2024-12-02 12:21:40,773 - werkzeug - INFO - [33mPress CTRL+C to quit[0m +2024-12-02 12:21:51,332 - __main__ - INFO - SWTICH_ACCESS_KEY_ID: None +2024-12-02 12:21:51,332 - __main__ - INFO - SWITCH_SECRET_ACCESS_KEY: None +2024-12-02 12:21:51,332 - __main__ - INFO - SWTICH_ENDPOINT_URL: None +2024-12-02 12:21:51,332 - __main__ - INFO - S3_BUCKET_NAME: cloud-bach-proj +2024-12-02 12:21:51,340 - botocore.credentials - INFO - Found credentials in environment variables. +2024-12-02 12:21:51,389 - botocore.configprovider - INFO - Found endpoint for s3 via: environment_global. +2024-12-02 12:21:51,394 - __main__ - INFO - Starting Flask application... +2024-12-02 12:21:51,396 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m + * Running on all addresses (0.0.0.0) + * Running on http://127.0.0.1:8000 + * Running on http://192.168.1.93:8000 +2024-12-02 12:21:51,396 - werkzeug - INFO - [33mPress CTRL+C to quit[0m +2024-12-02 12:23:04,117 - __main__ - INFO - SWTICH_ACCESS_KEY_ID: None +2024-12-02 12:23:04,117 - __main__ - INFO - SWITCH_SECRET_ACCESS_KEY: None +2024-12-02 12:23:04,117 - __main__ - INFO - SWTICH_ENDPOINT_URL: None +2024-12-02 12:23:04,117 - __main__ - INFO - S3_BUCKET_NAME: None +2024-12-02 12:23:04,126 - botocore.credentials - INFO - Found credentials in environment variables. +2024-12-02 12:23:04,196 - __main__ - CRITICAL - S3_BUCKET_NAME environment variable is not set +2024-12-02 12:53:11,151 - __main__ - INFO - SWTICH_ACCESS_KEY_ID: 4406dbe746a24614a9bc8f7ec864e59f +2024-12-02 12:53:11,151 - __main__ - INFO - SWITCH_SECRET_ACCESS_KEY: cec6e60954b24a51923fe5aaea9fbb3b +2024-12-02 12:53:11,151 - __main__ - INFO - SWTICH_ENDPOINT_URL: https://os.zhdk.cloud.switch.ch +2024-12-02 12:53:11,151 - __main__ - INFO - S3_BUCKET_NAME: cloud-bach-proj +2024-12-02 12:53:11,385 - __main__ - INFO - Starting Flask application... +2024-12-02 12:53:11,391 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m + * Running on all addresses (0.0.0.0) + * Running on http://127.0.0.1:8000 + * Running on http://192.168.1.93:8000 +2024-12-02 12:53:11,391 - werkzeug - INFO - [33mPress CTRL+C to quit[0m +2024-12-02 12:53:19,651 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:53:19] "OPTIONS /enroll HTTP/1.1" 200 - +2024-12-02 12:53:19,656 - __main__ - INFO - Enrollment attempt for email: test@gmail.com +2024-12-02 12:53:20,645 - __main__ - ERROR - Unexpected error: An error occurred (NoSuchBucket) when calling the PutObject operation: Unknown +2024-12-02 12:53:20,647 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:53:20] "[35m[1mPOST /enroll HTTP/1.1[0m" 500 - +2024-12-02 12:54:00,835 - __main__ - INFO - SWTICH_ACCESS_KEY_ID: 4406dbe746a24614a9bc8f7ec864e59f +2024-12-02 12:54:00,835 - __main__ - INFO - SWITCH_SECRET_ACCESS_KEY: cec6e60954b24a51923fe5aaea9fbb3b +2024-12-02 12:54:00,835 - __main__ - INFO - SWTICH_ENDPOINT_URL: https://os.zhdk.cloud.switch.ch +2024-12-02 12:54:00,835 - __main__ - INFO - S3_BUCKET_NAME: cloud-bach-proj +2024-12-02 12:54:00,923 - __main__ - INFO - Starting Flask application... +2024-12-02 12:54:01,360 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m + * Running on all addresses (0.0.0.0) + * Running on http://127.0.0.1:8000 + * Running on http://192.168.1.93:8000 +2024-12-02 12:54:01,361 - werkzeug - INFO - [33mPress CTRL+C to quit[0m +2024-12-02 12:54:09,932 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:54:09] "OPTIONS /enroll HTTP/1.1" 200 - +2024-12-02 12:54:09,937 - __main__ - INFO - Enrollment attempt for email: test@gmail.com +2024-12-02 12:54:10,203 - __main__ - INFO - Successfully enrolled user: test@gmail.com +2024-12-02 12:54:10,205 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:54:10] "POST /enroll HTTP/1.1" 200 - +2024-12-02 12:54:19,954 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:54:19] "OPTIONS /login HTTP/1.1" 200 - +2024-12-02 12:54:19,960 - __main__ - INFO - Login attempt for email: test@gmail.com +2024-12-02 12:54:20,282 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:54:20] "POST /login HTTP/1.1" 200 - +2024-12-02 12:54:27,064 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:54:27] "OPTIONS /logout HTTP/1.1" 200 - +2024-12-02 12:54:27,069 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:54:27] "[31m[1mPOST /logout HTTP/1.1[0m" 400 - +2024-12-02 12:55:40,966 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:55:40] "OPTIONS /logout HTTP/1.1" 200 - +2024-12-02 12:55:40,971 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:55:40] "[31m[1mPOST /logout HTTP/1.1[0m" 400 - +2024-12-02 12:55:46,985 - __main__ - INFO - SWTICH_ACCESS_KEY_ID: 4406dbe746a24614a9bc8f7ec864e59f +2024-12-02 12:55:46,985 - __main__ - INFO - SWITCH_SECRET_ACCESS_KEY: cec6e60954b24a51923fe5aaea9fbb3b +2024-12-02 12:55:46,985 - __main__ - INFO - SWTICH_ENDPOINT_URL: https://os.zhdk.cloud.switch.ch +2024-12-02 12:55:46,985 - __main__ - INFO - S3_BUCKET_NAME: cloud-bach-proj +2024-12-02 12:55:47,082 - __main__ - INFO - Starting Flask application... +2024-12-02 12:55:47,580 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m + * Running on all addresses (0.0.0.0) + * Running on http://127.0.0.1:8000 + * Running on http://192.168.1.93:8000 +2024-12-02 12:55:47,580 - werkzeug - INFO - [33mPress CTRL+C to quit[0m +2024-12-02 12:55:53,216 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:55:53] "OPTIONS /login HTTP/1.1" 200 - +2024-12-02 12:55:53,221 - __main__ - INFO - Login attempt for email: test@gmail.com +2024-12-02 12:55:53,396 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:55:53] "POST /login HTTP/1.1" 200 - +2024-12-02 12:55:54,335 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:55:54] "OPTIONS /logout HTTP/1.1" 200 - +2024-12-02 12:55:54,340 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:55:54] "[31m[1mPOST /logout HTTP/1.1[0m" 400 - +2024-12-02 12:56:23,774 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:56:23] "OPTIONS /logout HTTP/1.1" 200 - +2024-12-02 12:56:23,780 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:56:23] "[31m[1mPOST /logout HTTP/1.1[0m" 400 - +2024-12-02 12:56:30,635 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:56:30] "OPTIONS /login HTTP/1.1" 200 - +2024-12-02 12:56:30,641 - __main__ - INFO - Login attempt for email: test@gmail.com +2024-12-02 12:56:31,075 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:56:31] "POST /login HTTP/1.1" 200 - +2024-12-02 12:56:32,425 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:56:32] "OPTIONS /logout HTTP/1.1" 200 - +2024-12-02 12:56:32,430 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:56:32] "[31m[1mPOST /logout HTTP/1.1[0m" 400 - +2024-12-02 12:57:02,178 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:57:02] "OPTIONS /login HTTP/1.1" 200 - +2024-12-02 12:57:02,184 - __main__ - INFO - Login attempt for email: test@gmail.com +2024-12-02 12:57:02,825 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:57:02] "POST /login HTTP/1.1" 200 - +2024-12-02 12:57:04,463 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:57:04] "OPTIONS /logout HTTP/1.1" 200 - +2024-12-02 12:57:05,167 - werkzeug - INFO - 127.0.0.1 - - [02/Dec/2024 12:57:05] "POST /logout HTTP/1.1" 200 - +2024-12-09 09:10:26,299 - __main__ - INFO - SWTICH_ACCESS_KEY_ID: 4406dbe746a24614a9bc8f7ec864e59f +2024-12-09 09:10:26,299 - __main__ - INFO - SWITCH_SECRET_ACCESS_KEY: cec6e60954b24a51923fe5aaea9fbb3b +2024-12-09 09:10:26,299 - __main__ - INFO - SWTICH_ENDPOINT_URL: https://os.zhdk.cloud.switch.ch +2024-12-09 09:10:26,299 - __main__ - INFO - S3_BUCKET_NAME: cloud-bach-proj +2024-12-09 09:10:26,615 - __main__ - INFO - Starting Flask application... +2024-12-09 09:10:27,453 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m + * Running on all addresses (0.0.0.0) + * Running on http://127.0.0.1:8000 + * Running on http://192.168.1.159:8000 +2024-12-09 09:10:27,453 - werkzeug - INFO - [33mPress CTRL+C to quit[0m +2024-12-09 09:20:42,041 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:20:42] "OPTIONS /enroll HTTP/1.1" 200 - +2024-12-09 09:20:42,045 - __main__ - INFO - Enrollment attempt for email: sapos@hotmail.com +2024-12-09 09:20:43,477 - __main__ - INFO - Successfully enrolled user: sapos@hotmail.com +2024-12-09 09:20:43,478 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:20:43] "POST /enroll HTTP/1.1" 200 - +2024-12-09 09:20:52,022 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:20:52] "OPTIONS /login HTTP/1.1" 200 - +2024-12-09 09:20:52,026 - __main__ - INFO - Login attempt for email: sapos@hotmail.com +2024-12-09 09:20:52,208 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:20:52] "[31m[1mPOST /login HTTP/1.1[0m" 401 - +2024-12-09 09:20:56,219 - __main__ - INFO - Login attempt for email: sapos@hotmail.com +2024-12-09 09:20:56,909 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:20:56] "POST /login HTTP/1.1" 200 - +2024-12-09 09:21:21,262 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:21:21] "OPTIONS /logout HTTP/1.1" 200 - +2024-12-09 09:21:21,692 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:21:21] "POST /logout HTTP/1.1" 200 - +2024-12-09 09:21:29,789 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:21:29] "OPTIONS /enroll HTTP/1.1" 200 - +2024-12-09 09:21:29,793 - __main__ - INFO - Enrollment attempt for email: fran.abm94@gmail.com +2024-12-09 09:21:30,036 - __main__ - INFO - Successfully enrolled user: fran.abm94@gmail.com +2024-12-09 09:21:30,037 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:21:30] "POST /enroll HTTP/1.1" 200 - +2024-12-09 09:21:54,239 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:21:54] "OPTIONS /login HTTP/1.1" 200 - +2024-12-09 09:21:54,242 - __main__ - INFO - Login attempt for email: fran.abm94@gmail.com +2024-12-09 09:21:54,689 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:21:54] "POST /login HTTP/1.1" 200 - +2024-12-09 09:21:56,036 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:21:56] "OPTIONS /logout HTTP/1.1" 200 - +2024-12-09 09:21:56,455 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:21:56] "POST /logout HTTP/1.1" 200 - +2024-12-09 09:21:58,042 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:21:58] "OPTIONS /enroll HTTP/1.1" 200 - +2024-12-09 09:21:58,044 - __main__ - INFO - Enrollment attempt for email: fran.abm94@gmail.com +2024-12-09 09:21:58,125 - __main__ - INFO - Enrollment failed - user already exists: fran.abm94@gmail.com +2024-12-09 09:21:58,126 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:21:58] "[31m[1mPOST /enroll HTTP/1.1[0m" 409 - +2024-12-09 09:22:05,692 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:22:05] "OPTIONS /enroll HTTP/1.1" 200 - +2024-12-09 09:22:05,694 - __main__ - INFO - Enrollment attempt for email: fran.abm@gmail.com +2024-12-09 09:22:06,199 - __main__ - INFO - Successfully enrolled user: fran.abm@gmail.com +2024-12-09 09:22:06,200 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:22:06] "POST /enroll HTTP/1.1" 200 - +2024-12-09 09:22:16,204 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:22:16] "OPTIONS /login HTTP/1.1" 200 - +2024-12-09 09:22:16,205 - __main__ - INFO - Login attempt for email: fran.abm@gmail.com +2024-12-09 09:22:16,590 - werkzeug - INFO - 127.0.0.1 - - [09/Dec/2024 09:22:16] "POST /login HTTP/1.1" 200 - diff --git a/Application/backend/backend/main.py b/Application/backend/backend/main.py new file mode 100644 index 0000000000000000000000000000000000000000..544c803dfc84c5366e46be6e564c4d32375ae6df --- /dev/null +++ b/Application/backend/backend/main.py @@ -0,0 +1,131 @@ +# Flask Server to serve the frontend pages +from flask import Flask, request, jsonify +from flask_cors import CORS +import boto3 +import json +import logging +from functools import wraps +from dotenv import load_dotenv +import os +from datetime import datetime # Added for timestamps + +# Load environment variables +load_dotenv(dotenv_path='.env') + +# Basic logging setup +logging.basicConfig(level=logging.INFO) +logger = logging.getLogger(__name__) + +# Add error handling decorator +def handle_aws_errors(f): + @wraps(f) + def decorated_function(*args, **kwargs): + try: + return f(*args, **kwargs) + except boto3.exceptions.Boto3Error as e: + logger.error(f"AWS Error: {str(e)}") + return jsonify({'status': 'KO', 'message': 'Internal server error'}), 500 + except Exception as e: + logger.error(f"Unexpected error: {str(e)}") + return jsonify({'status': 'KO', 'message': 'Internal server error'}), 500 + return decorated_function + +app = Flask(__name__) +CORS(app) + +# Initialize S3 client +# TODO: Add your S3 credentials in .env file +s3_client = boto3.client( + 's3', + aws_access_key_id=os.getenv('SWTICH_ACCESS_KEY_ID'), + aws_secret_access_key=os.getenv('SWITCH_SECRET_ACCESS_KEY'), + endpoint_url=os.getenv('SWTICH_ENDPOINT_URL') +) + +# Constants +BUCKET_NAME = os.getenv('S3_BUCKET_NAME') +if not BUCKET_NAME: + logger.critical("S3_BUCKET_NAME environment variable is not set") + raise ValueError("S3_BUCKET_NAME environment variable is required") + +ENROLLMENT_PREFIX = 'enrollment/' +SESSION_PREFIX = 'session/' + +@app.route('/enroll', methods=['POST']) +@handle_aws_errors +def enroll(): + """ + Endpoint to handle user enrollment + Expected JSON payload: {'email': 'user@example.com', 'password': 'userpassword'} + """ + data = request.get_json() + email = data.get('email') + password = data.get('password') + + if not email or not password: + logger.warning(f"Enrollment attempt with missing credentials: {data}") + return jsonify({'status': 'KO:Missing credentials'}), 400 + + # TODO: Implement enrollment logic + # 1. Check if user already exists + # 2. Create new enrollment with timestamp + enrollment_data = { + 'email': email, + 'password': password, # TODO: Hash this password in production + 'enrolled_at': datetime.utcnow().isoformat() # Added timestamp + } + + return jsonify({'status': 'OK'}), 200 + +@app.route('/login', methods=['POST']) +@handle_aws_errors +def login(): + """ + Endpoint to handle user login + Expected JSON payload: {'email': 'user@example.com', 'password': 'userpassword'} + """ + data = request.get_json() + email = data.get('email') + password = data.get('password') + + if not email: + return jsonify({'status': 'KO:Missing email'}), 400 + + # TODO: Implement login logic + # 1. Check if user exists + # 2. Verify password + # 3. Create or verify session + session_data = { + 'email': email, + 'active': True, + 'login_at': datetime.utcnow().isoformat() # Added timestamp + } + + return jsonify({'status': 'OK'}), 200 + +# TODO: Implement these endpoints +@app.route('/logout', methods=['POST']) +def logout(): + """ + Endpoint to handle user logout + Expected JSON payload: {'email': 'user@example.com'} + """ + pass + +@app.route('/unenroll', methods=['POST']) +def unenroll(): + """ + Endpoint to handle user unenrollment + Expected JSON payload: {'email': 'user@example.com', 'password': 'userpassword'} + """ + pass + +if __name__ == '__main__': + try: + logger.info("Starting Flask application...") + # Create the bucket if it doesn't exist + s3_client.create_bucket(Bucket=BUCKET_NAME) + app.run(host='0.0.0.0', port=8000) + except Exception as e: + logger.critical(f"Failed to start application: {str(e)}") + diff --git a/Application/frontend/frontend/main.py b/Application/frontend/frontend/main.py new file mode 100644 index 0000000000000000000000000000000000000000..c0208793d2bc71495dce0a3d1a5899bf3cdef3cc --- /dev/null +++ b/Application/frontend/frontend/main.py @@ -0,0 +1,19 @@ +from flask import Flask, send_from_directory +import os + +app = Flask(__name__) + +# Serve static files from the views directory +@app.route('/') +def index(): + return send_from_directory('views', 'index.html') + +@app.route('/<path:path>') +def serve_pages(path): + if not path.endswith('.html'): + path = path + '.html' + return send_from_directory('views', path) + +if __name__ == '__main__': + # Run the server on a different port than the API server + app.run(host='0.0.0.0', port=3000, debug=True) diff --git a/Application/frontend/frontend/views/dashboard.html b/Application/frontend/frontend/views/dashboard.html new file mode 100644 index 0000000000000000000000000000000000000000..44872c69b2a204c84a0a7c3bf45596188dd0f227 --- /dev/null +++ b/Application/frontend/frontend/views/dashboard.html @@ -0,0 +1,78 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Dashboard</title> + <style> + body { + font-family: Arial, sans-serif; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + background-color: #f0f2f5; + } + .container { + text-align: center; + padding: 20px; + background-color: white; + border-radius: 8px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); + } + .button { + display: inline-block; + padding: 10px 20px; + margin: 10px; + border: none; + border-radius: 5px; + background-color: #1877f2; + color: white; + text-decoration: none; + cursor: pointer; + } + .button:hover { + background-color: #166fe5; + } + .welcome-text { + color: #1c1e21; + margin-bottom: 20px; + } + </style> +</head> +<body> + <div class="container"> + <h1 class="welcome-text">Welcome to Dashboard</h1> + <p>You are successfully logged in!</p> + <button onclick="logout()" class="button">Logout</button> + </div> + + <script> + // Get email from URL or localStorage (you should implement proper state management) + const email = localStorage.getItem('userEmail'); + console.log(email); + async function logout() { + try { + const response = await fetch('http://localhost:8000/logout', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ "email": email }), + }); + const data = await response.json(); + + if (data.status === 'OK') { + localStorage.removeItem('userEmail'); + window.location.href = 'index.html'; + } else { + alert('Logout failed: ' + data.status); + } + } catch (error) { + alert('Error during logout'); + } + } + </script> +</body> +</html> \ No newline at end of file diff --git a/Application/frontend/frontend/views/index.html b/Application/frontend/frontend/views/index.html new file mode 100644 index 0000000000000000000000000000000000000000..dc2a953b185a3e2415afbcece7a9e70beb01fd16 --- /dev/null +++ b/Application/frontend/frontend/views/index.html @@ -0,0 +1,50 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Welcome</title> + <style> + body { + font-family: Arial, sans-serif; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + background-color: #f0f2f5; + } + .container { + text-align: center; + padding: 20px; + background-color: white; + border-radius: 8px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); + } + .button { + display: inline-block; + padding: 10px 20px; + margin: 10px; + border: none; + border-radius: 5px; + background-color: #1877f2; + color: white; + text-decoration: none; + cursor: pointer; + } + .button:hover { + background-color: #166fe5; + } + </style> +</head> +<body> + <div class="container"> + <h1>Welcome</h1> + <div> + <a href="login.html" class="button">Login</a> + <a href="signup.html" class="button">Sign Up</a> + </div> + </div> +</body> +</html> + diff --git a/Application/frontend/frontend/views/login.html b/Application/frontend/frontend/views/login.html new file mode 100644 index 0000000000000000000000000000000000000000..47ca6b0890b6f0aa61dab3855020f79461da498d --- /dev/null +++ b/Application/frontend/frontend/views/login.html @@ -0,0 +1,103 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Login</title> + <style> + body { + font-family: Arial, sans-serif; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + background-color: #f0f2f5; + } + .container { + padding: 20px; + background-color: white; + border-radius: 8px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); + } + .form-group { + margin-bottom: 15px; + } + label { + display: block; + margin-bottom: 5px; + } + input { + width: 100%; + padding: 8px; + border: 1px solid #ddd; + border-radius: 4px; + box-sizing: border-box; + } + .button { + width: 100%; + padding: 10px; + border: none; + border-radius: 5px; + background-color: #1877f2; + color: white; + cursor: pointer; + } + .button:hover { + background-color: #166fe5; + } + .back-link { + display: block; + margin-top: 15px; + text-align: center; + color: #1877f2; + text-decoration: none; + } + </style> +</head> +<body> + <div class="container"> + <h2>Login</h2> + <form id="loginForm"> + <div class="form-group"> + <label for="email">Email:</label> + <input type="email" id="email" name="email" required> + </div> + <div class="form-group"> + <label for="password">Password:</label> + <input type="password" id="password" name="password" required> + </div> + <button type="submit" class="button">Login</button> + </form> + <a href="index.html" class="back-link">Back to Home</a> + </div> + + <script> + document.getElementById('loginForm').addEventListener('submit', async (e) => { + e.preventDefault(); + const email = document.getElementById('email').value; + const password = document.getElementById('password').value; + + try { + const response = await fetch('http://localhost:8000/login', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ email, password }), + }); + const data = await response.json(); + + if (data.status === 'OK') { + localStorage.setItem('userEmail', email); + window.location.href = 'dashboard.html'; + } else { + alert('Login failed: ' + data.status); + } + } catch (error) { + alert('Error during login'); + } + }); + </script> +</body> +</html> \ No newline at end of file diff --git a/Application/frontend/frontend/views/signup.html b/Application/frontend/frontend/views/signup.html new file mode 100644 index 0000000000000000000000000000000000000000..02769c5cc61ec032e8d7e7af450a4a87b8000ada --- /dev/null +++ b/Application/frontend/frontend/views/signup.html @@ -0,0 +1,103 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>Sign Up</title> + <style> + body { + font-family: Arial, sans-serif; + display: flex; + justify-content: center; + align-items: center; + height: 100vh; + margin: 0; + background-color: #f0f2f5; + } + .container { + padding: 20px; + background-color: white; + border-radius: 8px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); + } + .form-group { + margin-bottom: 15px; + } + label { + display: block; + margin-bottom: 5px; + } + input { + width: 100%; + padding: 8px; + border: 1px solid #ddd; + border-radius: 4px; + box-sizing: border-box; + } + .button { + width: 100%; + padding: 10px; + border: none; + border-radius: 5px; + background-color: #1877f2; + color: white; + cursor: pointer; + } + .button:hover { + background-color: #166fe5; + } + .back-link { + display: block; + margin-top: 15px; + text-align: center; + color: #1877f2; + text-decoration: none; + } + </style> +</head> +<body> + <div class="container"> + <h2>Sign Up</h2> + <form id="signupForm"> + <div class="form-group"> + <label for="email">Email:</label> + <input type="email" id="email" name="email" required> + </div> + <div class="form-group"> + <label for="password">Password:</label> + <input type="password" id="password" name="password" required> + </div> + <button type="submit" class="button">Sign Up</button> + </form> + <a href="index.html" class="back-link">Back to Home</a> + </div> + + <script> + document.getElementById('signupForm').addEventListener('submit', async (e) => { + e.preventDefault(); + const email = document.getElementById('email').value; + const password = document.getElementById('password').value; + + try { + const response = await fetch('http://localhost:8000/enroll', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ email, password }), + }); + const data = await response.json(); + + if (data.status === 'OK') { + alert('Sign up successful! Please login.'); + window.location.href = 'login.html'; + } else { + alert('Sign up failed: ' + data.status); + } + } catch (error) { + alert('Error during sign up'); + } + }); + </script> +</body> +</html> \ No newline at end of file