mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-18 02:30:51 +08:00
feat(cookie-login): add iFlow Cookie login functionality with UI elements and internationalization support
This commit is contained in:
4
app.js
4
app.js
@@ -480,6 +480,7 @@ class CLIProxyManager {
|
|||||||
const iflowOauthBtn = document.getElementById('iflow-oauth-btn');
|
const iflowOauthBtn = document.getElementById('iflow-oauth-btn');
|
||||||
const iflowOpenLink = document.getElementById('iflow-open-link');
|
const iflowOpenLink = document.getElementById('iflow-open-link');
|
||||||
const iflowCopyLink = document.getElementById('iflow-copy-link');
|
const iflowCopyLink = document.getElementById('iflow-copy-link');
|
||||||
|
const iflowCookieSubmit = document.getElementById('iflow-cookie-submit');
|
||||||
|
|
||||||
if (iflowOauthBtn) {
|
if (iflowOauthBtn) {
|
||||||
iflowOauthBtn.addEventListener('click', () => this.startIflowOAuth());
|
iflowOauthBtn.addEventListener('click', () => this.startIflowOAuth());
|
||||||
@@ -490,6 +491,9 @@ class CLIProxyManager {
|
|||||||
if (iflowCopyLink) {
|
if (iflowCopyLink) {
|
||||||
iflowCopyLink.addEventListener('click', () => this.copyIflowLink());
|
iflowCopyLink.addEventListener('click', () => this.copyIflowLink());
|
||||||
}
|
}
|
||||||
|
if (iflowCookieSubmit) {
|
||||||
|
iflowCookieSubmit.addEventListener('click', () => this.submitIflowCookieLogin());
|
||||||
|
}
|
||||||
|
|
||||||
// 使用统计
|
// 使用统计
|
||||||
const refreshUsageStats = document.getElementById('refresh-usage-stats');
|
const refreshUsageStats = document.getElementById('refresh-usage-stats');
|
||||||
|
|||||||
28
i18n.js
28
i18n.js
@@ -388,6 +388,20 @@ const i18n = {
|
|||||||
'auth_login.iflow_oauth_status_error': '认证失败:',
|
'auth_login.iflow_oauth_status_error': '认证失败:',
|
||||||
'auth_login.iflow_oauth_start_error': '启动 iFlow OAuth 失败:',
|
'auth_login.iflow_oauth_start_error': '启动 iFlow OAuth 失败:',
|
||||||
'auth_login.iflow_oauth_polling_error': '检查认证状态失败:',
|
'auth_login.iflow_oauth_polling_error': '检查认证状态失败:',
|
||||||
|
'auth_login.iflow_cookie_title': 'iFlow Cookie 登录',
|
||||||
|
'auth_login.iflow_cookie_label': 'Cookie 内容:',
|
||||||
|
'auth_login.iflow_cookie_placeholder': '粘贴浏览器中的 Cookie,例如 sessionid=...;',
|
||||||
|
'auth_login.iflow_cookie_hint': '直接提交 Cookie 以完成登录(无需打开授权链接),服务端将自动保存凭据。',
|
||||||
|
'auth_login.iflow_cookie_button': '提交 Cookie 登录',
|
||||||
|
'auth_login.iflow_cookie_status_success': 'Cookie 登录成功,凭据已保存。',
|
||||||
|
'auth_login.iflow_cookie_status_error': 'Cookie 登录失败:',
|
||||||
|
'auth_login.iflow_cookie_start_error': '提交 Cookie 登录失败:',
|
||||||
|
'auth_login.iflow_cookie_required': '请先填写 Cookie 内容',
|
||||||
|
'auth_login.iflow_cookie_result_title': 'Cookie 登录结果',
|
||||||
|
'auth_login.iflow_cookie_result_email': '账号',
|
||||||
|
'auth_login.iflow_cookie_result_expired': '过期时间',
|
||||||
|
'auth_login.iflow_cookie_result_path': '保存路径',
|
||||||
|
'auth_login.iflow_cookie_result_type': '类型',
|
||||||
|
|
||||||
// 使用统计
|
// 使用统计
|
||||||
'usage_stats.title': '使用统计',
|
'usage_stats.title': '使用统计',
|
||||||
@@ -922,6 +936,20 @@ const i18n = {
|
|||||||
'auth_login.iflow_oauth_status_error': 'Authentication failed:',
|
'auth_login.iflow_oauth_status_error': 'Authentication failed:',
|
||||||
'auth_login.iflow_oauth_start_error': 'Failed to start iFlow OAuth:',
|
'auth_login.iflow_oauth_start_error': 'Failed to start iFlow OAuth:',
|
||||||
'auth_login.iflow_oauth_polling_error': 'Failed to check authentication status:',
|
'auth_login.iflow_oauth_polling_error': 'Failed to check authentication status:',
|
||||||
|
'auth_login.iflow_cookie_title': 'iFlow Cookie Login',
|
||||||
|
'auth_login.iflow_cookie_label': 'Cookie Value:',
|
||||||
|
'auth_login.iflow_cookie_placeholder': 'Paste browser cookie, e.g. sessionid=...;',
|
||||||
|
'auth_login.iflow_cookie_hint': 'Submit an existing cookie to finish login without opening the authorization link; the credential file will be saved automatically.',
|
||||||
|
'auth_login.iflow_cookie_button': 'Submit Cookie Login',
|
||||||
|
'auth_login.iflow_cookie_status_success': 'Cookie login succeeded and credentials are saved.',
|
||||||
|
'auth_login.iflow_cookie_status_error': 'Cookie login failed:',
|
||||||
|
'auth_login.iflow_cookie_start_error': 'Failed to submit cookie login:',
|
||||||
|
'auth_login.iflow_cookie_required': 'Please provide the Cookie value first.',
|
||||||
|
'auth_login.iflow_cookie_result_title': 'Cookie Login Result',
|
||||||
|
'auth_login.iflow_cookie_result_email': 'Account',
|
||||||
|
'auth_login.iflow_cookie_result_expired': 'Expires At',
|
||||||
|
'auth_login.iflow_cookie_result_path': 'Saved Path',
|
||||||
|
'auth_login.iflow_cookie_result_type': 'Type',
|
||||||
|
|
||||||
// Usage Statistics
|
// Usage Statistics
|
||||||
'usage_stats.title': 'Usage Statistics',
|
'usage_stats.title': 'Usage Statistics',
|
||||||
|
|||||||
28
index.html
28
index.html
@@ -778,6 +778,34 @@
|
|||||||
<div id="iflow-oauth-status" class="form-hint" style="margin-top: 10px;"></div>
|
<div id="iflow-oauth-status" class="form-hint" style="margin-top: 10px;"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="card-content" style="border-top: 1px solid var(--border-color); margin-top: 16px; padding-top: 16px;">
|
||||||
|
<h4 style="margin-bottom: 10px;" data-i18n="auth_login.iflow_cookie_title">iFlow Cookie 登录</h4>
|
||||||
|
<p class="form-hint" data-i18n="auth_login.iflow_cookie_hint">
|
||||||
|
直接提交 Cookie 完成登录并保存凭据,无需打开授权链接。
|
||||||
|
</p>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="iflow-cookie-input" data-i18n="auth_login.iflow_cookie_label">Cookie 内容:</label>
|
||||||
|
<textarea id="iflow-cookie-input" rows="3" data-i18n-placeholder="auth_login.iflow_cookie_placeholder" placeholder="粘贴浏览器中的 Cookie"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="form-actions">
|
||||||
|
<button id="iflow-cookie-submit" class="btn btn-primary">
|
||||||
|
<i class="fas fa-cookie-bite"></i> <span data-i18n="auth_login.iflow_cookie_button">提交 Cookie 登录</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div id="iflow-cookie-status" class="form-hint" style="margin-top: 10px;"></div>
|
||||||
|
<div id="iflow-cookie-result" class="vertex-import-result" style="display: none;">
|
||||||
|
<div class="vertex-import-result-header">
|
||||||
|
<i class="fas fa-check-circle"></i>
|
||||||
|
<span data-i18n="auth_login.iflow_cookie_result_title">Cookie 登录结果</span>
|
||||||
|
</div>
|
||||||
|
<ul>
|
||||||
|
<li><span data-i18n="auth_login.iflow_cookie_result_email">账号</span>: <code id="iflow-cookie-result-email">-</code></li>
|
||||||
|
<li><span data-i18n="auth_login.iflow_cookie_result_expired">过期时间</span>: <code id="iflow-cookie-result-expired">-</code></li>
|
||||||
|
<li><span data-i18n="auth_login.iflow_cookie_result_path">保存路径</span>: <code id="iflow-cookie-result-path">-</code></li>
|
||||||
|
<li><span data-i18n="auth_login.iflow_cookie_result_type">类型</span>: <code id="iflow-cookie-result-type">-</code></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|||||||
@@ -862,6 +862,88 @@ export const oauthModule = {
|
|||||||
status.style.color = '';
|
status.style.color = '';
|
||||||
status.className = '';
|
status.className = '';
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 提交 iFlow Cookie 登录
|
||||||
|
async submitIflowCookieLogin() {
|
||||||
|
const cookieInput = document.getElementById('iflow-cookie-input');
|
||||||
|
const statusEl = document.getElementById('iflow-cookie-status');
|
||||||
|
const submitBtn = document.getElementById('iflow-cookie-submit');
|
||||||
|
const cookieValue = cookieInput ? cookieInput.value.trim() : '';
|
||||||
|
|
||||||
|
this.renderIflowCookieResult(null);
|
||||||
|
|
||||||
|
if (!cookieValue) {
|
||||||
|
this.showNotification(i18n.t('auth_login.iflow_cookie_required'), 'error');
|
||||||
|
if (statusEl) {
|
||||||
|
statusEl.textContent = `${i18n.t('auth_login.iflow_cookie_status_error')} ${i18n.t('auth_login.iflow_cookie_required')}`;
|
||||||
|
statusEl.style.color = 'var(--error-text)';
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (submitBtn) {
|
||||||
|
submitBtn.disabled = true;
|
||||||
|
}
|
||||||
|
if (statusEl) {
|
||||||
|
statusEl.textContent = i18n.t('auth_login.iflow_oauth_status_waiting');
|
||||||
|
statusEl.style.color = 'var(--warning-text)';
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await this.makeRequest('/iflow-auth-url', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({ cookie: cookieValue })
|
||||||
|
});
|
||||||
|
|
||||||
|
this.renderIflowCookieResult(response);
|
||||||
|
if (statusEl) {
|
||||||
|
statusEl.textContent = i18n.t('auth_login.iflow_cookie_status_success');
|
||||||
|
statusEl.style.color = 'var(--success-text)';
|
||||||
|
}
|
||||||
|
if (cookieInput) {
|
||||||
|
cookieInput.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.showNotification(i18n.t('auth_login.iflow_cookie_status_success'), 'success');
|
||||||
|
this.loadAuthFiles();
|
||||||
|
} catch (error) {
|
||||||
|
if (statusEl) {
|
||||||
|
statusEl.textContent = `${i18n.t('auth_login.iflow_cookie_status_error')} ${error.message}`;
|
||||||
|
statusEl.style.color = 'var(--error-text)';
|
||||||
|
}
|
||||||
|
this.showNotification(`${i18n.t('auth_login.iflow_cookie_start_error')} ${error.message}`, 'error');
|
||||||
|
} finally {
|
||||||
|
if (submitBtn) {
|
||||||
|
submitBtn.disabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
renderIflowCookieResult(result = null) {
|
||||||
|
const container = document.getElementById('iflow-cookie-result');
|
||||||
|
const emailEl = document.getElementById('iflow-cookie-result-email');
|
||||||
|
const expiredEl = document.getElementById('iflow-cookie-result-expired');
|
||||||
|
const pathEl = document.getElementById('iflow-cookie-result-path');
|
||||||
|
const typeEl = document.getElementById('iflow-cookie-result-type');
|
||||||
|
|
||||||
|
if (!container || !emailEl || !expiredEl || !pathEl || !typeEl) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
container.style.display = 'none';
|
||||||
|
emailEl.textContent = '-';
|
||||||
|
expiredEl.textContent = '-';
|
||||||
|
pathEl.textContent = '-';
|
||||||
|
typeEl.textContent = '-';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emailEl.textContent = result.email || '-';
|
||||||
|
expiredEl.textContent = result.expired || '-';
|
||||||
|
pathEl.textContent = result.saved_path || result.savedPath || result.path || '-';
|
||||||
|
typeEl.textContent = result.type || '-';
|
||||||
|
container.style.display = 'block';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user