Skip to content

Commit c46cf6d

Browse files
fix2
1 parent f007293 commit c46cf6d

2 files changed

Lines changed: 19 additions & 47 deletions

File tree

grades_dashboard.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -767,22 +767,6 @@ function setupSyncFeature() {
767767

768768
const API_BASE = '/api';
769769
let availableStructure = {}; // Store the loaded structure
770-
let turnstileEnabled = true;
771-
772-
// Fetch config
773-
fetch(`${API_BASE}/config`)
774-
.then(res => res.json())
775-
.then(data => {
776-
turnstileEnabled = data.turnstile_enabled;
777-
if (!turnstileEnabled) {
778-
const turnstileDiv = document.querySelector('.cf-turnstile');
779-
if (turnstileDiv) turnstileDiv.style.display = 'none';
780-
} else if (data.site_key) {
781-
const turnstileDiv = document.querySelector('.cf-turnstile');
782-
if (turnstileDiv) turnstileDiv.setAttribute('data-sitekey', data.site_key);
783-
}
784-
})
785-
.catch(err => console.error('Failed to load config:', err));
786770

787771
// Helper to toggle modal
788772
const toggleModal = (modal, show) => {
@@ -835,7 +819,7 @@ function setupSyncFeature() {
835819
return;
836820
}
837821

838-
if (turnstileEnabled && !turnstileResponse) {
822+
if (!turnstileResponse) {
839823
showStatus(loginStatus, '請完成驗證', 'error');
840824
return;
841825
}

server.py

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,6 @@ def static_files(filename):
103103
return send_from_directory('.', filename)
104104

105105

106-
@app.route('/api/config')
107-
def get_config():
108-
is_testing = app.debug or os.environ.get('ENVIRONMENT', '').lower() in ['testing', 'development']
109-
site_key = os.environ.get('TURNSTILE_SITE_KEY') or '0x4AAAAAAChO97Yocoqp2iiB'
110-
return jsonify({
111-
'turnstile_enabled': not is_testing,
112-
'site_key': site_key
113-
})
114-
115106
@app.route('/api/check_login')
116107
def check_login():
117108
# Only check if we have tokens in session
@@ -129,29 +120,26 @@ def login():
129120
if not username or not data.get('password'):
130121
return jsonify({'success': False, 'message': '請輸入帳號密碼'}), 400
131122

132-
is_testing = app.debug or os.environ.get('ENVIRONMENT', '').lower() in ['testing', 'development']
123+
turnstile_response = data.get('turnstile_response')
124+
secret_key = os.environ.get('TURNSTILE_SECRET_KEY') or '1x0000000000000000000000000000000AA'
133125

134-
if not is_testing:
135-
turnstile_response = data.get('turnstile_response')
136-
secret_key = os.environ.get('TURNSTILE_SECRET_KEY') or '1x0000000000000000000000000000000AA'
126+
if not turnstile_response:
127+
return jsonify({'success': False, 'message': '請完成驗證'}), 400
137128

138-
if not turnstile_response:
139-
return jsonify({'success': False, 'message': '請完成驗證'}), 400
140-
141-
try:
142-
cf_url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify'
143-
cf_data = {
144-
'secret': secret_key,
145-
'response': turnstile_response
146-
}
147-
cf_res = requests.post(cf_url, data=cf_data, timeout=10)
148-
cf_json = cf_res.json()
149-
if not cf_json.get('success'):
150-
logger.warning(f"Turnstile verification failed for user {username}: {cf_json}")
151-
return jsonify({'success': False, 'message': '驗證失敗,請重試'}), 400
152-
except Exception as e:
153-
logger.error(f"Turnstile API error: {e}")
154-
return jsonify({'success': False, 'message': '驗證連線失敗,請稍後再試'}), 500
129+
try:
130+
cf_url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify'
131+
cf_data = {
132+
'secret': secret_key,
133+
'response': turnstile_response
134+
}
135+
cf_res = requests.post(cf_url, data=cf_data, timeout=10)
136+
cf_json = cf_res.json()
137+
if not cf_json.get('success'):
138+
logger.warning(f"Turnstile verification failed for user {username}: {cf_json}")
139+
return jsonify({'success': False, 'message': '驗證失敗,請重試'}), 400
140+
except Exception as e:
141+
logger.error(f"Turnstile API error: {e}")
142+
return jsonify({'success': False, 'message': '驗證連線失敗,請稍後再試'}), 500
155143

156144
try:
157145
success, message, cookies, student_no, token = GradeFetcher.login_and_get_tokens(username, data.get('password'))

0 commit comments

Comments
 (0)