From c218ae4cc6f0205bd5f4e884956357d3bfbee439 Mon Sep 17 00:00:00 2001 From: TPD94 Date: Wed, 30 Apr 2025 04:42:47 -0400 Subject: [PATCH] Index tags, logout button --- cdrm-frontend/dist/index.html | 4 +-- .../src/components/Pages/MyAccount.jsx | 31 ++++++++++++++----- configs/index_tags.py | 9 ++++++ .../prechecks/config_file_checks.py | 1 + main.py | 7 +++-- routes/login.py | 5 +++ routes/react.py | 2 +- 7 files changed, 47 insertions(+), 12 deletions(-) diff --git a/cdrm-frontend/dist/index.html b/cdrm-frontend/dist/index.html index 2fffcc8..cbe53ec 100644 --- a/cdrm-frontend/dist/index.html +++ b/cdrm-frontend/dist/index.html @@ -12,8 +12,8 @@ {{ data.tab_title }} - - + +
diff --git a/cdrm-frontend/src/components/Pages/MyAccount.jsx b/cdrm-frontend/src/components/Pages/MyAccount.jsx index b271cbb..fa02027 100644 --- a/cdrm-frontend/src/components/Pages/MyAccount.jsx +++ b/cdrm-frontend/src/components/Pages/MyAccount.jsx @@ -5,15 +5,15 @@ function MyAccount() { const [wvList, setWvList] = useState([]); const [prList, setPrList] = useState([]); const [uploading, setUploading] = useState(false); - const [username, setUsername] = useState(''); // <-- Added state for username + const [username, setUsername] = useState(''); - // Fetch user CDMs + // Fetch user info const fetchUserInfo = async () => { try { const response = await axios.post('/userinfo'); setWvList(response.data.Widevine_Devices || []); setPrList(response.data.Playready_Devices || []); - setUsername(response.data.Username || ''); // <-- Set username here + setUsername(response.data.Username || ''); } catch (err) { console.error('Failed to fetch user info', err); } @@ -23,7 +23,7 @@ function MyAccount() { fetchUserInfo(); }, []); - // Handle File Upload + // Handle file upload const handleUpload = async (event, cdmType) => { const file = event.target.files[0]; if (!file) return; @@ -49,20 +49,37 @@ function MyAccount() { } }; + // Handle logout + const handleLogout = async () => { + try { + await axios.post('/logout'); + window.location.reload(); + } catch (error) { + console.error('Logout failed:', error); + alert('Logout failed!'); + } + }; + return (
{/* Left Panel */}
-

+

{username ? `${username}` : 'My Account'}

+
{/* Right Panel */}
{/* Widevine Section */} -
+

Widevine CDMs

{wvList.length === 0 ? ( @@ -92,7 +109,7 @@ function MyAccount() {
{/* Playready Section */} -
+

Playready CDMs

{prList.length === 0 ? ( diff --git a/configs/index_tags.py b/configs/index_tags.py index 2b4a6dd..aed1510 100644 --- a/configs/index_tags.py +++ b/configs/index_tags.py @@ -34,5 +34,14 @@ tags = { 'opengraph_image': 'https://cdrm-project.com/og-api.jpg', 'opengraph_url': 'https://cdrm-project.com/api', 'tab_title': 'API', + }, + 'account': { + 'description': 'Account for CDRM-Project', + 'keywords': 'Login, CDRM, CDM, CDRM-Project, register, account', + 'opengraph_title': 'My account', + 'opengraph_description': 'Account for CDRM-Project', + 'opengraph_image': 'https://cdrm-project.com/og-home.jpg', + 'opengraph_url': 'https://cdrm-project.com/account', + 'tab_title': 'My account', } } \ No newline at end of file diff --git a/custom_functions/prechecks/config_file_checks.py b/custom_functions/prechecks/config_file_checks.py index 9c9c320..5ca2e58 100644 --- a/custom_functions/prechecks/config_file_checks.py +++ b/custom_functions/prechecks/config_file_checks.py @@ -7,6 +7,7 @@ def check_for_config_file(): default_config = """\ default_wv_cdm: '' default_pr_cdm: '' +secret_key_flask: 'secretkey' # change the type to mariadb to use mariadb below database_type: 'sqlite' fqdn: '' diff --git a/main.py b/main.py index 8ac46c6..0edade8 100644 --- a/main.py +++ b/main.py @@ -12,9 +12,12 @@ from routes.upload import upload_bp from routes.user_info import user_info_bp from routes.register import register_bp from routes.login import login_bp - +import os +import yaml app = Flask(__name__) -app.secret_key = 'TT' +with open(f'{os.getcwd()}/configs/config.yaml', 'r') as file: + config = yaml.safe_load(file) +app.secret_key = config['secret_key_flask'] CORS(app) diff --git a/routes/login.py b/routes/login.py index c20ba93..167015d 100644 --- a/routes/login.py +++ b/routes/login.py @@ -30,3 +30,8 @@ def login_status(): return jsonify({'message': 'False'}) except: return jsonify({'message': 'False'}) + +@login_bp.route('/logout', methods=['POST']) +def logout(): + session.pop('username', None) + return jsonify({'message': 'Successfully logged out!'}) \ No newline at end of file diff --git a/routes/react.py b/routes/react.py index 5ca327a..6da08f6 100644 --- a/routes/react.py +++ b/routes/react.py @@ -26,7 +26,7 @@ def index(path=''): file_path = os.path.join(react_bp.static_folder, path) if path != "" and os.path.exists(file_path): return send_from_directory(react_bp.static_folder, path) - elif path.lower() in ['', 'cache', 'api', 'testplayer']: + elif path.lower() in ['', 'cache', 'api', 'testplayer', 'account']: data = index_tags.tags.get(path.lower(), index_tags.tags['index']) return render_template('index.html', data=data) else: