| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <!doctype html>
- <html lang="zh-CN">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
- <title>CocoBuddy · 登录中</title>
- <style>
- :root {
- --bg: #f6f7fb;
- --card: #ffffff;
- --ink: #171a20;
- --muted: #6b7280;
- --line: #e6e8ef;
- --brand: #2f6bff;
- --danger: #c0392b;
- }
- * { box-sizing: border-box; }
- html, body { height: 100%; margin: 0; }
- body {
- background: radial-gradient(1200px 600px at 50% -10%, #e8efff 0%, var(--bg) 55%);
- color: var(--ink);
- font: 15px/1.6 -apple-system, "Segoe UI", system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
- display: flex; align-items: center; justify-content: center; padding: 24px;
- }
- .card {
- width: 100%; max-width: 420px; background: var(--card);
- border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px 26px;
- box-shadow: 0 24px 60px rgba(23, 26, 32, .08); text-align: center;
- }
- .mark {
- width: 44px; height: 44px; border-radius: 13px; margin: 0 auto 18px;
- background: linear-gradient(135deg, #2f6bff, #7ab0ff);
- color: #fff; font-weight: 700; font-size: 20px;
- display: flex; align-items: center; justify-content: center;
- }
- .spinner {
- width: 26px; height: 26px; margin: 4px auto 16px;
- border: 3px solid #e3e9f7; border-top-color: var(--brand);
- border-radius: 50%; animation: spin .8s linear infinite;
- }
- @keyframes spin { to { transform: rotate(360deg); } }
- h1 { font-size: 18px; margin: 0 0 8px; letter-spacing: -.2px; }
- p { color: var(--muted); font-size: 13.5px; margin: 0 0 18px; min-height: 22px; }
- a {
- display: inline-block; color: var(--brand); text-decoration: none;
- font-size: 14px; font-weight: 600; padding: 10px 18px;
- border: 1px solid var(--line); border-radius: 10px;
- }
- a:hover { border-color: var(--brand); }
- .bad { color: var(--danger); }
- </style>
- </head>
- <body>
- <div class="card">
- <div class="mark">C</div>
- <div class="spinner" id="spin"></div>
- <h1 id="title">正在完成登录</h1>
- <p id="msg">正在校验平台登录状态…</p>
- <a id="back" href="/_cc/login" hidden>返回登录</a>
- </div>
- <script>
- (function () {
- var msg = document.getElementById('msg')
- var back = document.getElementById('back')
- var spin = document.getElementById('spin')
- var title = document.getElementById('title')
- function fail (text) {
- spin.hidden = true
- title.textContent = '登录没有完成'
- title.className = 'bad'
- msg.textContent = text || '登录失败,请返回重试。'
- back.hidden = false
- }
- function readHash () {
- var out = {}
- var raw = String(location.hash || '').replace(/^#/, '')
- if (!raw) return out
- raw.split('&').forEach(function (part) {
- var i = part.indexOf('=')
- if (i <= 0) return
- try {
- out[decodeURIComponent(part.slice(0, i))] = decodeURIComponent(part.slice(i + 1))
- } catch (e) { /* 忽略坏字段 */ }
- })
- return out
- }
- var hash = readHash()
- var query = new URLSearchParams(location.search)
- var key = hash.key || hash.apiKey || hash.api_key || hash.token || hash.access_token ||
- query.get('key') || query.get('apiKey') || query.get('token')
- // 先把 key 从地址栏和历史里抹掉,再发请求
- try { history.replaceState(null, '', location.pathname) } catch (e) { /* 老浏览器 */ }
- if (!key) return fail('没有拿到登录凭据。请回到平台重新登录,或返回用账号密码登录。')
- fetch('/_cc/api/login', {
- method: 'POST',
- headers: { 'content-type': 'application/json' },
- body: JSON.stringify({ apiKey: key })
- }).then(function (res) {
- return res.json().catch(function () { return null }).then(function (json) {
- return { ok: res.ok && json && json.ok, error: (json && json.error) || ('HTTP ' + res.status) }
- })
- }).then(function (result) {
- if (result.ok) {
- // 被 window.open 打开时,刷新父窗口并关掉自己(和桌面端独立登录窗口的体感一致)
- if (window.opener && !window.opener.closed) {
- try { window.opener.location.replace('/') } catch (e) { /* 跨域就只关闭 */ }
- window.close()
- return
- }
- return location.replace('/')
- }
- fail(result.error)
- }).catch(function (err) {
- fail(err && err.message)
- })
- })()
- </script>
- </body>
- </html>
|