| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- <!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;
- --brand-ink: #ffffff;
- --danger: #c0392b;
- --radius: 14px;
- }
- * { 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);
- }
- .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
- .mark {
- width: 34px; height: 34px; border-radius: 10px;
- background: linear-gradient(135deg, #2f6bff, #7ab0ff);
- color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center;
- font-size: 17px;
- }
- .logo b { font-size: 16px; letter-spacing: .2px; }
- .logo span { color: var(--muted); font-size: 12px; }
- h1 { font-size: 20px; margin: 0 0 6px; letter-spacing: -.2px; }
- .sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
- label { display: block; font-size: 12.5px; color: var(--muted); margin: 0 0 6px; }
- input, select {
- width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line);
- border-radius: 10px; background: #fff; color: var(--ink); font-size: 14.5px;
- outline: none; transition: border-color .15s, box-shadow .15s;
- }
- input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47, 107, 255, .12); }
- .field { margin-bottom: 14px; }
- .row { display: flex; gap: 10px; }
- .row > * { flex: 1; }
- button {
- width: 100%; height: 44px; border: 0; border-radius: 11px; background: var(--brand);
- color: var(--brand-ink); font-size: 15px; font-weight: 600; cursor: pointer;
- margin-top: 6px; transition: filter .15s, transform .05s;
- }
- button:hover { filter: brightness(1.04); }
- button:active { transform: translateY(1px); }
- button[disabled] { opacity: .6; cursor: default; }
- .tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
- .tab {
- padding: 0 0 10px; font-size: 13.5px; color: var(--muted); cursor: pointer;
- border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; width: auto;
- height: auto; border-radius: 0; font-weight: 500;
- }
- .tab.on { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
- .or {
- display: flex; align-items: center; gap: 10px;
- color: var(--muted); font-size: 12px; margin: 16px 0 4px;
- }
- .or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
- .hint { font-size: 12px; color: var(--muted); margin-top: 12px; }
- .err {
- margin-top: 14px; padding: 10px 12px; border-radius: 10px; font-size: 13px;
- background: #fdf1ef; color: var(--danger); border: 1px solid #f4d4cf; display: none;
- word-break: break-word;
- }
- .err.on { display: block; }
- .foot { margin-top: 18px; text-align: center; font-size: 12px; color: #9aa1ad; }
- [hidden] { display: none !important; }
- @media (max-width: 480px) {
- .card { padding: 26px 20px 22px; border-radius: 16px; }
- body { padding: 12px; }
- }
- </style>
- </head>
- <body>
- <form class="card" id="form" autocomplete="on">
- <div class="logo">
- <div class="mark">C</div>
- <div>
- <b>CocoBuddy</b><br>
- <span id="tagline">教学与办公助手 · Web 版</span>
- </div>
- </div>
- <h1 id="title">登录</h1>
- <p class="sub" id="subtitle">用你的可可课堂账号登录,和桌面客户端是同一个账号。</p>
- <div id="ssoPane" hidden>
- <button type="button" id="sso">用可可课堂账号登录</button>
- <div class="or"><span id="orText">或</span></div>
- </div>
- <div class="field">
- <label id="regionLabel">区域</label>
- <select id="region">
- <option value="zh-CN">中国内地 · cocorobo.cn</option>
- <option value="zh-HK">中国香港 · cocorobo.hk</option>
- <option value="en">International · cocorobo.com</option>
- </select>
- </div>
- <div class="tabs">
- <button type="button" class="tab on" data-mode="password" id="tabPassword">账号密码</button>
- <button type="button" class="tab" data-mode="key" id="tabKey">API Key</button>
- </div>
- <div id="passwordPane">
- <div class="field">
- <label id="accountLabel">账号 / 手机号</label>
- <input id="account" name="username" autocomplete="username" spellcheck="false">
- </div>
- <div class="field">
- <label id="passwordLabel">密码</label>
- <input id="password" name="password" type="password" autocomplete="current-password">
- </div>
- </div>
- <div id="keyPane" hidden>
- <div class="field">
- <label id="keyLabel">API Key</label>
- <input id="apiKey" spellcheck="false" autocomplete="off">
- </div>
- <p class="hint" id="keyHint">在桌面客户端「设置 → 账号」里可以看到,或让管理员给你一份。</p>
- </div>
- <button type="submit" id="submit">登录</button>
- <div class="err" id="err"></div>
- <div class="foot" id="foot">登录后会在服务器上为你准备一份独立的工作环境</div>
- </form>
- <script>
- window.__CC_SSO__ = __CC_SSO_JSON__
- (function () {
- var I18N = {
- 'zh-CN': {
- tagline: '教学与办公助手 · Web 版',
- title: '登录',
- subtitle: '用你的可可课堂账号登录,和桌面客户端是同一个账号。',
- region: '区域',
- account: '账号 / 手机号',
- password: '密码',
- key: 'API Key',
- keyHint: '在桌面客户端「设置 → 账号」里可以看到,或让管理员给你一份。',
- username: '账号密码',
- submit: '登录',
- working: '正在登录…',
- sso: '用可可课堂账号登录',
- or: '或',
- foot: '登录后会在服务器上为你准备一份独立的工作环境',
- empty: '请填写账号和密码',
- emptyKey: '请填写 API Key'
- },
- 'zh-HK': {
- tagline: '教學與辦公助手 · Web 版',
- title: '登入',
- subtitle: '用你的 cococlass 帳號登入,和桌面客戶端是同一個帳號。',
- region: '區域',
- account: '帳號 / 手機號',
- password: '密碼',
- key: 'API Key',
- keyHint: '在桌面客戶端「設定 → 帳號」裡可以看到,或讓管理員給你一份。',
- username: '帳號密碼',
- submit: '登入',
- working: '正在登入…',
- sso: '用可可課堂帳號登入',
- or: '或',
- foot: '登入後會在伺服器上為你準備一份獨立的工作環境',
- empty: '請填寫帳號和密碼',
- emptyKey: '請填寫 API Key'
- },
- en: {
- tagline: 'Teaching & office assistant · Web',
- title: 'Sign in',
- subtitle: 'Use your cococlass account — same account as the desktop client.',
- region: 'Region',
- account: 'Account / phone',
- password: 'Password',
- key: 'API Key',
- keyHint: 'Find it in the desktop client under Settings → Account, or ask your admin.',
- username: 'Password',
- submit: 'Sign in',
- working: 'Signing in…',
- sso: 'Sign in with CocoClass account',
- or: 'or',
- foot: 'A private workspace will be prepared for you on the server',
- empty: 'Enter your account and password',
- emptyKey: 'Enter your API Key'
- }
- }
- var nav = String(navigator.language || 'zh-CN').toLowerCase().replace(/_/g, '-')
- var locale = nav.indexOf('en') === 0 ? 'en' : (/hant|tw|hk|mo/.test(nav) ? 'zh-HK' : 'zh-CN')
- var t = I18N[locale]
- var mode = 'password'
- function $(id) { return document.getElementById(id) }
- function apply () {
- $('tagline').textContent = t.tagline
- $('title').textContent = t.title
- $('subtitle').textContent = t.subtitle
- $('regionLabel').textContent = t.region
- $('accountLabel').textContent = t.account
- $('passwordLabel').textContent = t.password
- $('keyLabel').textContent = t.key
- $('keyHint').textContent = t.keyHint
- $('tabPassword').textContent = t.username
- $('submit').textContent = t.submit
- $('foot').textContent = t.foot
- document.documentElement.lang = locale
- }
- apply()
- $('region').value = locale
- // 配了平台单点登录:主按钮直接去平台自己的登录界面(服务端补 state 与 redirect)。
- // 表单保留,API Key 仍可用于自测或管理员发 key。
- var boot = window.__CC_SSO__ || {}
- var sso = boot.sso
- if (sso && sso.url) {
- $('ssoPane').hidden = false
- $('sso').textContent = t.sso || '用可可课堂账号登录'
- $('orText').textContent = t.or || '或'
- $('sso').addEventListener('click', function () {
- location.href = '/_cc/login?sso=1'
- })
- }
- Array.prototype.forEach.call(document.querySelectorAll('.tab'), function (tab) {
- tab.addEventListener('click', function () {
- mode = tab.getAttribute('data-mode')
- Array.prototype.forEach.call(document.querySelectorAll('.tab'), function (x) {
- x.classList.toggle('on', x === tab)
- })
- $('passwordPane').hidden = mode !== 'password'
- $('keyPane').hidden = mode !== 'key'
- })
- })
- function fail (message) {
- var box = $('err')
- box.textContent = message
- box.classList.add('on')
- }
- function deviceId () {
- try {
- var saved = localStorage.getItem('cc.device')
- if (saved) return saved
- var made = 'web-' + Math.random().toString(36).slice(2) + Date.now().toString(36)
- localStorage.setItem('cc.device', made)
- return made
- } catch (err) { return '' }
- }
- // 单点登录回调失败会带 ?err= 回来,直接显示原因
- var query = new URLSearchParams(location.search)
- if (query.get('err')) fail(query.get('err'))
- $('form').addEventListener('submit', async function (event) {
- event.preventDefault()
- $('err').classList.remove('on')
- var region = $('region').value
- var body = { region: region, locale: region, deviceId: deviceId() }
- if (mode === 'key') {
- var key = $('apiKey').value.trim()
- if (!key) return fail(t.emptyKey)
- body.apiKey = key
- } else {
- var account = $('account').value.trim()
- var password = $('password').value
- if (!account || !password) return fail(t.empty)
- body.mode = 'password'
- body.account = account
- body.password = password
- }
- $('submit').disabled = true
- $('submit').textContent = t.working
- try {
- var res = await fetch('/_cc/api/login', {
- method: 'POST',
- headers: { 'content-type': 'application/json' },
- body: JSON.stringify(body)
- })
- var json = await res.json().catch(function () { return null })
- if (!res.ok || !json || !json.ok) {
- throw new Error((json && json.error) || ('HTTP ' + res.status))
- }
- location.replace('/')
- } catch (err) {
- fail(err.message || 'sign-in failed')
- $('submit').disabled = false
- $('submit').textContent = t.submit
- }
- })
- })()
- </script>
- </body>
- </html>
|